You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+66-1Lines changed: 66 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1072,6 +1072,71 @@ run_id = response['id']
1072
1072
thread_id = response['thread_id']
1073
1073
```
1074
1074
1075
+
#### Vision in a thread
1076
+
1077
+
You can include images in a thread and they will be described & read by the LLM. In this example I'm using [this file](https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png):
1078
+
1079
+
```
1080
+
require "openai"
1081
+
1082
+
# Make a client
1083
+
client = OpenAI::Client.new(
1084
+
access_token: "access_token_goes_here",
1085
+
log_errors: true # Don't log errors in production.
1086
+
)
1087
+
1088
+
# Upload image as a file
1089
+
file_id = client.files.upload(
1090
+
parameters: {
1091
+
file: "path/to/example.png",
1092
+
purpose: "assistants"
1093
+
}
1094
+
)["id"]
1095
+
1096
+
# Create assistant
1097
+
assistant_id = client.assistants.create(
1098
+
parameters: {
1099
+
model: "gpt-4o",
1100
+
name: "Image reader",
1101
+
instructions: "You are an image describer. You describe the contents of images."
1102
+
})["id"]
1103
+
1104
+
# Create thread
1105
+
thread_id = client.threads.create["id"]
1106
+
1107
+
# Add image in message
1108
+
client.messages.create(
1109
+
thread_id: thread_id,
1110
+
parameters: {
1111
+
role: "user", # Required for manually created messages
=> "The image contains a placeholder graphic with a tilted, stylized representation of a postage stamp in the top part, which includes an abstract landscape with hills and a sun. Below the stamp, in the middle of the image, there is italicized text in a light golden color that reads, \"This is just an example.\" The background is a light pastel shade, and a yellow border frames the entire image."
1138
+
```
1139
+
1075
1140
#### Runs involving function tools
1076
1141
1077
1142
In case you are allowing the assistant to access `function` tools (they are defined in the same way as functions during chat completion), you might get a status code of `requires_action` when the assistant wants you to evaluate one or more function tools:
@@ -1128,7 +1193,7 @@ require "openai"
1128
1193
# Make a client
1129
1194
client = OpenAI::Client.new(
1130
1195
access_token: "access_token_goes_here",
1131
-
log_errors: true # Don't do this in production.
1196
+
log_errors: true # Don't log errors in production.
0 commit comments