|
110 | 110 | }, |
111 | 111 | { |
112 | 112 | "cell_type": "code", |
113 | | - "execution_count": 14, |
| 113 | + "execution_count": 3, |
114 | 114 | "id": "a89258b6", |
115 | 115 | "metadata": {}, |
116 | 116 | "outputs": [ |
|
121 | 121 | " 'role': 'user'}]" |
122 | 122 | ] |
123 | 123 | }, |
124 | | - "execution_count": 14, |
| 124 | + "execution_count": 3, |
125 | 125 | "metadata": {}, |
126 | 126 | "output_type": "execute_result" |
127 | 127 | } |
|
133 | 133 | }, |
134 | 134 | { |
135 | 135 | "cell_type": "code", |
136 | | - "execution_count": 15, |
| 136 | + "execution_count": 4, |
137 | 137 | "id": "491b0ddb", |
138 | 138 | "metadata": {}, |
| 139 | + "outputs": [], |
| 140 | + "source": [ |
| 141 | + "ret = llms.query(\"openai/gpt-4o\", msgs, temperature=0.5, max_tokens=1000, stream=True)\n" |
| 142 | + ] |
| 143 | + }, |
| 144 | + { |
| 145 | + "cell_type": "code", |
| 146 | + "execution_count": 5, |
| 147 | + "id": "1c795bd0", |
| 148 | + "metadata": {}, |
139 | 149 | "outputs": [ |
140 | 150 | { |
141 | 151 | "name": "stdout", |
142 | 152 | "output_type": "stream", |
143 | 153 | "text": [ |
144 | | - "A monoid is an algebraic structure with a single associative binary operation and an identity element. Specifically, a set M is a monoid if it is equipped with a binary operation (let's call it *) that satisfies the following properties:\n", |
| 154 | + "A monoid is an algebraic structure with a single associative binary operation and an identity element. Formally, a set M equipped with an operation * (often called multiplication) is a monoid if it satisfies two properties:\n", |
145 | 155 | "\n", |
146 | 156 | "1. **Associativity**: For all elements a, b, and c in M, the equation (a * b) * c = a * (b * c) holds.\n", |
147 | | - "2. **Identity Element**: There exists an element e in M such that for every element a in M, the equation e * a = a * e = a holds.\n", |
| 157 | + "2. **Identity element**: There exists an element e in M such that for every element a in M, the equations e * a = a * e = a hold.\n", |
| 158 | + "\n", |
| 159 | + "A simple example of a monoid is the set of natural numbers (including zero) with the operation of addition. In this case:\n", |
148 | 160 | "\n", |
149 | | - "A simple example of a monoid is the set of natural numbers (including zero) with the operation of addition. \n", |
| 161 | + "- The binary operation is addition (+), which is associative. For any natural numbers a, b, and c, we have (a + b) + c = a + (b + c).\n", |
| 162 | + "- The identity element is 0, because for any natural number a, a + 0 = 0 + a = a.\n", |
150 | 163 | "\n", |
151 | | - "- The set is {0, 1, 2, 3, ...}.\n", |
152 | | - "- The binary operation is addition (+).\n", |
153 | | - "- The identity element is 0 because adding 0 to any natural number does not change the number (0 + a = a + 0 = a).\n", |
154 | | - "- Addition is associative because for any natural numbers a, b, and c, the equation (a + b) + c = a + (b + c) is always true." |
| 164 | + "Thus, the natural numbers with addition form a monoid.\n" |
155 | 165 | ] |
156 | 166 | } |
157 | 167 | ], |
158 | 168 | "source": [ |
159 | | - "ret = llms.query(\"openai/gpt-4o\", msgs, temperature=0.5, max_tokens=1000, stream=True)\n", |
160 | 169 | "if ret[\"ok\"]:\n", |
161 | | - " for chunk in ret[\"response\"]:\n", |
162 | | - " choice0 = chunk.choices[0]\n", |
163 | | - " if choice0.finish_reason == \"stop\":\n", |
164 | | - " break \n", |
165 | | - " content = choice0.delta.content \n", |
166 | | - " print(content, end=\"\", flush=True)\n", |
| 170 | + " for chunk in ret[\"chunks\"]:\n", |
| 171 | + " if chunk[\"error\"]:\n", |
| 172 | + " print()\n", |
| 173 | + " print(\"Error:\", chunk[\"error\"])\n", |
| 174 | + " break\n", |
| 175 | + " print(chunk[\"answer\"], end=\"\")\n", |
| 176 | + " print()\n", |
167 | 177 | "else:\n", |
168 | 178 | " print(\"Error:\", ret[\"error\"])" |
169 | 179 | ] |
170 | 180 | }, |
171 | 181 | { |
172 | 182 | "cell_type": "code", |
173 | 183 | "execution_count": null, |
174 | | - "id": "0eeea159", |
| 184 | + "id": "f7fa724b", |
175 | 185 | "metadata": {}, |
176 | 186 | "outputs": [], |
177 | 187 | "source": [] |
|
0 commit comments