Skip to content

Commit

Permalink
fix: support ThreadMessage.Content as an array
Browse files Browse the repository at this point in the history
FileIDs on ThreadMessage isn't supported anymore, but Content can be
an array.

Fixes: sashabaranov#773
  • Loading branch information
adamdecaf committed Aug 26, 2024
1 parent 6439e1f commit d6c7739
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
10 changes: 8 additions & 2 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,21 @@ func TestRun(t *testing.T) {
_, err = client.CancelRun(ctx, threadID, runID)
checks.NoError(t, err, "CancelRun error")

prompt := "Hello, World!"
_, err = client.CreateThreadAndRun(ctx, openai.CreateThreadAndRunRequest{
RunRequest: openai.RunRequest{
AssistantID: assistantID,
},
Thread: openai.ThreadRequest{
Messages: []openai.ThreadMessage{
{
Role: openai.ThreadMessageRoleUser,
Content: "Hello, World!",
Role: openai.ThreadMessageRoleUser,
Content: []openai.ThreadMessageContent{
{
Type: "text",
Text: prompt,
},
},
},
},
},
Expand Down
20 changes: 15 additions & 5 deletions thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,21 @@ const (
)

type ThreadMessage struct {
Role ThreadMessageRole `json:"role"`
Content string `json:"content"`
FileIDs []string `json:"file_ids,omitempty"`
Attachments []ThreadAttachment `json:"attachments,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Role ThreadMessageRole `json:"role"`
Content []ThreadMessageContent `json:"content"`
Attachments []ThreadAttachment `json:"attachments,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}

type ThreadMessageContent struct {
Type string `json:"type"`
ImageFile *ThreadMessageImageFile `json:"image_file,omitempty"`
Text string `json:"text,omitempty"`
}

type ThreadMessageImageFile struct {
FileID string `json:"file_id"`
Detail *string `json:"detail,omitempty"`
}

type ThreadAttachment struct {
Expand Down
20 changes: 16 additions & 4 deletions thread_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ func TestThread(t *testing.T) {

ctx := context.Background()

prompt := "Hello, World!"
_, err := client.CreateThread(ctx, openai.ThreadRequest{
Messages: []openai.ThreadMessage{
{
Role: openai.ThreadMessageRoleUser,
Content: "Hello, World!",
Role: openai.ThreadMessageRoleUser,
Content: []openai.ThreadMessageContent{
{
Type: "text",
Text: prompt,
},
},
},
},
})
Expand Down Expand Up @@ -153,11 +159,17 @@ func TestAzureThread(t *testing.T) {

ctx := context.Background()

prompt := "Hello, World!"
_, err := client.CreateThread(ctx, openai.ThreadRequest{
Messages: []openai.ThreadMessage{
{
Role: openai.ThreadMessageRoleUser,
Content: "Hello, World!",
Role: openai.ThreadMessageRoleUser,
Content: []openai.ThreadMessageContent{
{
Type: "text",
Text: prompt,
},
},
},
},
})
Expand Down

0 comments on commit d6c7739

Please sign in to comment.