From dc1edf8c3e98197ac10d3591fea0c11a55bcc790 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sun, 19 May 2024 21:50:43 +0000 Subject: [PATCH] Split google API types into types.go --- pkg/lmcli/provider/google/google.go | 87 ++--------------------------- pkg/lmcli/provider/google/types.go | 80 ++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 83 deletions(-) create mode 100644 pkg/lmcli/provider/google/types.go diff --git a/pkg/lmcli/provider/google/google.go b/pkg/lmcli/provider/google/google.go index bf7f8ae..b546460 100644 --- a/pkg/lmcli/provider/google/google.go +++ b/pkg/lmcli/provider/google/google.go @@ -15,88 +15,9 @@ import ( "git.mlow.ca/mlow/lmcli/pkg/lmcli/tools" ) -type Client struct { - APIKey string - BaseURL string -} - -type ContentPart struct { - Text string `json:"text,omitempty"` - FunctionCall *FunctionCall `json:"functionCall,omitempty"` - FunctionResp *FunctionResponse `json:"functionResponse,omitempty"` -} - -type FunctionCall struct { - Name string `json:"name"` - Args map[string]string `json:"args"` -} - -type FunctionResponse struct { - Name string `json:"name"` - Response interface{} `json:"response"` -} - -type Content struct { - Role string `json:"role"` - Parts []ContentPart `json:"parts"` -} - -type GenerationConfig struct { - MaxOutputTokens *int `json:"maxOutputTokens,omitempty"` - Temperature *float32 `json:"temperature,omitempty"` - TopP *float32 `json:"topP,omitempty"` - TopK *int `json:"topK,omitempty"` -} - -type GenerateContentRequest struct { - Contents []Content `json:"contents"` - Tools []Tool `json:"tools,omitempty"` - SystemInstructions string `json:"systemInstructions,omitempty"` - GenerationConfig *GenerationConfig `json:"generationConfig,omitempty"` -} - -type Candidate struct { - Content Content `json:"content"` - FinishReason string `json:"finishReason"` - Index int `json:"index"` -} - -type UsageMetadata struct { - PromptTokenCount int `json:"promptTokenCount"` - CandidatesTokenCount int `json:"candidatesTokenCount"` - TotalTokenCount int `json:"totalTokenCount"` -} - -type GenerateContentResponse struct { - Candidates []Candidate `json:"candidates"` - UsageMetadata UsageMetadata `json:"usageMetadata"` -} - -type Tool struct { - FunctionDeclarations []FunctionDeclaration `json:"functionDeclarations"` -} - -type FunctionDeclaration struct { - Name string `json:"name"` - Description string `json:"description"` - Parameters ToolParameters `json:"parameters"` -} - -type ToolParameters struct { - Type string `json:"type"` - Properties map[string]ToolParameter `json:"properties,omitempty"` - Required []string `json:"required,omitempty"` -} - -type ToolParameter struct { - Type string `json:"type"` - Description string `json:"description"` - Values []string `json:"values,omitempty"` -} - func convertTools(tools []model.Tool) []Tool { - geminiTools := make([]Tool, 0, len(tools)) - for _, tool := range tools { + geminiTools := make([]Tool, len(tools)) + for i, tool := range tools { params := make(map[string]ToolParameter) var required []string @@ -112,7 +33,7 @@ func convertTools(tools []model.Tool) []Tool { } } - geminiTools = append(geminiTools, Tool{ + geminiTools[i] = Tool{ FunctionDeclarations: []FunctionDeclaration{ { Name: tool.Name, @@ -124,7 +45,7 @@ func convertTools(tools []model.Tool) []Tool { }, }, }, - }) + } } return geminiTools } diff --git a/pkg/lmcli/provider/google/types.go b/pkg/lmcli/provider/google/types.go new file mode 100644 index 0000000..1d2eb30 --- /dev/null +++ b/pkg/lmcli/provider/google/types.go @@ -0,0 +1,80 @@ +package google + +type Client struct { + APIKey string + BaseURL string +} + +type ContentPart struct { + Text string `json:"text,omitempty"` + FunctionCall *FunctionCall `json:"functionCall,omitempty"` + FunctionResp *FunctionResponse `json:"functionResponse,omitempty"` +} + +type FunctionCall struct { + Name string `json:"name"` + Args map[string]string `json:"args"` +} + +type FunctionResponse struct { + Name string `json:"name"` + Response interface{} `json:"response"` +} + +type Content struct { + Role string `json:"role"` + Parts []ContentPart `json:"parts"` +} + +type GenerationConfig struct { + MaxOutputTokens *int `json:"maxOutputTokens,omitempty"` + Temperature *float32 `json:"temperature,omitempty"` + TopP *float32 `json:"topP,omitempty"` + TopK *int `json:"topK,omitempty"` +} + +type GenerateContentRequest struct { + Contents []Content `json:"contents"` + Tools []Tool `json:"tools,omitempty"` + SystemInstructions string `json:"systemInstructions,omitempty"` + GenerationConfig *GenerationConfig `json:"generationConfig,omitempty"` +} + +type Candidate struct { + Content Content `json:"content"` + FinishReason string `json:"finishReason"` + Index int `json:"index"` +} + +type UsageMetadata struct { + PromptTokenCount int `json:"promptTokenCount"` + CandidatesTokenCount int `json:"candidatesTokenCount"` + TotalTokenCount int `json:"totalTokenCount"` +} + +type GenerateContentResponse struct { + Candidates []Candidate `json:"candidates"` + UsageMetadata UsageMetadata `json:"usageMetadata"` +} + +type Tool struct { + FunctionDeclarations []FunctionDeclaration `json:"functionDeclarations"` +} + +type FunctionDeclaration struct { + Name string `json:"name"` + Description string `json:"description"` + Parameters ToolParameters `json:"parameters"` +} + +type ToolParameters struct { + Type string `json:"type"` + Properties map[string]ToolParameter `json:"properties,omitempty"` + Required []string `json:"required,omitempty"` +} + +type ToolParameter struct { + Type string `json:"type"` + Description string `json:"description"` + Values []string `json:"values,omitempty"` +}