Skip to content

Commit

Permalink
fix: correct function overload
Browse files Browse the repository at this point in the history
  • Loading branch information
lucgagan committed Jun 27, 2023
1 parent 3973646 commit 73dff42
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/createChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,13 @@ export const createChat = (
} as any;
};

const sendMessage = async <T extends MessageOptions>(
prompt: string,
messageOptions?: T
): Promise<"expect" extends keyof T ? StructuredChoice : Choice> => {
type SendMessageReturn<T> = T extends undefined ? Choice : StructuredChoice;


function sendMessage<T extends MessageOptions>(prompt: string, messageOptions: T): Promise<SendMessageReturn<T>>;
function sendMessage(prompt: string): Promise<SendMessageReturn<undefined>>;

async function sendMessage(prompt: string, messageOptions?: MessageOptions) {
const message: Message = {
content: messageOptions?.expect
? extendPrompt(prompt, messageOptions.expect)
Expand Down Expand Up @@ -204,7 +207,7 @@ export const createChat = (
} else {
return choice as any;
}
};
}

const addMessage = (message: Message) => {
messages.push(message);
Expand Down

0 comments on commit 73dff42

Please sign in to comment.