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

[BREAKING_CHANGES] fix: support ThreadMessage.Content as an array #821

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adamdecaf
Copy link

Describe the change
FileIDs on ThreadMessage isn't supported anymore, but Content can be an array.

Provide OpenAI documentation link
https://platform.openai.com/docs/api-reference/threads/createThread

Describe your solution
Remove old fields and update existing ones to support current OpenAI endpoints.

Tests
I've verified this allows me to upload an image and prompt in a thread (ran under an assistant).

Here's the snippet of code that creates the thread.

	thread, err := c.underlying.CreateThread(ctx, openaiclient.ThreadRequest{
		Messages: []openaiclient.ThreadMessage{
			{
				Role: openaiclient.ThreadMessageRoleUser,
				Content: []openaiclient.ThreadMessageContent{
					{
						Type: "image_file",
						ImageFile: &openaiclient.ThreadMessageImageFile{
							FileID: file.ID,
						},
					},
					{
						Type: "text",
						Text: &prompt,
					},
				},
			},
		},
	})

Fixes: #773

Copy link

codecov bot commented Aug 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.01%. Comparing base (774fc9d) to head (d6c7739).
Report is 45 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #821      +/-   ##
==========================================
+ Coverage   98.46%   99.01%   +0.55%     
==========================================
  Files          24       26       +2     
  Lines        1364     1418      +54     
==========================================
+ Hits         1343     1404      +61     
+ Misses         15        8       -7     
  Partials        6        6              

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

Attachments []ThreadAttachment `json:"attachments,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Role ThreadMessageRole `json:"role"`
Content []ThreadMessageContent `json:"content"`
Copy link
Owner

Choose a reason for hiding this comment

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

Hey, thank you for the PR!

The documentation says it is either a string or array: https://platform.openai.com/docs/api-reference/messages/createMessage#messages-createmessage-content

So I think we need a new type here that supports proper marshalling

Copy link
Author

Choose a reason for hiding this comment

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

Could we send an array of one with text: { ... } instead of a new type?

thread.go Outdated Show resolved Hide resolved
FileIDs on ThreadMessage isn't supported anymore, but Content can be
an array.

Fixes: sashabaranov#773
@adamdecaf adamdecaf force-pushed the fix-thread-messages-issue-773 branch from aa77be8 to d6c7739 Compare August 26, 2024 17:40
@archimed-shaman
Copy link

Hi, guys.
Are there any updates on this PR? It seems like without it, the library can't fully utilize the assistants' API.

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.

Unknown parameter for CreateThreadAndRun method
3 participants