Skip to content

Commit 0184a29

Browse files
author
Loris Mendiondo
committed
add support for assistant vision model, partial implementation of https://platform.openai.com/docs/assistants/migration
1 parent ed6f494 commit 0184a29

File tree

3 files changed

+56
-25
lines changed

3 files changed

+56
-25
lines changed

assistant.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,39 @@ const (
1414
)
1515

1616
type Assistant struct {
17-
ID string `json:"id"`
18-
Object string `json:"object"`
19-
CreatedAt int64 `json:"created_at"`
20-
Name *string `json:"name,omitempty"`
21-
Description *string `json:"description,omitempty"`
22-
Model string `json:"model"`
23-
Instructions *string `json:"instructions,omitempty"`
24-
Tools []AssistantTool `json:"tools"`
25-
FileIDs []string `json:"file_ids,omitempty"`
26-
Metadata map[string]any `json:"metadata,omitempty"`
17+
ID string `json:"id"`
18+
Object string `json:"object"`
19+
CreatedAt int64 `json:"created_at"`
20+
Name *string `json:"name,omitempty"`
21+
Description *string `json:"description,omitempty"`
22+
Model string `json:"model"`
23+
Instructions *string `json:"instructions,omitempty"`
24+
Tools []AssistantTool `json:"tools"`
25+
FileIDs []string `json:"file_ids,omitempty"`
26+
Metadata map[string]any `json:"metadata,omitempty"`
27+
ToolResources ToolResources `json:"tool_resources,omitempty"`
2728

2829
httpHeader
2930
}
3031

32+
type ToolResources struct {
33+
FileSearch *FileSearchResources `json:"file_search,omitempty"`
34+
CodeInterpreter *CodeInterpreterResources `json:"code_interpreter,omitempty"`
35+
}
36+
37+
type FileSearchResources struct {
38+
VectorStoreIDs []string `json:"vector_store_ids"`
39+
}
40+
41+
type CodeInterpreterResources struct {
42+
FileIDs []string `json:"file_ids"`
43+
}
44+
3145
type AssistantToolType string
3246

3347
const (
3448
AssistantToolTypeCodeInterpreter AssistantToolType = "code_interpreter"
35-
AssistantToolTypeRetrieval AssistantToolType = "retrieval"
49+
AssistantToolTypeFileSearch AssistantToolType = "file_search"
3650
AssistantToolTypeFunction AssistantToolType = "function"
3751
)
3852

messages.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,29 @@ const (
1212
)
1313

1414
type Message struct {
15-
ID string `json:"id"`
16-
Object string `json:"object"`
17-
CreatedAt int `json:"created_at"`
18-
ThreadID string `json:"thread_id"`
19-
Role string `json:"role"`
20-
Content []MessageContent `json:"content"`
21-
FileIds []string `json:"file_ids"` //nolint:revive //backwards-compatibility
22-
AssistantID *string `json:"assistant_id,omitempty"`
23-
RunID *string `json:"run_id,omitempty"`
24-
Metadata map[string]any `json:"metadata"`
15+
ID string `json:"id"`
16+
Object string `json:"object"`
17+
CreatedAt int `json:"created_at"`
18+
ThreadID string `json:"thread_id"`
19+
Role string `json:"role"`
20+
Content []MessageContent `json:"content"`
21+
AssistantID *string `json:"assistant_id,omitempty"`
22+
RunID *string `json:"run_id,omitempty"`
23+
Metadata map[string]any `json:"metadata"`
24+
Attachments []MessageAttachment `json:"attachments,omitempty"`
2525

2626
httpHeader
2727
}
2828

29+
type MessageAttachment struct {
30+
FileID string `json:"file_id"`
31+
Tools []MessageTool `json:"tools"`
32+
}
33+
34+
type MessageTool struct {
35+
Type string `json:"type"`
36+
}
37+
2938
type MessagesList struct {
3039
Messages []Message `json:"data"`
3140

@@ -42,6 +51,7 @@ type MessageContent struct {
4251
Text *MessageText `json:"text,omitempty"`
4352
ImageFile *ImageFile `json:"image_file,omitempty"`
4453
}
54+
4555
type MessageText struct {
4656
Value string `json:"value"`
4757
Annotations []any `json:"annotations"`

thread.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ const (
3333
ThreadMessageRoleUser ThreadMessageRole = "user"
3434
)
3535

36+
type ContentInterface interface{}
37+
3638
type ThreadMessage struct {
37-
Role ThreadMessageRole `json:"role"`
38-
Content string `json:"content"`
39-
FileIDs []string `json:"file_ids,omitempty"`
40-
Metadata map[string]any `json:"metadata,omitempty"`
39+
Role ThreadMessageRole `json:"role"`
40+
Content ContentInterface `json:"content"`
41+
Metadata map[string]any `json:"metadata,omitempty"`
42+
Attachments []ThreadAttachment `json:"attachments,omitempty"`
43+
}
44+
45+
type ThreadAttachment struct {
46+
FileID string `json:"file_id"`
47+
Tools []MessageTool `json:"tools,omitempty"`
4148
}
4249

4350
type ThreadDeleteResponse struct {

0 commit comments

Comments
 (0)