Skip to content

Commit 273874f

Browse files
authored
Merge pull request #23 from pamelafox/openaifixes
Update openai examples in cookbook
2 parents 08ae7f3 + 2500aea commit 273874f

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
azure-ai-inference~=1.0.0b4
22
azure-ai-evaluation~=1.1.0
3-
openai~=1.37.1
3+
openai~=1.72.0
44
mistralai~=0.4.2
55
python-dotenv~=1.0.1
66
ipykernel~=6.29.5

samples/python/openai/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ To run these notebooks, click on a link below to open it in Codespaces and selec
1414
To run these scripts, open your terminal and run a command like:
1515

1616
```shell
17-
python3 samples/python/openai/basic.py
17+
python samples/python/openai/basic.py
1818
```
1919

2020
* [basic.py](basic.py): basic call to the gpt-4o-mini chat completion API

samples/python/openai/embeddings_getting_started.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
],
133133
"metadata": {
134134
"kernelspec": {
135-
"display_name": "gh-cookbook",
135+
"display_name": "Python 3",
136136
"language": "python",
137137
"name": "python3"
138138
},

samples/python/openai/getting_started.ipynb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,10 @@
259259
"\n",
260260
"# Print the streamed response\n",
261261
"for update in response:\n",
262-
" if update.choices[0].delta.content:\n",
263-
" print(update.choices[0].delta.content, end=\"\")\n"
262+
" if update.choices:\n",
263+
" content = update.choices[0].delta.content\n",
264+
" if content:\n",
265+
" print(content, end=\"\")\n"
264266
]
265267
},
266268
{
@@ -404,7 +406,7 @@
404406
],
405407
"metadata": {
406408
"kernelspec": {
407-
"display_name": "gh-cookbook",
409+
"display_name": "Python 3",
408410
"language": "python",
409411
"name": "python3"
410412
},

samples/python/openai/streaming.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434

3535
# Print the streamed response
3636
for update in response:
37-
if update.choices[0].delta.content:
38-
print(update.choices[0].delta.content, end="")
37+
if update.choices:
38+
content = update.choices[0].delta.content
39+
if content:
40+
print(content, end="")
3941

4042
print()

0 commit comments

Comments
 (0)