-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ai/core: expose raw response headers (#1417)
- Loading branch information
Showing
27 changed files
with
543 additions
and
133 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,11 @@ | ||
--- | ||
'@ai-sdk/provider-utils': patch | ||
'@ai-sdk/anthropic': patch | ||
'@ai-sdk/provider': patch | ||
'@ai-sdk/mistral': patch | ||
'@ai-sdk/google': patch | ||
'@ai-sdk/openai': patch | ||
'ai': patch | ||
--- | ||
|
||
ai/core: add support for getting raw response headers. |
24 changes: 24 additions & 0 deletions
24
examples/ai-core/src/stream-text/openai-response-headers.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,24 @@ | ||
import { openai } from '@ai-sdk/openai'; | ||
import { experimental_streamText } from 'ai'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
async function main() { | ||
const result = await experimental_streamText({ | ||
model: openai('gpt-3.5-turbo'), | ||
maxTokens: 512, | ||
temperature: 0.3, | ||
maxRetries: 5, | ||
prompt: 'Invent a new holiday and describe its traditions.', | ||
}); | ||
|
||
console.log(`Request ID: ${result.rawResponse?.headers?.['x-request-id']}`); | ||
console.log(); | ||
|
||
for await (const textPart of result.textStream) { | ||
process.stdout.write(textPart); | ||
} | ||
} | ||
|
||
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
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
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.