-
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.
ai/core: add text streaming usage and finish reason support (#1217)
- Loading branch information
Showing
16 changed files
with
721 additions
and
31 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
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
41 changes: 41 additions & 0 deletions
41
packages/core/ai-model-specification/errors/invalid-response-data-error.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,41 @@ | ||
/** | ||
* Server returned a response with invalid data content. This should be thrown by providers when they | ||
* cannot parse the response from the API. | ||
*/ | ||
export class InvalidResponseDataError extends Error { | ||
readonly data: unknown; | ||
|
||
constructor({ | ||
data, | ||
message = `Invalid response data: ${JSON.stringify(data)}.`, | ||
}: { | ||
data: unknown; | ||
message?: string; | ||
}) { | ||
super(message); | ||
|
||
this.name = 'AI_InvalidResponseDataError'; | ||
|
||
this.data = data; | ||
} | ||
|
||
static isInvalidResponseDataError( | ||
error: unknown, | ||
): error is InvalidResponseDataError { | ||
return ( | ||
error instanceof Error && | ||
error.name === 'AI_InvalidResponseDataError' && | ||
(error as InvalidResponseDataError).data != null | ||
); | ||
} | ||
|
||
toJSON() { | ||
return { | ||
name: this.name, | ||
message: this.message, | ||
stack: this.stack, | ||
|
||
data: this.data, | ||
}; | ||
} | ||
} |
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.