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 const personas: Record< | |
string, | |
{ name: string; prompt: string; role: string; imageUri?: string } | |
> = { | |
/* ... */ | |
Robot: { | |
name: "JaSON", | |
imageUri: "./Robot.png", | |
role: "Robot", | |
prompt: "You only respond with JSON code. You're always honest when you aren't sure how to do something.", |
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
import { Conversation, Message } from "./conversation/types"; | |
import { Persona } from "./persona/types"; | |
export const getPersonas: () => Promise<Persona[]> = () => { | |
return fetch("http://localhost:3010/persona", { | |
method: "GET", | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
}).then((response) => { |
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
app.route("/conversation").get(async (req, res) => { | |
const conversations = await inMemoryDB.getConversationList(); | |
res.status(200).send(conversations); | |
}); |
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(); |
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 { | |
/* ... */ | |
deleteConversation = (id: string) => { | |
if (id in ConversationStorage) { | |
delete ConversationStorage[id]; | |
return Promise.resolve(true); | |
} | |
return Promise.resolve(false); | |
}; | |
/* ... */ |
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
.put(async (req, res) => { | |
//continue an ongoing conversation | |
const { id } = req.params; | |
const { message } = req.body; | |
const response = await inMemoryDB.updateConversation(id, { | |
text: message, | |
sent: new Date(), | |
source: "user", | |
}); | |
res.status(200).send(response); |
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 { | |
/* ... */ | |
private newMessage = ( | |
message: OpenAI.Chat.Completions.ChatCompletionMessageParam | |
) => ({ ...message, sent: new Date() }); | |
sendMessages = async ( | |
id: string, | |
messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[] | |
) => { | |
ConversationStorage[id].messages.push(...messages.map(this.newMessage)); |
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
.post(async (req, res) => { | |
//start a new conversation | |
const { id } = req.params; | |
const { persona, message } = req.body; | |
const response = await inMemoryDB.createConversation(id, persona, { | |
text: message, | |
sent: new Date(), | |
source: "user", | |
}); | |
res.status(200).send(response); |
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
app.route("/conversation/:id") | |
.get(async (req, res) => { | |
//get a conversation | |
const { id } = req.params; | |
const response = await inMemoryDB.getConversation(id); | |
res.status(200).send(response); | |
}) |
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 { | |
/* ... */ | |
startConversation = async ( | |
id: string, | |
systemPersona: string, | |
persona: string, | |
message: string | |
) => { | |
const startConversationTime = new Date(); | |
const startMessages: ChatCompletionMessageParam[] = [ |
NewerOlder