Skip to content

Commit 192b8f2

Browse files
authored
docs(readme): add examples for chat with image content (#1703)
1 parent 73f9fda commit 192b8f2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,48 @@ we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
5151
to add `OPENAI_API_KEY="My API Key"` to your `.env` file
5252
so that your API Key is not stored in source control.
5353

54+
### Vision
55+
56+
With a hosted image:
57+
58+
```python
59+
response = client.chat.completions.create(
60+
model="gpt-4o-mini",
61+
messages=[
62+
{
63+
"role": "user",
64+
"content": [
65+
{"type": "text", "text": prompt},
66+
{
67+
"type": "image_url",
68+
"image_url": {"url": f"{img_url}"},
69+
},
70+
],
71+
}
72+
],
73+
)
74+
```
75+
76+
With the image as a base64 encoded string:
77+
78+
```python
79+
response = client.chat.completions.create(
80+
model="gpt-4o-mini",
81+
messages=[
82+
{
83+
"role": "user",
84+
"content": [
85+
{"type": "text", "text": prompt},
86+
{
87+
"type": "image_url",
88+
"image_url": {"url": f"data:{img_type};base64,{img_b64_str}"},
89+
},
90+
],
91+
}
92+
],
93+
)
94+
```
95+
5496
### Polling Helpers
5597

5698
When interacting with the API some actions such as starting a Run and adding files to vector stores are asynchronous and take time to complete. The SDK includes

0 commit comments

Comments
 (0)