-
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/perplexity): add support for return_images (#4651)
Co-authored-by: Kevin Wolf <[email protected]>
- Loading branch information
1 parent
76413f5
commit 18713a5
Showing
7 changed files
with
228 additions
and
34 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/perplexity': patch | ||
--- | ||
|
||
feat (provider/perplexity): add support for return_images |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'dotenv/config'; | ||
import { perplexity } from '@ai-sdk/perplexity'; | ||
import { generateText } from 'ai'; | ||
|
||
async function main() { | ||
const result = await generateText({ | ||
model: perplexity('sonar-pro'), | ||
prompt: | ||
'Tell me about the earliest cave drawings known and include images.', | ||
providerOptions: { | ||
perplexity: { | ||
return_images: true, | ||
}, | ||
}, | ||
}); | ||
|
||
console.log(result.text); | ||
console.log(); | ||
console.log('Token usage:', result.usage); | ||
console.log('Finish reason:', result.finishReason); | ||
console.log('Metadata:', result.experimental_providerMetadata); | ||
} | ||
|
||
main().catch(console.error); |
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,30 @@ | ||
import { perplexity } from '@ai-sdk/perplexity'; | ||
import { streamText } from 'ai'; | ||
import 'dotenv/config'; | ||
|
||
async function main() { | ||
const result = streamText({ | ||
model: perplexity('sonar-pro'), | ||
prompt: | ||
'Tell me about the earliest cave drawings known and include images.', | ||
providerOptions: { | ||
perplexity: { | ||
return_images: true, | ||
}, | ||
}, | ||
}); | ||
|
||
for await (const textPart of result.textStream) { | ||
process.stdout.write(textPart); | ||
} | ||
|
||
console.log(); | ||
console.log('Token usage:', await result.usage); | ||
console.log('Finish reason:', await result.finishReason); | ||
console.log( | ||
'Metadata:', | ||
JSON.stringify(await result.experimental_providerMetadata, null, 2), | ||
); | ||
} | ||
|
||
main().catch(console.error); |
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
Oops, something went wrong.