-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (provider/openai): send user message content as text when possib…
…le (#1765) Co-authored-by: minpeter <minpeter@friendli.ai> Co-authored-by: minpeter <kali2005611@gmail.com>
- Loading branch information
1 parent
f370fbf
commit fb42e76
Showing
5 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ai-sdk/openai': patch | ||
--- | ||
|
||
feat (provider/openai): send user message content as text when possible |
43 changes: 43 additions & 0 deletions
43
packages/openai/src/convert-to-openai-chat-messages.test.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { convertToOpenAIChatMessages } from './convert-to-openai-chat-messages'; | ||
|
||
describe('user messages', () => { | ||
it('should convert messages with image parts to multiple parts', async () => { | ||
const result = convertToOpenAIChatMessages([ | ||
{ | ||
role: 'user', | ||
content: [ | ||
{ type: 'text', text: 'Hello' }, | ||
{ | ||
type: 'image', | ||
image: new Uint8Array([0, 1, 2, 3]), | ||
mimeType: 'image/png', | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
role: 'user', | ||
content: [ | ||
{ type: 'text', text: 'Hello' }, | ||
{ | ||
type: 'image_url', | ||
image_url: { url: 'data:image/png;base64,AAECAw==' }, | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it('should convert messages with only a text part to a string content', async () => { | ||
const result = convertToOpenAIChatMessages([ | ||
{ | ||
role: 'user', | ||
content: [{ type: 'text', text: 'Hello' }], | ||
}, | ||
]); | ||
|
||
expect(result).toEqual([{ role: 'user', content: 'Hello' }]); | ||
}); | ||
}); |
This file contains 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
This file contains 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
This file contains 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