8000 Update Functions notebook example · jithinraj/llama-cpp-python@85ead98 · GitHub
[go: up one dir, main page]

Skip to content

Commit 85ead98

Browse files
committed
Update Functions notebook example
1 parent b7e60b6 commit 85ead98

File tree

1 file changed

+77
-17
lines changed

1 file changed

+77
-17
lines changed

examples/notebooks/Functions.ipynb

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Function Calling with OpenAI Python Client"
8+
]
9+
},
310
{
411
"cell_type": "code",
5-
"execution_count": 29,
12+
"execution_count": 4,
613
"metadata": {},
714
"outputs": [
815
{
916
"name": "stdout",
1017
"output_type": "stream",
1118
"text": [
12-
"ChatCompletion(id='chatcmpl-b6dcbb47-1120-4761-8cd9-83542c97647b', choices=[Choice(finish_reason='stop', index=0, message=ChatCompletionMessage(content=\"The current temperature in San Francisco is 72 degrees Fahrenheit. It's a sunny day with clear skies, making it perfect for outdoor activities.\\n \", role='assistant', function_call=None, tool_calls=None))], created=1699602158, model='gpt-3.5-turbo-1106', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=38, prompt_tokens=135, total_tokens=173))\n"
19+
"ChatCompletion(id='chatcmpl-a2d9eb9f-7354-472f-b6ad-4d7a807729a3', choices=[Choice(finish_reason='stop', index=0, message=ChatCompletionMessage(content='The current weather in San Francisco is **72°F** (22°C).\\n ', role='assistant', function_call=None, tool_calls=None))], created=1699638365, model='gpt-3.5-turbo-1106', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=22, prompt_tokens=136, total_tokens=158))\n"
1320
]
1421
}
1522
],
@@ -100,9 +107,26 @@
100107
"print(run_conversation())"
101108
]
102109
},
110+
{
111+
"cell_type": "markdown",
112+
"metadata": {},
113+
"source": [
114+
"# Function Calling with Instructor\n",
115+
"\n",
116+
"You'll need to install the [`instructor`](https://github.com/jxnl/instructor/) package to run this notebook. You can do so by running the following command in your terminal:\n",
117+
"\n",
118+
"```bash\n",
119+
"pip install instructor\n",
120+
"```\n",
10000
121+
"\n",
122+
"We'll highlight a few basic examples taken from the [instructor cookbook](https://jxnl.github.io/instructor/)\n",
123+
"\n",
124+
"## Basic Usage"
125+
]
126+
},
103127
{
104128
"cell_type": "code",
105-
"execution_count": 30,
129+
"execution_count": 5,
106130
"metadata": {},
107131
"outputs": [
108132
{
@@ -139,11 +163,28 @@
139163
"print(user)"
140164
]
141165
},
166+
{
167+
"cell_type": "markdown",
168+
"metadata": {},
169+
"source": [
170+
"## Text Classification\n",
171+
"\n",
172+
"### Single-Label Classification"
173+
]
174+
},
142175
{
143176
"cell_type": "code",
144-
"execution_count": 31,
177+
"execution_count": 7,
145178
"metadata": {},
146-
"outputs": [],
179+
"outputs": [
180+
{
181+
"name": "stdout",
182+
"output_type": "stream",
183+
"text": [
184+
"class_label=<Labels.SPAM: 'spam'>\n"
185+
]
186+
}
187+
],
147188
"source": [
148189
"import enum\n",
149190
"\n",
@@ -172,19 +213,27 @@
172213
" ) # type: ignore\n",
173214
"\n",
174215
"prediction = classify(\"Hello there I'm a Nigerian prince and I want to give you money\")\n",
175-
"assert prediction.class_label == Labels.SPAM"
216+
"assert prediction.class_label == Labels.SPAM\n",
217+
"print(prediction)"
218+
]
219+
},
220+
{
221+
"cell_type": "markdown",
222+
"metadata": {},
223+
"source": [
224+
"### Multi-Label Classification"
176225
]
177226
},
178227
{
179228
"cell_type": "code",
180-
"execution_count": 32,
229+
"execution_count": 12,
181230
"metadata": {},
182231
"outputs": [
183232
{
184233
"name": "stdout",
185234
"output_type": "stream",
186235
"text": [
187-
"class_labels=[<MultiLabels.BILLING: 'billing'>, <MultiLabels.TECH_ISSUE: 'tech_issue'>]\n"
236+
"class_labels=[<MultiLabels.TECH_ISSUE: 'tech_issue'>, <MultiLabels.BILLING: 'billing'>]\n"
188237
]
189238
}
190239
],
@@ -223,16 +272,27 @@
223272
"print(prediction)"
224273
]
225274
},
275+
{
276+
"cell_type": "markdown",
277+
"metadata": {},
278+
"source"< 341A /span>: [
279+
"## Self-Critique"
280+
]
281+
},
226282
{
227283
"cell_type": "code",
228-
"execution_count": 33,
284+
"execution_count": 13,
229285
"metadata": {},
230286
"outputs": [
231287
{
232288
"name": "stdout",
233289
"output_type": "stream",
234290
"text": [
235-
"question='What is the meaning of life?' answer='The meaning of life, according to the Devil, is to live a life of sin and debauchery.'\n"
291+
"question='What is the meaning of life?' answer='According to the Devil, the meaning of life is to live a life of sin and debauchery.'\n",
292+
"1 validation error for QuestionAnswerNoEvil\n",
293+
"answer\n",
294+
" Assertion failed, The statement promotes sin and debauchery, which can be considered objectionable. [type=assertion_error, input_value='According to the Devil, ... of sin and debauchery.', input_type=str]\n",
295+
" For further information visit https://errors.pydantic.dev/2.3/v/assertion_error\n"
236296
]
237297
}
238298
],
@@ -294,6 +354,13 @@
294354
" print(e)"
295355
]
296356
},
357+
{
358+
"cell_type": "markdown",
359+
"metadata": {},
360+
"source": [
361+
"## Answering Questions with Validated Citations"
362+
]
363+
},
297364
{
298365
"cell_type": "code",
299366
"execution_count": 42,
@@ -366,13 +433,6 @@
366433
"qa = ask_ai(question, context)\n",
367434
"print(qa)"
368435
]
369-
},
370-
{
371-
"cell_type": "code",
372-
"execution_count": null,
373-
"metadata": {},
374-
"outputs": [],
375-
"source": []
376436
}
377437
],
378438
"metadata": {

0 commit comments

Comments
 (0)
0