Skip to content

Commit

Permalink
fix: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lucgagan committed Jun 27, 2023
1 parent 5d19b93 commit 051435d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/createChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ ${expect.examples
.join("\n\n")}`;
};

interface SendMessage {
<T extends MessageOptions>(
prompt: string,
messageOptions: T
// @ts-expect-error TODO
): Promise<StructuredChoice<FromSchema<T["expect"]["schema"]>>>;

(
prompt: string,
messageOptions?: MessageOptions
): Promise<Choice>;
}

export type Chat = {
addMessage: (message: Message) => void;
getMessages: () => Message[];
sendMessage: SendMessage;

};

/**
* @property apiKey - OpenAI API key.
* @property frequencyPenalty - Number between -2.0 and 2.0. Positive values penalize new
Expand Down Expand Up @@ -79,7 +99,7 @@ ${expect.examples
*/
export const createChat = (
options: Omit<CompletionsOptions, "messages" | "n" | "onUpdate">
) => {
): Chat => {
const messages: Message[] = [];

const userFunctions: Record<string, UserFunction> = {};
Expand Down Expand Up @@ -210,6 +230,4 @@ export const createChat = (
getMessages: () => messages,
sendMessage,
};
};

export type Chat = ReturnType<typeof createChat>;
};

0 comments on commit 051435d

Please sign in to comment.