summaryrefslogtreecommitdiff
path: root/packages/ai/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/ai/index.ts')
-rw-r--r--packages/ai/index.ts76
1 files changed, 76 insertions, 0 deletions
diff --git a/packages/ai/index.ts b/packages/ai/index.ts
new file mode 100644
index 0000000..d2fc090
--- /dev/null
+++ b/packages/ai/index.ts
@@ -0,0 +1,76 @@
+// import Openai from "./src/openai";
+import Claude from "./src/claude";
+import Gemini from "./src/gemini";
+import Generic from "./src/generic";
+import OpenAIResponses from "./src/openai-responses";
+import type { AIModelAPI, LLMChoice } from "./src/types";
+
+export type * from "./src/types";
+export * as NLP from "./src/nlp";
+
+export default function (choice: LLMChoice): AIModelAPI {
+ try {
+ const api =
+ "gemini" in choice
+ ? new Gemini(choice.gemini)
+ : "claude" in choice
+ ? new Claude(choice.claude)
+ : "chatgpt" in choice
+ ? new OpenAIResponses({
+ baseURL: "https://api.openai.com/v1",
+ apiKey: Bun.env.OPENAI_API_KEY!,
+ model: choice.chatgpt || "gpt-5-nano",
+ })
+ : "deepseek" in choice
+ ? new Generic({
+ baseURL: "https://api.deepseek.com",
+ apiKey: Bun.env.DEEPSEEK_API_KEY!,
+ model: "deepseek-reasoner",
+ })
+ : "kimi" in choice
+ ? new Generic({
+ baseURL: "https://api.moonshot.ai/v1",
+ apiKey: Bun.env.MOONSHOT_API_KEY!,
+ model: "kimi-k2-0905-preview", // "kimi-latest"?
+ })
+ : "grok" in choice
+ ? new Generic({
+ baseURL: "https://api.x.ai/v1",
+ apiKey: Bun.env.XAI_API_KEY!,
+ model: "grok-4", // "kimi-latest"?
+ })
+ : new Generic({
+ baseURL: choice.openai.url,
+ apiKey: choice.openai.apiKey,
+ model: choice.openai.model,
+ allowBrowser: choice.openai.allowBrowser,
+ });
+ // "" in choice
+ // ? new Generic(choice.other)
+ // : choice.name === "deepseek"
+ // ? new Generic({
+ // baseURL: "https://api.deepseek.com",
+ // apiKey: Bun.env.DEEPSEEK_API_KEY!,
+ // model: "deepseek-chat",
+ // })
+ // : choice.name === "grok"
+ // ? new Generic({
+ // baseURL: "https://api.x.ai/v1",
+ // apiKey: Bun.env.GROK_API_KEY!,
+ // model: "grok-2-latest",
+ // })
+ // : choice.name === "chatgpt"
+ // ? new Generic({
+ // baseURL: "https://api.openai.com/v1",
+ // apiKey: Bun.env.OPENAI_API_KEY!,
+ // model: "gpt-4o",
+ // })
+ // : choice.name === "claude"
+ // ? new Claude()
+ // : new Gemini();
+ return api;
+ } catch (e) {
+ // TODO
+ console.error("couldnt start API", e);
+ }
+}