Documentation
¶
Index ¶
- func CreateAuthorizedHTTPRequest(ctx context.Context, c Client, method, path string, bodyRdr io.Reader) (*http.Request, error)
- func CreateDeleteHTTPRequest(ctx context.Context, c Client, path string) (*http.Request, error)
- func CreateJSONRequest(ctx context.Context, c Client, method, path string, bodyV interface{}) (*http.Request, error)
- func CreateUploadFileHTTPRequest(ctx context.Context, c Client, fileName string, fileData []byte) (*http.Request, error)
- func DoHTTPRequest(ctx context.Context, c Client, req *http.Request, resp interface{}) error
- type Assistant
- type AssistantBase
- type ChatChoice
- type ChatDefaultResponse
- type ChatRequest
- type Client
- func (c Client) Chat(ctx context.Context, req ChatRequest) (string, error)
- func (c Client) CreateAssistant(ctx context.Context, bodyV NewAssistantRequest) (Assistant, error)
- func (c Client) CreateThreadAndRun(ctx context.Context, req NewThreadAndRunRequest) (ThreadRun, error)
- func (c Client) CreateThreadAndRunCompleted(ctx context.Context, req NewThreadAndRunRequest) (ThreadRun, error)
- func (c Client) Delete(ctx context.Context, path string) error
- func (c Client) DeleteAssistant(ctx context.Context, id string) error
- func (c Client) DeleteFile(ctx context.Context, id string) error
- func (c Client) GetThread(ctx context.Context, threadID string) (Thread, error)
- func (c Client) GetThreadMessages(ctx context.Context, threadID string) ([]ThreadMessage, error)
- func (c Client) GetThreadRun(ctx context.Context, threadID, runID string) (ThreadRun, error)
- func (c Client) GetThreadRunResponse(ctx context.Context, threadID string, runID string) (string, error)
- func (c Client) MakeChatRequest(ctx context.Context, reqV ChatRequest, respV interface{}) error
- func (c Client) NewChatWithAssistant(ctx context.Context, req NewThreadAndRunRequest) (string, error)
- func (c Client) NewThread(ctx context.Context, req ThreadInput) (Thread, error)
- func (c Client) NewThreadRun(ctx context.Context, threadID string, req ThreadRunInput) (ThreadRun, error)
- func (c Client) NewThreadRunComplete(ctx context.Context, threadID string, req ThreadRunInput) (ThreadRun, error)
- func (c Client) UploadFile(ctx context.Context, fileName string, fileData []byte) (File, error)
- func (c Client) WaitForThreadRunCompletion(ctx context.Context, threadID, runID string) (ThreadRun, error)
- type DeleteResponse
- type Error
- type File
- type JSONSchema
- type Message
- type MessageResponseFormat
- type MessageResponseFormatJSONSchema
- type Model
- type NewAssistantRequest
- type NewThreadAndRunRequest
- type Role
- type Thread
- type ThreadBase
- type ThreadInput
- type ThreadMessage
- type ThreadMessageBase
- type ThreadMessageContent
- type ThreadMessageContentText
- type ThreadMessageInput
- type ThreadMessagesResponse
- type ThreadRun
- type ThreadRunInput
- type Tool
- type ToolResources
- type ToolResourcesCodeInterpreter
- type ToolResourcesFileSearch
- type ToolResourcesFileSearchVectorStore
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateDeleteHTTPRequest ¶
func CreateJSONRequest ¶
Types ¶
type Assistant ¶
type Assistant struct {
ID string `json:"id"`
CreatedAt int `json:"created_at"`
AssistantBase `json:",inline"`
}
type AssistantBase ¶
type AssistantBase struct {
Model Model `json:"model"` // gpt-4o
Name string `json:"name"`
Description string `json:"description"`
Tools []Tool `json:"tools"`
ToolResources ToolResources `json:"tool_resources"`
Instructions string `json:"instructions"`
ResponseFormat interface{} `json:"response_format,omitempty"`
}
type ChatChoice ¶
type ChatChoice struct {
FinishReason string `json:"finish_reason"`
Index int `json:"index"`
Logprobs string `json:"logprobs"`
Message Message `json:"message"`
}
Response Types
type ChatDefaultResponse ¶
type ChatDefaultResponse struct {
Choices []ChatChoice `json:"choices,omitempty"`
Created int `json:"created,omitempty"`
ID string `json:"id,omitempty"`
Model string `json:"model,omitempty"`
Object string `json:"object,omitempty"`
SystemFingerprint string `json:"system_fingerprint"`
Usage *Usage `json:"usage,omitempty"`
Error *Error `json:"error,omitempty"`
}
Response Types
type ChatRequest ¶
type ChatRequest struct {
Model Model `json:"model"`
Messages []Message `json:"messages"`
ResponseFormat *MessageResponseFormat `json:"response_format,omitempty"`
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"` // -2 to 2: Low value = more deterministic, high value = more random
Temperature float64 `json:"temperature,omitempty"` // 0-2: Low value = more deterministic, high value = more random
}
Request Types
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClientWithKey ¶
NewClient creates a new OpenAI client based on HTTP.
func (Client) CreateAssistant ¶
func (Client) CreateThreadAndRun ¶
func (Client) CreateThreadAndRunCompleted ¶
func (Client) DeleteAssistant ¶
func (Client) GetThreadMessages ¶
func (Client) GetThreadRun ¶
func (Client) GetThreadRunResponse ¶
func (Client) MakeChatRequest ¶
func (c Client) MakeChatRequest(ctx context.Context, reqV ChatRequest, respV interface{}) error
Chat sends a chat request to the OpenAI API.
func (Client) NewChatWithAssistant ¶
func (Client) NewThreadRun ¶
func (Client) NewThreadRunComplete ¶
func (Client) UploadFile ¶
type DeleteResponse ¶
type DeleteResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Deleted bool `json:"deleted"`
}
{
"id": "asst_e5qL6DqZr0gD2PpYjpRAg4BQ",
"object": "assistant.deleted",
"deleted": true
}
type Error ¶
type Error struct {
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
Param string `json:"param,omitempty"`
Type string `json:"type,omitempty"`
}
Response Types
type File ¶
type File struct {
Object string `json:"object"`
ID string `json:"id"`
Purpose string `json:"purpose"`
Filename string `json:"filename"`
Bytes int `json:"bytes"`
CreatedAt int `json:"created_at"`
Status string `json:"status"`
StatusDetail *string `json:"status_details"`
}
{
"object": "file",
"id": "file-xDqy7hp1VUKBItRWOeIxto3r",
"purpose": "assistants",
"filename": "goku-schemasys-lock.json",
"bytes": 80476,
"created_at": 1731908604,
"status": "processed",
"status_details": null
}
type JSONSchema ¶
type JSONSchema []byte
Request Types
func NewJSONSchemaFromStruct ¶
func NewJSONSchemaFromStruct(v interface{}) (JSONSchema, error)
func (JSONSchema) MarshalJSON ¶
func (v JSONSchema) MarshalJSON() ([]byte, error)
func (*JSONSchema) UnmarshalJSON ¶
func (v *JSONSchema) UnmarshalJSON(data []byte) error
type Message ¶
type Message struct {
Role Role `json:"role"`
Content string `json:"content"`
Refusal string `json:"refusal,omitempty"` // Optional: Only in responses, if the assistant refuses to respond.
}
Shared Types
type MessageResponseFormat ¶
type MessageResponseFormat struct {
Type string `json:"type,omitempty"`
JSONSchema MessageResponseFormatJSONSchema `json:"json_schema,omitempty"`
}
Request Types
type MessageResponseFormatJSONSchema ¶
type MessageResponseFormatJSONSchema struct {
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
Strict bool `json:"strict,omitempty"`
Schema JSONSchema `json:"schema,omitempty"`
}
Request Types
type NewAssistantRequest ¶
type NewAssistantRequest struct {
AssistantBase `json:",inline"`
}
type NewThreadAndRunRequest ¶
type NewThreadAndRunRequest struct {
AssistantID string `json:"assistant_id"`
Thread ThreadInput `json:"thread,omitempty"` // Optional (if we want to provide initial messages)
ToolResources ToolResources `json:"tool_resources,omitempty"` // Maybe allows us to provide more files to the assistant?
ResponseFormat *MessageResponseFormat `json:"response_format,omitempty"`
}
type Thread ¶
type Thread struct {
ID string `json:"id,omitempty"`
ThreadBase `json:",inline"`
}
type ThreadBase ¶
type ThreadBase struct{}
type ThreadInput ¶
type ThreadInput struct {
Messages []ThreadMessageInput `json:"messages,omitempty"` // only for initial messages, in the Thread request
ThreadBase `json:",inline"`
}
type ThreadMessage ¶
type ThreadMessage struct {
ThreadMessageBase `json:",inline"`
Content []ThreadMessageContent `json:"content"`
ID string `json:"id"`
CreatedAt int `json:"created_at"`
AssistantID string `json:"assistant_id"`
ThreadID string `json:"thread_id"`
RunID string `json:"run_id"`
}
type ThreadMessageBase ¶
type ThreadMessageBase struct {
Role Role `json:"role"`
}
type ThreadMessageContent ¶
type ThreadMessageContent struct {
Type string `json:"type"`
Text ThreadMessageContentText `json:"text"`
}
type ThreadMessageContentText ¶
type ThreadMessageContentText struct {
Value string `json:"value"`
Annotations []interface{} `json:"annotations"`
}
type ThreadMessageInput ¶
type ThreadMessageInput struct {
ThreadMessageBase `json:",inline"`
Content string `json:"content"`
}
type ThreadMessagesResponse ¶
type ThreadMessagesResponse struct {
Object string `json:"object"`
Data []ThreadMessage `json:"data"`
}
type ThreadRun ¶
type ThreadRun struct {
ID string `json:"id"`
Object string `json:"object"` // Always "thread.run"
CreatedAt int `json:"created_at"`
AssistantID string `json:"assistant_id"`
ThreadID string `json:"thread_id"`
Status string `json:"status"`
StartedAt int `json:"started_at"`
ExpiresAt int `json:"expires_at"`
CancelledAt int `json:"cancelled_at"`
FailedAt int `json:"failed_at"`
CompletedAt int `json:"completed_at"`
LastError *Error `json:"last_error,omitempty"`
Model Model `json:"model"`
Instructions string `json:"instructions"`
Tools []Tool `json:"tools"`
Metadata struct{} `json:"metadata"`
IncompleteDetails string `json:"incomplete_details"`
Usage Usage `json:"usage"`
Temperature float64 `json:"temperature"`
TopP float64 `json:"top_p"`
MaxPromptTokens int `json:"max_prompt_tokens"`
MaxCompletionTokens int `json:"max_completion_tokens"`
TruncationStrategy struct {
Type string `json:"type"`
LastMessages string `json:"last_messages"`
} `json:"truncation_strategy"`
ResponseFormat interface{} `json:"response_format"`
ToolChoice string `json:"tool_choice"`
ParallelToolCalls bool `json:"parallel_tool_calls"`
}
{
"id": "run_abc123",
"object": "thread.run",
"created_at": 1698107661,
"assistant_id": "asst_abc123",
"thread_id": "thread_abc123",
"status": "completed",
"started_at": 1699073476,
"expires_at": null,
"cancelled_at": null,
"failed_at": null,
"completed_at": 1699073498,
"last_error": null,
"model": "gpt-4o",
"instructions": null,
"tools": [{"type": "file_search"}, {"type": "code_interpreter"}],
"metadata": {},
"incomplete_details": null,
"usage": {
"prompt_tokens": 123,
"completion_tokens": 456,
"total_tokens": 579
},
"temperature": 1.0,
"top_p": 1.0,
"max_prompt_tokens": 1000,
"max_completion_tokens": 1000,
"truncation_strategy": {
"type": "auto",
"last_messages": null
},
"response_format": "auto",
"tool_choice": "auto",
"parallel_tool_calls": true
}
type ThreadRunInput ¶
type ThreadRunInput struct {
AssistantID string `json:"assistant_id"`
Model Model `json:"model"` // If provided, will override the assistant's model
AdditionalMessages []ThreadMessageInput `json:"additional_messages,omitempty"`
ResponseFormat *MessageResponseFormat `json:"response_format,omitempty"`
}
type ToolResources ¶
type ToolResources struct {
CodeInterpreter ToolResourcesCodeInterpreter `json:"code_interpreter"`
FileSearch ToolResourcesFileSearch `json:"file_search,omitempty"`
}
type ToolResourcesCodeInterpreter ¶
type ToolResourcesCodeInterpreter struct {
FileIDs []string `json:"file_ids,omitempty"`
}
type ToolResourcesFileSearch ¶
type ToolResourcesFileSearch struct {
VectorStores []ToolResourcesFileSearchVectorStore `json:"vector_stores,omitempty"`
VectorStoreIDs []string `json:"vector_store_ids,omitempty"`
}
type ToolResourcesFileSearchVectorStore ¶
type ToolResourcesFileSearchVectorStore struct {
FileIDs []string `json:"file_ids,omitempty"`
}
type Usage ¶
type Usage struct {
CompletionTokens int `json:"completion_tokens"`
CompletionTokensDetail struct {
ReasoningTokens int `json:"reasoning_tokens"`
} `json:"completion_tokens_details"`
PromptTokens int `json:"prompt_tokens"`
PromptTokensDetail struct {
CachedTokens int `json:"cached_tokens"`
} `json:"prompt_tokens_details"`
TotalTokens int `json:"total_tokens"`
}
Response Types
Click to show internal directories.
Click to hide internal directories.