-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
61 update openai client #62
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9312334
#61: Create OpenAI Chat Response Schema
mkrueger12 3101610
#61: Test unmarshling
mkrueger12 6e3a693
#61: unmarshal openai response
mkrueger12 650833c
#61: Update CohereChatCompletion struct and related types
mkrueger12 8026dfd
#61: Update Cohere chat response mapping
mkrueger12 f463344
#61: lint
mkrueger12 79e4f45
#61: lint
mkrueger12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,26 +8,27 @@ type UnifiedChatRequest struct { | |
|
||
// UnifiedChatResponse defines Glide's Chat Response Schema unified across all language models | ||
type UnifiedChatResponse struct { | ||
ID string `json:"id,omitempty"` | ||
Created float64 `json:"created,omitempty"` | ||
Provider string `json:"provider,omitempty"` | ||
Router string `json:"router,omitempty"` | ||
Model string `json:"model,omitempty"` | ||
Cached bool `json:"cached,omitempty"` | ||
ProviderResponse ProviderResponse `json:"provider_response,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"` | ||
} | ||
|
||
// ProviderResponse contains data from the chosen provider | ||
// ProviderResponse is the unified response from the provider. | ||
|
||
type ProviderResponse struct { | ||
ResponseID map[string]string `json:"response_id,omitempty"` | ||
ResponseID map[string]string `json:"responseID,omitempty"` | ||
Message ChatMessage `json:"message"` | ||
TokenCount TokenCount `json:"token_count"` | ||
TokenCount TokenCount `json:"tokenCount"` | ||
} | ||
|
||
type TokenCount struct { | ||
PromptTokens float64 `json:"prompt_tokens"` | ||
ResponseTokens float64 `json:"response_tokens"` | ||
TotalTokens float64 `json:"total_tokens"` | ||
PromptTokens float64 `json:"promptTokens"` | ||
ResponseTokens float64 `json:"responseTokens"` | ||
TotalTokens float64 `json:"totalTokens"` | ||
} | ||
|
||
// ChatMessage is a message in a chat request. | ||
|
@@ -41,15 +42,93 @@ type ChatMessage struct { | |
Name string `json:"name,omitempty"` | ||
} | ||
|
||
// ChatChoice is a choice in a chat response. | ||
type ChatChoice struct { | ||
// OpenAI Chat Response | ||
// TODO: Should this live here? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkrueger12 I would move it under OpenAI package. |
||
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"` | ||
} | ||
|
||
type Choice struct { | ||
Index int `json:"index"` | ||
Message ChatMessage `json:"message"` | ||
Logprobs interface{} `json:"logprobs"` | ||
FinishReason string `json:"finish_reason"` | ||
} | ||
|
||
type Usage struct { | ||
CompletionTokens float64 `json:"completion_tokens,omitempty"` | ||
PromptTokens float64 `json:"prompt_tokens,omitempty"` | ||
TotalTokens float64 `json:"total_tokens,omitempty"` | ||
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"` | ||
} | ||
|
||
type CohereTokenCount struct { | ||
PromptTokens float64 `json:"prompt_tokens"` | ||
ResponseTokens float64 `json:"response_tokens"` | ||
TotalTokens float64 `json:"total_tokens"` | ||
BilledTokens float64 `json:"billed_tokens"` | ||
} | ||
|
||
type Meta struct { | ||
APIVersion struct { | ||
Version string `json:"version"` | ||
} `json:"api_version"` | ||
BilledUnits struct { | ||
InputTokens int `json:"input_tokens"` | ||
OutputTokens int `json:"output_tokens"` | ||
} `json:"billed_units"` | ||
} | ||
|
||
type Citation struct { | ||
Start int `json:"start"` | ||
End int `json:"end"` | ||
Text string `json:"text"` | ||
DocumentID []string `json:"documentId"` | ||
} | ||
|
||
type Documents struct { | ||
ID string `json:"id"` | ||
Data map[string]string `json:"data"` // TODO: This needs to be updated | ||
} | ||
|
||
type SearchQuery struct { | ||
Text string `json:"text"` | ||
GenerationID string `json:"generationId"` | ||
} | ||
|
||
type SearchResults struct { | ||
SearchQuery []SearchQueryObject `json:"searchQuery"` | ||
Connectors []ConnectorsResponse `json:"connectors"` | ||
DocumentID []string `json:"documentId"` | ||
} | ||
|
||
type SearchQueryObject struct { | ||
Text string `json:"text"` | ||
GenerationID string `json:"generationId"` | ||
} | ||
|
||
type ConnectorsResponse struct { | ||
ID string `json:"id"` | ||
UserAccessToken string `json:"user_access_token"` | ||
ContOnFail string `json:"continue_on_failure"` | ||
Options map[string]string `json:"options"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this one be called ModelResponse too?