-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type guards for messages #32
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When going through the incoming JSON array from OpenAI API, each element can be of a different type.
Deno uses TypeScript which uses type guards to simplify type assertions.
Examples
Let's say we have an array of messages:
When a
FunctionCompletionMessage
is being inserted tomessageArray
, it is important to verify that the last element is of typeFunctionAwareAssistantCompletionMessage
.When inserting user input into the
messageArray
, it is important to check that it is well-formed (UserCompletionMessage
).Suggestion
Add the following guard functions:
isSystemCompletionMessage(x: unknown): x is SystemCompletionMessage
isUserCompletionMessage(x: unknown): x is UserCompletionMessage
isFunctionAwareAssistantCompletionMessage(x: unknown): x is FunctionAwareAssistantCompletionMessage
isFunctionCompletionMessage(x: unknown): x is FunctionCompletionMessage
isAssistantCompletionMessage(x: unknown): x is AssistantCompletionMessage
The text was updated successfully, but these errors were encountered: