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
+55-3Lines changed: 55 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,8 +124,9 @@ client:create_response({
124
124
}, {
125
125
stream=true
126
126
}, function(chunk)
127
-
ifchunk.text_deltathen
128
-
io.stdout:write(chunk.text_delta)
127
+
-- Raw event object from API: check type and access delta directly
128
+
ifchunk.type=="response.output_text.delta" then
129
+
io.stdout:write(chunk.delta)
129
130
io.stdout:flush()
130
131
end
131
132
end)
@@ -246,7 +247,7 @@ Sends a request to the `/responses` endpoint (Responses API).
246
247
247
248
-`input`: A string or array of message objects (with `role` and `content` fields)
248
249
-`opts`: Additional options passed directly to the API (eg. model, temperature, instructions, tools, previous_response_id, etc.) https://platform.openai.com/docs/api-reference/responses
249
-
-`stream_callback`: Optional function called for each parsed chunk when `stream = true` is passed in opts
250
+
-`stream_callback`: Optional function called for each raw event object when `stream = true` is passed in opts (eg. `{type = "response.output_text.delta", delta = "Hello"}`)
250
251
251
252
Returns HTTP status, response object, and output headers. The response object
252
253
will be decoded from JSON if possible, otherwise the raw string is returned.
@@ -320,6 +321,57 @@ Sends a request to the `/images/generations` endpoint to generate images.
320
321
321
322
Returns HTTP status, response object, and output headers.
322
323
324
+
#### ResponsesChatSession
325
+
326
+
This class manages chat sessions using OpenAI's Responses API. Unlike
327
+
ChatSession, conversation state is maintained server-side via
328
+
`previous_response_id`. Typically created with `new_responses_chat_session`.
329
+
330
+
The field `response_history` stores an array of response objects from past
331
+
interactions. The field `current_response_id` holds the ID of the most recent
332
+
response, used to maintain conversation continuity.
333
+
334
+
##### `new(client, opts)`
335
+
336
+
Constructor for the ResponsesChatSession.
337
+
338
+
-`client`: An instance of the OpenAI client.
339
+
-`opts`: An optional table of options.
340
+
-`model`: Model to use (defaults to client's default_model)
341
+
-`instructions`: System instructions for the conversation
342
+
-`tools`: Array of tool definitions
343
+
-`previous_response_id`: Resume from a previous response
344
+
345
+
##### `session:send(input, stream_callback)`
346
+
347
+
Sends input and returns the response, maintaining conversation state
348
+
automatically.
349
+
350
+
-`input`: A string or array of message objects.
351
+
-`stream_callback`: Optional function for streaming responses.
352
+
353
+
Returns a response object on success (or accumulated text string when
354
+
streaming). On failure, returns `nil`, an error message, and the raw response.
355
+
356
+
Response objects have helper methods:
357
+
-`response:get_output_text()`: Extract all text content as a string
358
+
-`response:get_images()`: Extract generated images (when using image_generation tool)
359
+
-`tostring(response)`: Converts to text string
360
+
361
+
The `stream_callback` receives two arguments: the delta text string and the raw
362
+
event object. Each call provides an incremental piece of the response text.
0 commit comments