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[] = [ |
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 { | |
/* ... */ | |
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", |
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 { personas } from "../persona"; | |
import { ChatGptConversationService } from "./chatgpt"; | |
import {Conversation, ConversationList, ConversationListEntry, ConversationService, Message } from "./types"; | |
/* | |
* Should only be instantiated once for this app due to it being used in-memory rather than synced to a store | |
*/ | |
export class InMemoryConversationService implements ConversationService { | |
chatgpt: ChatGptConversationService; | |
constructor() { |
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 OpenAI from "openai"; | |
import { ChatCompletionMessageParam } from "openai/resources"; | |
import { Message } from "../types"; | |
const openai = new OpenAI({ | |
apiKey: process.env.OPEN_AI_API_KEY, | |
}); | |
type StorageMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam & { | |
sent: Date; |
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("/persona").get(async (req, res) => { | |
const personas = getPersonas(); | |
const personaMap = personas.map((p) => ({ | |
id: p.id, | |
name: p.name, | |
imageUri: p.imageUri, | |
})); | |
res.status(200).send(personaMap); |
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 } | |
> = { | |
Builder: { | |
name: "Craig", | |
imageUri: "./Craig.png", | |
role: "Builder", | |
prompt: "You are a master craftsman, able to build anything you can imagine. When responding, be gruff but helpful. 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
export type Message = { text: string; sent: Date; source: string }; | |
export type Conversation = Message[]; | |
export type ConversationListEntry = { | |
id: string; | |
persona: string; | |
firstMessage: Message; | |
}; | |
export type ConversationList = ConversationListEntry[]; | |
export interface ConversationService { | |
getConversationList: () => Promise<ConversationList>; |
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 express from "express"; | |
const app = express(); | |
app.use(express.json()); | |
app.get("/", (req, res) => { | |
res.send("Hello World"); | |
}); | |
const run = () => { |
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
services: | |
api: | |
build: ./api | |
ports: | |
- "3010:3000" | |
volumes: | |
- .:/app | |
environment: | |
- NODE_ENV=development | |
- PORT=3000 |
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
FROM node:21-alpine | |
WORKDIR /app/web | |
COPY . . | |
RUN npm install --silent --legacy-peer-deps | |
CMD ["npm", "run", "dev"] |