feat: openai: allow assistant content to be string#486
Merged
Conversation
Signed-off-by: Aaron Choo <achoo30@bloomberg.net>
Signed-off-by: Aaron Choo <achoo30@bloomberg.net>
mathetake
reviewed
Mar 13, 2025
internal/apischema/openai/openai.go
Outdated
| return nil | ||
| } | ||
|
|
||
| return fmt.Errorf("cannot unmarshal JSON data as string or assistant content parts") |
Member
There was a problem hiding this comment.
if there's no format then let's use errors.New
Suggested change
| return fmt.Errorf("cannot unmarshal JSON data as string or assistant content parts") | |
| return errors.New("cannot unmarshal JSON data as string or assistant content parts") |
yuzisun
reviewed
Mar 13, 2025
| if content.Type == openai.ChatCompletionAssistantMessageParamContentTypeRefusal { | ||
| contentBlocks = append(contentBlocks, &awsbedrock.ContentBlock{Text: content.Refusal}) | ||
| } else if content.Text != nil { | ||
| // TODO: we are sometimes missing the content (should fix) |
Contributor
There was a problem hiding this comment.
Can remove this TODO now, this is the fix
yuzisun
reviewed
Mar 13, 2025
| Value: openai.ChatCompletionAssistantMessageParam{ | ||
| Content: openai.ChatCompletionAssistantMessageParamContent{ | ||
| Text: ptr.To("I dunno"), | ||
| Content: openai.StringOrAssistantRoleContentUnion{ |
Contributor
There was a problem hiding this comment.
Can you help add the missing unmarshall test which is why this issue is not caught
Contributor
Author
There was a problem hiding this comment.
The issue was content being parsed as string even though it was sent as AssistantContentType. Added a test, but the behavior is unideal since the unmarshalling now sees it as valid:
Signed-off-by: Aaron Choo <achoo30@bloomberg.net>
Member
|
LGTM from me |
yuzisun
approved these changes
Mar 13, 2025
aabchoo
added a commit
that referenced
this pull request
Mar 14, 2025
**Commit Message** Content type should be able to be string so adding this for compatibility. It's already done for the other types - keeping it consistent. --------- Signed-off-by: Aaron Choo <achoo30@bloomberg.net> Co-authored-by: Dan Sun <dsun20@bloomberg.net>
aabchoo
added a commit
that referenced
this pull request
Mar 14, 2025
**Commit Message** PR to backport `mockChatCompletionMetrics`, chat completion stream fix, and openai content type. Including: - #459 (468 uses mock components introduced here) - #468 - #486 --------- Signed-off-by: Huamin Chen <hchen@redhat.com> Signed-off-by: Ignasi Barrera <ignasi@tetrate.io> Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com> Signed-off-by: Aaron Choo <achoo30@bloomberg.net> Co-authored-by: Ignasi Barrera <ignasi@tetrate.io> Co-authored-by: Takeshi Yoneda <t.y.mathetake@gmail.com> Co-authored-by: Dan Sun <dsun20@bloomberg.net>
mathetake
pushed a commit
that referenced
this pull request
Mar 18, 2025
…508) **Commit Message** AWS Claude 3.5 v1 has cases when assistant returns empty content. Sending that back to AWS will result in a validation error. Will skip adding empty content if string is empty. ``` openai.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/', 'code': '400', 'message': 'The text field in the ContentBlock object at messages.3.content.0 is blank. Add text to the text field, and try again.'}} ``` **Related Issues/PRs (if applicable)** #486 Signed-off-by: Aaron Choo <achoo30@bloomberg.net>
aabchoo
added a commit
that referenced
this pull request
Mar 20, 2025
…508) **Commit Message** AWS Claude 3.5 v1 has cases when assistant returns empty content. Sending that back to AWS will result in a validation error. Will skip adding empty content if string is empty. ``` openai.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/', 'code': '400', 'message': 'The text field in the ContentBlock object at messages.3.content.0 is blank. Add text to the text field, and try again.'}} ``` **Related Issues/PRs (if applicable)** #486 Signed-off-by: Aaron Choo <achoo30@bloomberg.net>
aabchoo
added a commit
that referenced
this pull request
Mar 20, 2025
**Commit Message** Ref: (#508) AWS Claude 3.5 v1 has cases when assistant returns empty content. Sending that back to AWS will result in a validation error. Will skip adding empty content if string is empty. ``` openai.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/', 'code': '400', 'message': 'The text field in the ContentBlock object at messages.3.content.0 is blank. Add text to the text field, and try again.'}} ``` **Related Issues/PRs (if applicable)** #486 Signed-off-by: Aaron Choo <achoo30@bloomberg.net>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Commit Message
Content type should be able to be string so adding this for compatibility. It's already done for the other types - keeping it consistent.