Created
May 19, 2024 14:31
-
-
Save christopherbauer/522915e5310a65c2ea333f3e5d54989b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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