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
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -445,6 +445,11 @@ Appends a message to the chat history and triggers a completion with
445
445
`generate_response` and returns the response as a string. On failure, returns
446
446
`nil`, an error message, and the raw request response.
447
447
448
+
On success, a second return value contains the raw API response. For
449
+
non-streaming requests this is the decoded response object (including fields
450
+
like `usage`); for streaming requests it is the raw SSE payload string. The
451
+
latest raw response is also stored on `chat.last_response`.
452
+
448
453
If the response includes `tool_calls` or a `function_call`, the entire message
449
454
object is returned instead of a string. You can send the result back by passing
450
455
a `role = "tool"` message (with `tool_call_id`) or a `role = "function"` message
@@ -488,6 +493,18 @@ Calls the OpenAI API to generate the next response for the stored chat history.
488
493
Returns the response as a string. On failure, returns `nil`, an error message,
489
494
and the raw request response.
490
495
496
+
On success, a second return value contains the raw API response. For
497
+
non-streaming requests this is the decoded response object, so you can inspect
498
+
fields like `usage`:
499
+
500
+
```lua
501
+
localtext, raw=chat:generate_response()
502
+
print(text)
503
+
print(raw.usage.total_tokens)
504
+
```
505
+
506
+
The latest raw response is also stored on `chat.last_response`.
507
+
491
508
-`append_response`: Whether the response should be appended to the chat history (default: true).
492
509
-`opts`: (optional) A table of per-request overrides. For backward compatibility, a function can be passed and will be treated as `{stream_callback = fn}`.
0 commit comments