From 79e4f45785a4d9ecc2ea1a8f898d78aaac8b4b8a Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 4 Jan 2024 18:54:34 -0700 Subject: [PATCH] #61: lint --- pkg/api/schemas/language.go | 95 +++++++++++++++++------------------- pkg/providers/openai/chat.go | 2 +- 2 files changed, 47 insertions(+), 50 deletions(-) diff --git a/pkg/api/schemas/language.go b/pkg/api/schemas/language.go index 15c840d1..f9d93868 100644 --- a/pkg/api/schemas/language.go +++ b/pkg/api/schemas/language.go @@ -8,12 +8,12 @@ type UnifiedChatRequest struct { // UnifiedChatResponse defines Glide's Chat Response Schema unified across all language models type UnifiedChatResponse struct { - ID string `json:"id,omitempty"` - Created int `json:"created,omitempty"` - Provider string `json:"provider,omitempty"` - Router string `json:"router,omitempty"` - Model string `json:"model,omitempty"` - Cached bool `json:"cached,omitempty"` + ID string `json:"id,omitempty"` + Created int `json:"created,omitempty"` + Provider string `json:"provider,omitempty"` + Router string `json:"router,omitempty"` + Model string `json:"model,omitempty"` + Cached bool `json:"cached,omitempty"` ModelResponse ProviderResponse `json:"modelResponse,omitempty"` } @@ -26,9 +26,9 @@ type ProviderResponse struct { } type TokenCount struct { - PromptTokens float64 `json:"promptTokens"` - ResponseTokens float64 `json:"responseTokens"` - TotalTokens float64 `json:"totalTokens"` + PromptTokens float64 `json:"promptTokens"` + ResponseTokens float64 `json:"responseTokens"` + TotalTokens float64 `json:"totalTokens"` } // ChatMessage is a message in a chat request. @@ -45,47 +45,47 @@ type ChatMessage struct { // OpenAI Chat Response // TODO: Should this live here? type OpenAIChatCompletion struct { - ID string `json:"id"` - Object string `json:"object"` - Created int `json:"created"` - Model string `json:"model"` - SystemFingerprint string `json:"system_fingerprint"` - Choices []Choice `json:"choices"` - Usage Usage `json:"usage"` + ID string `json:"id"` + Object string `json:"object"` + Created int `json:"created"` + Model string `json:"model"` + SystemFingerprint string `json:"system_fingerprint"` + Choices []Choice `json:"choices"` + Usage Usage `json:"usage"` } type Choice struct { - Index int `json:"index"` - Message ChatMessage `json:"message"` - Logprobs interface{} `json:"logprobs"` - FinishReason string `json:"finish_reason"` + Index int `json:"index"` + Message ChatMessage `json:"message"` + Logprobs interface{} `json:"logprobs"` + FinishReason string `json:"finish_reason"` } type Usage struct { - PromptTokens float64 `json:"prompt_tokens"` - CompletionTokens float64 `json:"completion_tokens"` - TotalTokens float64 `json:"total_tokens"` + PromptTokens float64 `json:"prompt_tokens"` + CompletionTokens float64 `json:"completion_tokens"` + TotalTokens float64 `json:"total_tokens"` } // Cohere Chat Response type CohereChatCompletion struct { - Text string `json:"text"` - GenerationID string `json:"generation_id"` - ResponseID string `json:"response_id"` - TokenCount CohereTokenCount `json:"token_count"` - Citations []Citation `json:"citations"` - Documents []Documents `json:"documents"` - SearchQueries []SearchQuery `json:"search_queries"` - SearchResults []SearchResults `json:"search_results"` - Meta Meta `json:"meta"` - ToolInputs map[string]interface{} `json:"tool_inputs"` + Text string `json:"text"` + GenerationID string `json:"generation_id"` + ResponseID string `json:"response_id"` + TokenCount CohereTokenCount `json:"token_count"` + Citations []Citation `json:"citations"` + Documents []Documents `json:"documents"` + SearchQueries []SearchQuery `json:"search_queries"` + SearchResults []SearchResults `json:"search_results"` + Meta Meta `json:"meta"` + ToolInputs map[string]interface{} `json:"tool_inputs"` } type CohereTokenCount struct { - PromptTokens float64 `json:"prompt_tokens"` - ResponseTokens float64 `json:"response_tokens"` - TotalTokens float64 `json:"total_tokens"` - BilledTokens float64 `json:"billed_tokens"` + PromptTokens float64 `json:"prompt_tokens"` + ResponseTokens float64 `json:"response_tokens"` + TotalTokens float64 `json:"total_tokens"` + BilledTokens float64 `json:"billed_tokens"` } type Meta struct { @@ -99,33 +99,30 @@ type Meta struct { } type Citation struct { - Start int `json:"start"` - End int `json:"end"` - Text string `json:"text"` + Start int `json:"start"` + End int `json:"end"` + Text string `json:"text"` DocumentID []string `json:"documentId"` - } type Documents struct { - ID string `json:"id"` + ID string `json:"id"` Data map[string]string `json:"data"` // TODO: This needs to be updated } type SearchQuery struct { - Text string `json:"text"` + Text string `json:"text"` GenerationID string `json:"generationId"` } type SearchResults struct { - SearchQuery []SearchQueryObject `json:"searchQuery"` - Connectors []ConnectorsResponse `json:"connectors"` - DocumentID []string `json:"documentId"` - - + SearchQuery []SearchQueryObject `json:"searchQuery"` + Connectors []ConnectorsResponse `json:"connectors"` + DocumentID []string `json:"documentId"` } type SearchQueryObject struct { - Text string `json:"text"` + Text string `json:"text"` GenerationID string `json:"generationId"` } diff --git a/pkg/providers/openai/chat.go b/pkg/providers/openai/chat.go index 613648cd..25946444 100644 --- a/pkg/providers/openai/chat.go +++ b/pkg/providers/openai/chat.go @@ -160,7 +160,7 @@ func (c *Client) doChatRequest(ctx context.Context, payload *ChatRequest) (*sche c.telemetry.Logger.Error("failed to parse openai chat response", zap.Error(err)) return nil, err } - + // Map response to UnifiedChatResponse schema response := schemas.UnifiedChatResponse{ ID: openAICompletion.ID,