Skip to content
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

Extract ChatCompletionMessage type #19

Merged

Conversation

blakechambers
Copy link
Contributor

This was mentioned in a comment as part of #17, but the differences between ChatCompletion and ChatCompletionOptions make it difficult to exchange sequences of messages with the API (without needing to limit fields passed to OpenAI). This refactor makes it a little easier.

Let me know if you have any suggestions or feedback.

Comment on lines +230 to +238
type JSONSchema =
& (
| ObjectSchema
| StringSchema
| NumberSchema
| BooleanSchema
| ArraySchema
)
& { description?: string };
Copy link
Contributor Author

@blakechambers blakechambers Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change unrelated to the PR: this is auto-formatting from the vscode deno formatter.

src/types.ts Outdated Show resolved Hide resolved
Comment on lines +250 to +255
export type ChatCompletionMessage =
| SystemCompletionMessage
| UserCompletionMessage
| FunctionAwareAssistantCompletionMessage
| FunctionCompletionMessage
| AssistantCompletionMessage;
Copy link
Contributor Author

@blakechambers blakechambers Jun 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I'm summing both the "functional" version of the API and the "regular". That means having both a FunctionAwareAssistantCompletionMessage and a AssistantCompletionMessage which is a little strange.

I thought about doing something more sophisticated (i.e. breaking out a type for "functional" models and altering the options here dynamically) but it started to head down a generic heavy path – which, in my opinion, complicated the typing more than it's worth.

interface FunctionCompletionMessage {
content: string;
role: "function";
name: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure name can only show up here? If yes, LGTM! Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. The main docs really only refers to name as something used by function, BUT while trying to verify this I stumbled on examples from
the cookbook using message name to further instruct system (Cases 10 and 13).

With that said, in f81bdd8, I marked them as optional again.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, let me verify that this is still fine and I'll merge.

Copy link
Collaborator

@lino-levan lino-levan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lino-levan lino-levan merged commit 9c6c51e into load1n9:main Jun 24, 2023
@blakechambers blakechambers deleted the extracts-chat-completion-message branch June 24, 2023 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants