Skip to content

Commit 8708d21

Browse files
author
push edp
committed
feat: support for Assistant stream mode and implemented stream event callbacks
1 parent 12cdb6d commit 8708d21

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

assistant_stream_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestAssistantStream(t *testing.T) {
3030

3131
server.RegisterHandler("/v1/threads/"+theadID+"/runs",
3232
func(w http.ResponseWriter, _ *http.Request) {
33+
//nolint:lll
3334
resBytes := []byte(`
3435
event: thread.run.created
3536
data: {"id":"run_123","object":"thread.run","created_at":1710330640,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710331240,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"file_ids":[],"metadata":{},"usage":null}
@@ -133,6 +134,7 @@ func TestAssistantStreamWithTools(t *testing.T) {
133134

134135
server.RegisterHandler("/v1/threads/"+theadID+"/runs/"+runID+"/submit_tool_outputs",
135136
func(w http.ResponseWriter, _ *http.Request) {
137+
//nolint:lll
136138
resBytes := []byte(`
137139
event: thread.run.step.completed
138140
data: {"id":"step_001","object":"thread.run.step","created_at":1710352449,"run_id":"run_123","assistant_id":"asst_123","thread_id":"thread_123","type":"tool_calls","status":"completed","cancelled_at":null,"completed_at":1710352475,"expires_at":1710353047,"failed_at":null,"last_error":null,"step_details":{"type":"tool_calls","tool_calls":[{"id":"call_iWr0kQ2EaYMaxNdl0v3KYkx7","type":"function","function":{"name":"get_current_weather","arguments":"{\"location\":\"San Francisco, CA\",\"unit\":\"fahrenheit\"}","output":"70 degrees and sunny."}}]},"usage":{"prompt_tokens":291,"completion_tokens":24,"total_tokens":315}}
@@ -197,6 +199,7 @@ data: [DONE]
197199

198200
server.RegisterHandler("/v1/threads/"+theadID+"/runs",
199201
func(w http.ResponseWriter, _ *http.Request) {
202+
//nolint:lll
200203
resBytes := []byte(`
201204
event: thread.run.created
202205
data: {"id":"run_123","object":"thread.run","created_at":1710330640,"assistant_id":"asst_123","thread_id":"thread_123","status":"queued","started_at":null,"expires_at":1710331240,"cancelled_at":null,"failed_at":null,"completed_at":null,"required_action":null,"last_error":null,"model":"gpt-4-turbo","instructions":null,"tools":[],"file_ids":[],"metadata":{},"usage":null}
@@ -334,6 +337,7 @@ data: [DONE]
334337
t.Fatalf("ToolOutputs error, %v", toolOuputs)
335338
}
336339

340+
//nolint:lll
337341
stream, err = client.CreateAssistantThreadRunSubmitToolOutputStream(ctx, theadID, runID, openai.SubmitToolOutputsRequest{
338342
ToolOutputs: toolOuputs,
339343
})

messages.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ type MessageFilesList struct {
7676
type MessageDelta struct {
7777
Content []MessageDeltaContent `json:"content"`
7878
Role string `json:"role"`
79-
FileIds []string `json:"file_ids,omitempty"`
79+
FileIds []string `json:"file_ids,omitempty"` //nolint:revive // backwards-compatibility
80+
8081
}
8182

8283
type MessageDeltaContent struct {

0 commit comments

Comments
 (0)