Skip to content

Instantly share code, notes, and snippets.

@christopherbauer
Created May 19, 2024 14:31
Show Gist options
  • Save christopherbauer/522915e5310a65c2ea333f3e5d54989b to your computer and use it in GitHub Desktop.
Save christopherbauer/522915e5310a65c2ea333f3e5d54989b to your computer and use it in GitHub Desktop.
export class ChatGptConversationService {
/* ... */
getConversationList = () => Promise.resolve(ConversationStorage);
/* ... */
}
export class InMemoryConversationService implements ConversationService {
/* ... */
getConversationList = async (): Promise<ConversationList> => {
const conversations = await this.chatgpt.getConversationList();
if (!conversations) {
return [];
}
return Object.keys(conversations).map<ConversationListEntry>((key) => {
const firstMessage = conversations[key].messages.filter(
(sm) => sm.role === "user"
)[0];
return {
id: key,
persona: conversations[key].persona,
firstMessage: {
text: String(firstMessage.content),
sent: firstMessage.sent,
source: firstMessage.role,
},
};
});
};
/* ... */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment