Skip to content

Commit

Permalink
feat: provide vector store (#772)
Browse files Browse the repository at this point in the history
* implement vectore store feature

* fix after integration testing

* fix golint error

* improve test to increare code coverage

* fix golint anc code coverage problem

* add tool_resource in assistant response

* chore: code style

* feat: use pagination param

* feat: use pagination param

* test: use pagination param

* test: rm unused code

---------

Co-authored-by: Denny Depok <[email protected]>
Co-authored-by: eric.p <eric.p>
  • Loading branch information
Pengguancheng and kodernubie authored Jun 19, 2024
1 parent 68acf22 commit 0a42130
Show file tree
Hide file tree
Showing 4 changed files with 728 additions and 18 deletions.
50 changes: 33 additions & 17 deletions assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ const (
)

type Assistant struct {
ID string `json:"id"`
Object string `json:"object"`
CreatedAt int64 `json:"created_at"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Model string `json:"model"`
Instructions *string `json:"instructions,omitempty"`
Tools []AssistantTool `json:"tools"`
FileIDs []string `json:"file_ids,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
ID string `json:"id"`
Object string `json:"object"`
CreatedAt int64 `json:"created_at"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Model string `json:"model"`
Instructions *string `json:"instructions,omitempty"`
Tools []AssistantTool `json:"tools"`
FileIDs []string `json:"file_ids,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
ToolResources *AssistantToolResource `json:"tool_resources,omitempty"`

httpHeader
}
Expand All @@ -34,26 +35,41 @@ const (
AssistantToolTypeCodeInterpreter AssistantToolType = "code_interpreter"
AssistantToolTypeRetrieval AssistantToolType = "retrieval"
AssistantToolTypeFunction AssistantToolType = "function"
AssistantToolTypeFileSearch AssistantToolType = "file_search"
)

type AssistantTool struct {
Type AssistantToolType `json:"type"`
Function *FunctionDefinition `json:"function,omitempty"`
}

type AssistantToolFileSearch struct {
VectorStoreIDs []string `json:"vector_store_ids"`
}

type AssistantToolCodeInterpreter struct {
FileIDs []string `json:"file_ids"`
}

type AssistantToolResource struct {
FileSearch *AssistantToolFileSearch `json:"file_search,omitempty"`
CodeInterpreter *AssistantToolCodeInterpreter `json:"code_interpreter,omitempty"`
}

// AssistantRequest provides the assistant request parameters.
// When modifying the tools the API functions as the following:
// If Tools is undefined, no changes are made to the Assistant's tools.
// If Tools is empty slice it will effectively delete all of the Assistant's tools.
// If Tools is populated, it will replace all of the existing Assistant's tools with the provided tools.
type AssistantRequest struct {
Model string `json:"model"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Instructions *string `json:"instructions,omitempty"`
Tools []AssistantTool `json:"-"`
FileIDs []string `json:"file_ids,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Model string `json:"model"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Instructions *string `json:"instructions,omitempty"`
Tools []AssistantTool `json:"-"`
FileIDs []string `json:"file_ids,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
ToolResources *AssistantToolResource `json:"tool_resources,omitempty"`
}

// MarshalJSON provides a custom marshaller for the assistant request to handle the API use cases
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (

const AzureAPIKeyHeader = "api-key"

const defaultAssistantVersion = "v1" // This will be deprecated by the end of 2024.
const defaultAssistantVersion = "v2" // upgrade to v2 to support vector store

// ClientConfig is a configuration of a client.
type ClientConfig struct {
Expand Down
Loading

0 comments on commit 0a42130

Please sign in to comment.