-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error codes and more legibility / CTAs to error output.
- Loading branch information
1 parent
e3fd97c
commit 92c34d9
Showing
22 changed files
with
267 additions
and
55 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,97 @@ | ||
import _ from 'lodash'; | ||
import { Jsonifiable } from 'type-fest'; | ||
|
||
export enum ErrorCode { | ||
MissingCompletionModel = 1000, | ||
MissingChatModel = 1001, | ||
MissingImageModel = 1002, | ||
UnrenderableType = 1003, | ||
GeneratorMustBeExhausted = 1004, | ||
GeneratorCannotBeUsedTwice = 1005, | ||
GeneratorCannotBeUsedAsIterableAfterAwaiting = 1006, | ||
UnexpectedRenderType = 1007, | ||
LogitBiasBadInput = 1008, | ||
ChatCompletionMissingChildren = 1009, | ||
ChatCompletionUnexpectedChild = 1010, | ||
ImageBadDimensions = 1011, | ||
ModelOutputDidNotMatchUIShape = 1012, | ||
AIJSXEndpointFailed = 1013, | ||
AIJSXEndpointHadEmptyResponse = 1014, | ||
|
||
ModelOutputDidNotMatchConstraint = 2000, | ||
|
||
UnsupportedMimeType = 2001, | ||
MissingFixieAPIKey = 2002, | ||
CorpusNotReady = 2003, | ||
FixieStatusNotOk = 2004, | ||
|
||
ModelOutputCouldNotBeParsedForTool = 2005, | ||
ModelHallucinatedTool = 2006, | ||
} | ||
|
||
export type ErrorBlame = | ||
/** An error that is expected to occur, like a network failure. */ | ||
| 'runtime' | ||
/** An error that's most likely caused by the user. */ | ||
| 'user' | ||
/** An error that's most likely the fault of AI.JSX itself. */ | ||
| 'internal' | ||
/** An error where it's not clear who caused it. */ | ||
| 'ambiguous'; | ||
|
||
/** | ||
* A generic error thrown by AI.JSX. It could be a user error, runtime error, or internal error. | ||
*/ | ||
export class AIJSXError extends Error { | ||
constructor( | ||
message: string, | ||
public readonly code: ErrorCode, | ||
public readonly blame: ErrorBlame, | ||
public readonly metadata: Jsonifiable = {} | ||
) { | ||
super(message); | ||
} | ||
|
||
private messageOfErrorKind() { | ||
switch (this.blame) { | ||
case 'runtime': | ||
return "This is a runtime error that's expected to occur with some frequency. It may go away on retry. It may be made more likely by errors in your code, or in AI.JSX."; | ||
case 'user': | ||
return 'This may be due to a mistake in your code.'; | ||
case 'internal': | ||
return 'This is most likely a bug in AI.JSX. Bug reports appreciated. :)'; | ||
case 'ambiguous': | ||
return "It's unclear whether this was caused by a bug in AI.JSX, in your code, or is an expected runtime error."; | ||
} | ||
} | ||
|
||
private formattedMessage() { | ||
return _.last(this.message) === '.' ? this.message : `${this.message}.`; | ||
} | ||
|
||
toString() { | ||
return `AI.JSX(${this.code}): ${this.formattedMessage()} | ||
${this.messageOfErrorKind()} | ||
Need help? | ||
* Discord: https://discord.com/channels/1065011484125569147/1121125525142904862 | ||
* Docs: https://docs.ai-jsx.com/ | ||
* GH: https://github.com/fixie-ai/ai-jsx/issues`; | ||
} | ||
} | ||
|
||
/** | ||
* Represents an error that occurs while invoking an HTTP request to a Large Language Model. | ||
*/ | ||
export class HttpError extends Error { | ||
export class HttpError extends AIJSXError { | ||
constructor( | ||
message: string, | ||
readonly statusCode: number, | ||
readonly errorCode: number, | ||
readonly responseBody?: string, | ||
readonly responseHeaders?: Record<string, string> | ||
) { | ||
super(message || `HTTP request failed with status code ${statusCode}`); | ||
super(message || `HTTP request failed with status code ${statusCode}`, errorCode, 'runtime'); | ||
} | ||
} |
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.
92c34d9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ai-jsx-docs – ./packages/docs
ai-jsx-docs-fixie-ai.vercel.app
ai-jsx-docs.vercel.app
docs.ai-jsx.com
ai-jsx-docs-git-main-fixie-ai.vercel.app
92c34d9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ai-jsx-tutorial-nextjs – ./packages/tutorial-nextjs
ai-jsx-tutorial-nextjs.vercel.app
ai-jsx-tutorial-nextjs-fixie-ai.vercel.app
ai-jsx-tutorial-nextjs-git-main-fixie-ai.vercel.app
92c34d9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ai-jsx-nextjs-demo – ./packages/nextjs-demo
ai-jsx-nextjs-demo-fixie-ai.vercel.app
ai-jsx-nextjs-demo.vercel.app
ai-jsx-nextjs-demo-git-main-fixie-ai.vercel.app