mirror of
https://github.com/NousResearch/atropos.git
synced 2026-04-24 17:04:55 +00:00
Move to subfolder
This commit is contained in:
parent
a88e3afddf
commit
7eae51cc5c
23 changed files with 0 additions and 0 deletions
31
environments/hack0/DeepSacrifice/server/llm/openai_client.ts
Normal file
31
environments/hack0/DeepSacrifice/server/llm/openai_client.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* OpenAI API client for GPT-4o-mini feedback.
|
||||
* Expects to run in Bun/Node.js where process.env is available.
|
||||
* If you see a type error for 'process', install @types/node as a dev dependency.
|
||||
*/
|
||||
|
||||
import OpenAI from "openai";
|
||||
import type { ChatCompletionMessageParam } from "openai/resources/chat/completions";
|
||||
|
||||
const OPENAI_API_KEY = process.env.OPENAI_API_KEY || "";
|
||||
const MODEL = "gpt-4o-mini"; // Use gpt-4o-mini if available, else gpt-4o
|
||||
|
||||
if (!OPENAI_API_KEY) {
|
||||
throw new Error("OPENAI_API_KEY is not set");
|
||||
}
|
||||
|
||||
const openai = new OpenAI({ apiKey: OPENAI_API_KEY });
|
||||
|
||||
export async function callOpenAI(
|
||||
messages: ChatCompletionMessageParam[],
|
||||
max_tokens = 64,
|
||||
): Promise<string> {
|
||||
const response = await openai.chat.completions.create({
|
||||
model: MODEL,
|
||||
messages,
|
||||
max_tokens,
|
||||
});
|
||||
const content = response.choices[0]?.message?.content;
|
||||
if (!content) throw new Error("No content returned from OpenAI");
|
||||
return content.trim();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue