Merge branch 'feat/backend'

This commit is contained in:
Christopher Mayor
2026-04-24 15:01:37 -07:00
9 changed files with 107 additions and 12 deletions

View File

@@ -7,9 +7,14 @@ import type {
} from "../types";
import type { SearchResult } from "./tavily";
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
let _client: OpenAI | null = null;
function getClient(): OpenAI {
if (!_client) {
_client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
}
return _client;
}
const SYSTEM_PROMPT = `You are an expert research analyst. Your job is to compare items across multiple dimensions and produce structured, insightful comparison data.
@@ -106,7 +111,7 @@ Provide a comprehensive comparison with scores, pros/cons, and a recommendation.
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
try {
const response = await client.chat.completions.create({
const response = await getClient().chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: "system", content: SYSTEM_PROMPT },