Skip to content

Commit 4a0c4ae

Browse files
jameszyaoSimsonW
authored andcommitted
fix: fix typos in inference examples
1 parent 3b949ba commit 4a0c4ae

File tree

2 files changed

+75
-21
lines changed

2 files changed

+75
-21
lines changed

examples/inference/chat_completion.ipynb

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@
3838
},
3939
"id": "49abde692940b09e"
4040
},
41+
{
42+
"cell_type": "markdown",
43+
"source": [
44+
"## Single-round chat completion"
45+
],
46+
"metadata": {
47+
"collapsed": false
48+
},
49+
"id": "84b663418e3e3b19"
50+
},
4151
{
4252
"cell_type": "code",
4353
"execution_count": null,
4454
"outputs": [],
4555
"source": [
46-
"# normal \n",
4756
"chat_completion_result = taskingai.inference.chat_completion(\n",
4857
" model_id=model_id,\n",
4958
" messages=[\n",
@@ -58,12 +67,21 @@
5867
},
5968
"id": "43dcc632665f0de4"
6069
},
70+
{
71+
"cell_type": "markdown",
72+
"source": [
73+
"## Multi-round chat completion"
74+
],
75+
"metadata": {
76+
"collapsed": false
77+
},
78+
"id": "9f84e86d19409580"
79+
},
6180
{
6281
"cell_type": "code",
6382
"execution_count": null,
6483
"outputs": [],
6584
"source": [
66-
"# multi round chat completion\n",
6785
"chat_completion_result = taskingai.inference.chat_completion(\n",
6886
" model_id=model_id,\n",
6987
" messages=[\n",
@@ -87,7 +105,7 @@
87105
"execution_count": null,
88106
"outputs": [],
89107
"source": [
90-
"# config max tokens\n",
108+
"# Add max tokens configs\n",
91109
"chat_completion_result = taskingai.inference.chat_completion(\n",
92110
" model_id=model_id,\n",
93111
" messages=[\n",
@@ -109,12 +127,22 @@
109127
},
110128
"id": "f7c1b8be2579d9e0"
111129
},
130+
{
131+
"cell_type": "markdown",
132+
"source": [
133+
"## Function call"
134+
],
135+
"metadata": {
136+
"collapsed": false
137+
},
138+
"id": "c615ece16c777029"
139+
},
112140
{
113141
"cell_type": "code",
114142
"execution_count": null,
115143
"outputs": [],
116144
"source": [
117-
"# function call\n",
145+
"# function definition\n",
118146
"function = Function(\n",
119147
" name=\"plus_a_and_b\",\n",
120148
" description=\"Sum up a and b and return the result\",\n",
@@ -132,48 +160,64 @@
132160
" },\n",
133161
" \"required\": [\"a\", \"b\"]\n",
134162
" },\n",
135-
")\n",
163+
")"
164+
],
165+
"metadata": {
166+
"collapsed": false
167+
},
168+
"id": "2645bdc3df011e7d"
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": null,
173+
"outputs": [],
174+
"source": [
175+
"# chat completion with the function call\n",
136176
"chat_completion_result = taskingai.inference.chat_completion(\n",
137177
" model_id=model_id,\n",
138178
" messages=[\n",
139-
" SystemMessage(\"You are a professional assistant.\"),\n",
140179
" UserMessage(\"What is the result of 112 plus 22?\"),\n",
141180
" ],\n",
142181
" functions=[function]\n",
143182
")\n",
144-
"print(f\"chat_completion_result = {chat_completion_result}\")\n",
145-
"\n",
146-
"assistant_function_call_message = chat_completion_result.message\n",
147-
"fucntion_name = assistant_function_call_message.function_call.name\n",
148-
"argument_content = json.dumps(assistant_function_call_message.function_call.arguments)\n",
149-
"print(f\"function name: {fucntion_name}, argument content: {argument_content}\")"
183+
"function_call_assistant_message = chat_completion_result.message\n",
184+
"print(f\"function_call_assistant_message = {function_call_assistant_message}\")"
150185
],
151186
"metadata": {
152187
"collapsed": false
153188
},
154-
"id": "2645bdc3df011e7d"
189+
"id": "850adc819aa228fc"
155190
},
156191
{
157-
"cell_type": "markdown",
158-
"source": [],
192+
"cell_type": "code",
193+
"execution_count": null,
194+
"outputs": [],
195+
"source": [
196+
"# get the function call result\n",
197+
"def plus_a_and_b(a, b):\n",
198+
" return a + b\n",
199+
"\n",
200+
"arguments = function_call_assistant_message.function_call.arguments\n",
201+
"function_call_result = plus_a_and_b(**arguments)\n",
202+
"print(f\"function_call_result = {function_call_result}\")"
203+
],
159204
"metadata": {
160205
"collapsed": false
161206
},
162-
"id": "ed6957f0c380ba9f"
207+
"id": "45787662d2148352"
163208
},
164209
{
165210
"cell_type": "code",
166211
"execution_count": null,
167212
"outputs": [],
168213
"source": [
169-
"# add function message\n",
214+
"# chat completion with the function result\n",
170215
"chat_completion_result = taskingai.inference.chat_completion(\n",
171216
" model_id=model_id,\n",
172217
" messages=[\n",
173-
" SystemMessage(\"You are a professional assistant.\"),\n",
174218
" UserMessage(\"What is the result of 112 plus 22?\"),\n",
175-
" assistant_function_call_message,\n",
176-
" FunctionMessage(name=fucntion_name, content=\"144\")\n",
219+
" function_call_assistant_message,\n",
220+
" FunctionMessage(name=\"plus_a_and_b\", content=str(function_call_result))\n",
177221
" ],\n",
178222
" functions=[function]\n",
179223
")\n",
@@ -184,6 +228,16 @@
184228
},
185229
"id": "9df9a8b9eafa17d9"
186230
},
231+
{
232+
"cell_type": "markdown",
233+
"source": [
234+
"## Stream mode"
235+
],
236+
"metadata": {
237+
"collapsed": false
238+
},
239+
"id": "a64da98251c5d3c5"
240+
},
187241
{
188242
"cell_type": "code",
189243
"execution_count": null,

examples/inference/text_embedding.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"source": [
3131
"from taskingai.inference import *\n",
3232
"import json\n",
33-
"# choose an available chat_completion model from your project\n",
33+
"# choose an available text embedding model from your project\n",
3434
"model_id = \"YOUR_MODEL_ID\""
3535
],
3636
"metadata": {

0 commit comments

Comments
 (0)