Skip to content
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

54 unified response #55

Merged
merged 4 commits into from
Jan 2, 2024
Merged

54 unified response #55

merged 4 commits into from
Jan 2, 2024

Conversation

mkrueger12
Copy link
Contributor

  • Updated the Unified schema per the GEP

  • Updated the doChatRequest func to marshal openai response into the unified response

  • Tested

@mkrueger12 mkrueger12 self-assigned this Jan 1, 2024
@mkrueger12 mkrueger12 linked an issue Jan 1, 2024 that may be closed by this pull request
Copy link

codecov bot commented Jan 1, 2024

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (4cde769) 67.52% compared to head (e879a8d) 69.56%.
Report is 1 commits behind head on develop.

Files Patch % Lines
pkg/providers/openai/chat.go 80.43% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #55      +/-   ##
===========================================
+ Coverage    67.52%   69.56%   +2.04%     
===========================================
  Files            8        8              
  Lines          234      276      +42     
===========================================
+ Hits           158      192      +34     
- Misses          65       71       +6     
- Partials        11       13       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mkrueger12 mkrueger12 removed the request for review from roma-glushko January 2, 2024 16:01
@mkrueger12 mkrueger12 merged commit 8900b8d into develop Jan 2, 2024
5 of 7 checks passed
@mkrueger12 mkrueger12 deleted the 54-unified-response branch January 2, 2024 16:02

var tokenCount schemas.TokenCount

message := responseJSON["choices"].([]interface{})[0].(map[string]interface{})["message"].(map[string]interface{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkrueger12 looking at this code I feel like it's worth defining OpenAI Chat Response schema, map the response into it and then remap into the unified chat response schema

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roma-glushko I can do that. What advantage does it provide?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkrueger12 That would make the implementation more readable at very least and it would give an understanding what the actual provider response might look like, what information it contains in a declarative way 👀

In this specific case, expression like responseJSON["choices"].([]interface{})[0].(map[string]interface{}) means that you are sure that the response has the choices key where you also are sure there is at least one item e.g. [0]. But is this always a case? Because if not I think this code will fail with an exception trying to access that info but in fact getting nil.

If you had a validation via the defined OpenAI chat response, you would ensure that the response has all needed fields which would simply the code here.

Something like that.


response = schemas.UnifiedChatResponse{
ID: responseJSON["id"].(string),
Created: float64(time.Now().Unix()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it in UTC timezone?

Router string `json:"router,omitempty"`
Model string `json:"model,omitempty"`
Cached bool `json:"cached,omitempty"`
ProviderResponse ProviderResponse `json:"provider_response,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think ProviderResponse -> ModelResponse would be a good idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Unified Response
2 participants