-
Notifications
You must be signed in to change notification settings - Fork 342
Add MessageAdapter content parts serialization test coverage #11800
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -861,6 +861,28 @@ class AIGuardInternalTests extends DDSpecification { | |
| } | ||
| } | ||
|
|
||
| void 'test adapter serializes content parts'() { | ||
|
smola marked this conversation as resolved.
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.
The root Useful? React with 👍 / 👎.
Member
Author
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. Nope. Nope. Nope.
Contributor
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. In a way codex is right :) |
||
| given: | ||
| final adapter = new Moshi.Builder().add(new AIGuardInternal.AIGuardFactory()).build() | ||
| .adapter(AIGuard.Message) | ||
|
|
||
| expect: | ||
| // STRICT enforces array element ordering (object key order is always ignored), so a regression | ||
| // that serialized the content parts out of sequence would be caught here | ||
| JSONAssert.assertEquals(expected, adapter.toJson(message), JSONCompareMode.STRICT) | ||
|
|
||
| where: | ||
| message | expected | ||
| AIGuard.Message.message('user', [] as List<AIGuard.ContentPart>) | '{"role": "user", "content": []}' | ||
| AIGuard.Message.message('user', [AIGuard.ContentPart.text('Hello world')]) | '{"role": "user", "content": [{"type": "text", "text": "Hello world"}]}' | ||
| AIGuard.Message.message('user', [AIGuard.ContentPart.imageUrl('https://example.com/image.jpg')]) | '{"role": "user", "content": [{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}]}' | ||
| AIGuard.Message.message('user', [ | ||
| AIGuard.ContentPart.text('Describe this image:'), | ||
|
smola marked this conversation as resolved.
|
||
| AIGuard.ContentPart.imageUrl('https://example.com/image.jpg'), | ||
| AIGuard.ContentPart.text('What do you see?') | ||
| ]) | '{"role": "user", "content": [{"type": "text", "text": "Describe this image:"}, {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}, {"type": "text", "text": "What do you see?"}]}' | ||
| } | ||
|
|
||
| void 'test backward compatibility with string content'() { | ||
| given: | ||
| final aiguard = mockClient(200, [data: [attributes: [action: 'ALLOW', reason: 'Good']]]) | ||
|
|
||
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.
nit: the adapter is re-created on every
where:row. Consider moving it to a@Sharedfield.