Skip to content

Instantly share code, notes, and snippets.

@christopherbauer
Last active May 18, 2024 17:12
Show Gist options
  • Select an option

  • Save christopherbauer/cdc40ee7800003f5b3d71c72bb9446a5 to your computer and use it in GitHub Desktop.

Select an option

Save christopherbauer/cdc40ee7800003f5b3d71c72bb9446a5 to your computer and use it in GitHub Desktop.
export class ChatGptConversationService {
/* ... */
getConversation = (id: string) =>
Promise.resolve(
ConversationStorage[id]?.messages
.filter((m) => m.role !== "system")
.map<Message>((m) => ({
text: String(m.content),
sent: m.sent,
source: m.role === "user" ? "user" : "bot",
}))
);
/* ... */
}
export class InMemoryConversationService implements ConversationService {
/* ... */
getConversation = async (id: string): Promise<Conversation> => {
const messages = await this.chatgpt.getConversation(id);
if (!messages) {
return [];
}
return messages;
};
/* ... */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment