File tree Expand file tree Collapse file tree 3 files changed +23
-6
lines changed
Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -7,14 +7,17 @@ local status, response = client:chat({
77 {
88 role = " user" ,
99 content = {
10- { type = " image_url" , image_url = " https://leafo.net/hi.png" },
10+ { type = " image_url" , image_url = { url = " https://leafo.net/hi.png" } },
1111 { type = " text" , text = " Describe this image" }
1212 }
1313 }
1414}, {
15- model = " gpt-4-vision-preview"
15+ -- model = "gpt-4-vision-preview" -- not needed anymore, all modern models support vision
1616})
1717
1818if status == 200 then
1919 print (response .choices [1 ].message .content )
20+ else
21+ print (" Got unexpected status:" , status )
22+ print (require (" cjson" ).encode (response ))
2023end
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ local content_format = types.string + types.array_of(types.one_of({
99 }),
1010 types .shape ({
1111 type = " image_url" ,
12- image_url = types .string + types . partial ({
12+ image_url = types .partial ({
1313 url = types .string
1414 })
1515 })
203203 return nil , err , response
204204 end
205205 if append_response then
206- self :append_message (out .message )
206+ local message = {
207+ role = out .message .role ,
208+ content = out .message .content
209+ }
210+ if out .message .function_call then
211+ message .function_call = out .message .function_call
212+ end
213+ self :append_message (message )
207214 end
208215 return out .response or out .message
209216 end
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ empty = (types.nil + types.literal(cjson.null))\describe "nullable"
77
88content_format = types. string + types. array_of types. one_of {
99 types. shape { type : " text" , text : types. string }
10- types. shape { type : " image_url" , image_url : types. string + types . partial {
10+ types. shape { type : " image_url" , image_url : types. partial {
1111 url : types. string
1212 }}
1313}
@@ -232,7 +232,14 @@ class ChatSession
232232 return nil , err, response
233233
234234 if append_response
235- @append_message out. message
235+ -- only append the fields needed for chat history, not extra API fields like annotations
236+ message = {
237+ role : out. message. role
238+ content : out. message. content
239+ }
240+ if out. message. function_call
241+ message. function_call = out. message. function_call
242+ @append_message message
236243
237244 -- response is missing for function_calls, so we return the entire message object
238245 out. response or out. message
You can’t perform that action at this time.
0 commit comments