Skip to content

Commit

Permalink
update support for assistants with tool_resources, top_p and temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
skyscrapr committed May 6, 2024
1 parent 0af38c3 commit 64a2d4e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
40 changes: 29 additions & 11 deletions openai/assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ func (c *Client) Assistants() *AssistantsEndpoint {
}

type Assistant struct {
Id string `json:"id"`
Object string `json:"object"` // The object type, which is always assistant.
CreatedAt int64 `json:"created_at"`
Name *string `json:"name"`
Description *string `json:"description"`
Model string `json:"model"`
Instructions *string `json:"instructions"`
Tools []AssistantTool `json:"tools,omitempty"`
FileIds []string `json:"file_ids"`
MetaData map[string]string `json:"metadata,omitempty"`
Id string `json:"id"`
Object string `json:"object"` // The object type, which is always assistant.
CreatedAt int64 `json:"created_at"`
Name *string `json:"name"`
Description *string `json:"description"`
Model string `json:"model"`
Instructions *string `json:"instructions"`
Tools []AssistantTool `json:"tools,omitempty"`
ToolResources *AssistantToolResources `json:"tool_resources,omitempty"`
MetaData map[string]string `json:"metadata,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
}

type Assistants struct {
Expand All @@ -59,10 +61,13 @@ type AssistantRequest struct {
Tools []AssistantTool `json:"tools,omitempty"`

// A list of file IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. Files are ordered by their creation date in ascending order.
FileIds []string `json:"file_ids,omitempty"`
ToolResources *AssistantToolResources `json:"tool_resources,omitempty"`

// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and va
MetaData map[string]string `json:"metadata,omitempty"`

Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
}

type AssistantFile struct {
Expand Down Expand Up @@ -92,6 +97,19 @@ type AssistantTool struct {
} `json:"function,omitempty"`
}

type AssistantToolResources struct {
CodeInterpreter *struct {
FileIDs []string `json:"file_ids"`
} `json:"code_interpreter,omitempty"`
FileSearch *struct {
VectorStoreIDs []string `json:"vector_store_ids"`
VectorStore *struct {
FileIDs []string `json:"file_ids"`
MetaData map[string]string `json:"metadata,omitempty"`
} `json:"vector_store,omitempty"`
} `json:"file_search,omitempty"`
}

// Create an assistant with a model and instructions.
// [OpenAI Documentation]: https://platform.openai.com/docs/api-reference/assistants/createAssistant
func (e *AssistantsEndpoint) CreateAssistant(req *AssistantRequest) (*Assistant, error) {
Expand Down
15 changes: 12 additions & 3 deletions openai/assistant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/skyscrapr/openai-sdk-go/openai"
"github.com/skyscrapr/openai-sdk-go/openai/test"
openai_test "github.com/skyscrapr/openai-sdk-go/openai/test"
)

func TestCreateAssistant(t *testing.T) {
Expand All @@ -32,8 +32,17 @@ func TestCreateAssistant(t *testing.T) {
Name: &name,
Description: &description,
Instructions: &instructions,
FileIds: []string{"test_file_id_1", "test_file_id_2"},
MetaData: map[string]string{"test_key_1": "test_value_1"},
Tools: []openai.AssistantTool{{
Type: "code_intepreter",
}},
ToolResources: &openai.AssistantToolResources{
CodeInterpreter: &struct {
FileIDs []string "json:\"file_ids\""
}{
FileIDs: []string{"file_1", "file_2"},
},
},
MetaData: map[string]string{"test_key_1": "test_value_1"},
}
_, err := client.Assistants().CreateAssistant(&req)
t.Helper()
Expand Down

0 comments on commit 64a2d4e

Please sign in to comment.