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

Add support for multi part chat messages (and gpt-4-vision-preview model) #580

Merged
merged 4 commits into from
Nov 24, 2023

Conversation

rkintzi
Copy link
Contributor

@rkintzi rkintzi commented Nov 14, 2023

OpenAI has recently introduced a new model called gpt-4-visual-preview, which now supports images as input. The chat completion endpoint accepts multi-part chat messages, where the content can be an array of structs in addition to the usual string format.

This commit introduces new structures and constants to represent different types of content parts. It also implements the json.Marshaler and json.Unmarshaler interfaces on ChatCompletionMessage.

Issues: #539,#596
Similar PR: #557

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (515de02) 98.35% compared to head (592b7dc) 98.44%.
Report is 10 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #580      +/-   ##
==========================================
+ Coverage   98.35%   98.44%   +0.09%     
==========================================
  Files          24       24              
  Lines        1276     1354      +78     
==========================================
+ Hits         1255     1333      +78     
  Misses         15       15              
  Partials        6        6              

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

@rkintzi rkintzi force-pushed the master branch 2 times, most recently from b468820 to 2b59ea6 Compare November 14, 2023 21:22
OpenAI has recently introduced a new model called gpt-4-visual-preview,
which now supports images as input. The chat completion endpoint accepts
multi-part chat messages, where the content can be an array of structs
in addition to the usual string format.

This commit introduces new structures and constants to represent
different types of content parts. It also implements the json.Marshaler
and json.Unmarshaler interfaces on ChatCompletionMessage.
@rkintzi rkintzi changed the title Add support for multi part chat messages Add support for multi part chat messages (and gpt-4-vision-preview model) Nov 18, 2023
@emil14
Copy link

emil14 commented Nov 20, 2023

any updates?

@rkintzi
Copy link
Contributor Author

rkintzi commented Nov 20, 2023

We are waiting for review.

@sashabaranov
Copy link
Owner

Hey, thank you for the PR! Sorry for being so slow with the review!

chat.go Outdated Show resolved Hide resolved
chat.go Outdated Show resolved Hide resolved
chat.go Outdated Show resolved Hide resolved
chat.go Show resolved Hide resolved
chat.go Outdated Show resolved Hide resolved
@sashabaranov
Copy link
Owner

Looks good! Just a couple of minor fixes and let's merge

Copy link
Owner

@sashabaranov sashabaranov left a comment

Choose a reason for hiding this comment

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

Thank you for the updates! Note: there were more tests, do you want to return them or can we merge like that?

@rkintzi
Copy link
Contributor Author

rkintzi commented Nov 24, 2023

I introduced requested changes.

@rkintzi
Copy link
Contributor Author

rkintzi commented Nov 24, 2023

Not sure what you are referring with "more tests". Do you mean that we catch errors in tests? If so, then my answer is no. I don't thing it is worth wrapping json.Unmarshal/json.Marshal errors only to be able to catch them in test. This could potentially break someones code.

@sashabaranov
Copy link
Owner

@rkintzi
Copy link
Contributor Author

rkintzi commented Nov 24, 2023

And what about them? I really don't get what is the change that you suggest?

@sashabaranov
Copy link
Owner

@rkintzi ah, sorry, they are still here. I was looking only at the diff from the latest commit! Thank you for the PR! ❤️

@sashabaranov sashabaranov merged commit 03caea8 into sashabaranov:master Nov 24, 2023
3 checks passed
@rkintzi
Copy link
Contributor Author

rkintzi commented Nov 24, 2023

Sure thing! You're welcome!

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

Successfully merging this pull request may close these issues.

3 participants