-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (ai/core): add additional information to NoObjectGeneratedError (#…
- Loading branch information
Showing
17 changed files
with
808 additions
and
113 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': patch | ||
--- | ||
|
||
feat (ai/core): standardize generateObject, streamObject, and output errors to NoObjectGeneratedError |
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': patch | ||
--- | ||
|
||
feat (ai/core): add additional information to NoObjectGeneratedError |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { generateObject, NoObjectGeneratedError } from 'ai'; | ||
import { MockLanguageModelV1 } from 'ai/test'; | ||
import 'dotenv/config'; | ||
import { z } from 'zod'; | ||
|
||
async function main() { | ||
try { | ||
await generateObject({ | ||
model: new MockLanguageModelV1({ | ||
defaultObjectGenerationMode: 'json', | ||
doGenerate: async () => ({ | ||
rawCall: { rawPrompt: null, rawSettings: {} }, | ||
response: { | ||
id: 'id-1', | ||
timestamp: new Date(123), | ||
modelId: 'model-1', | ||
}, | ||
finishReason: 'stop', | ||
usage: { promptTokens: 10, completionTokens: 20 }, | ||
text: `{"content":"Hello broken json`, | ||
}), | ||
}), | ||
schema: z.object({ content: z.string() }), | ||
prompt: 'Hello, test!', | ||
}); | ||
} catch (error) { | ||
if (NoObjectGeneratedError.isInstance(error)) { | ||
console.log('NoObjectGeneratedError'); | ||
console.log('Cause:', error.cause); | ||
console.log('Text:', error.text); | ||
console.log('Response:', error.response); | ||
console.log('Usage:', error.usage); | ||
} | ||
} | ||
} | ||
|
||
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.