refactor: remove CLI, local LLM support, and unused configs
This commit is contained in:
parent
55ddcd3180
commit
0ae3b9f686
8 changed files with 0 additions and 575 deletions
|
|
@ -1,42 +0,0 @@
|
|||
import { LLM_CONFIG } from "../../config/llm.js";
|
||||
import { OpenAiCompatibleAdapter } from "./openai-compatible.js";
|
||||
import { GeminiAdapter } from "./gemini.js";
|
||||
import type { LlmAdapter } from "./types.js";
|
||||
|
||||
export function createAdapter(): LlmAdapter {
|
||||
switch (LLM_CONFIG.provider) {
|
||||
case "local":
|
||||
return new OpenAiCompatibleAdapter(
|
||||
LLM_CONFIG.url,
|
||||
undefined,
|
||||
LLM_CONFIG.model,
|
||||
);
|
||||
case "openrouter":
|
||||
return new OpenAiCompatibleAdapter(
|
||||
LLM_CONFIG.url,
|
||||
process.env["OPENROUTER_API_KEY"],
|
||||
LLM_CONFIG.model,
|
||||
);
|
||||
case "deepseek":
|
||||
return new OpenAiCompatibleAdapter(
|
||||
LLM_CONFIG.url,
|
||||
process.env["DEEPSEEK_API_KEY"],
|
||||
LLM_CONFIG.model,
|
||||
);
|
||||
case "groq":
|
||||
return new OpenAiCompatibleAdapter(
|
||||
LLM_CONFIG.url,
|
||||
process.env["GROQ_API_KEY"],
|
||||
LLM_CONFIG.model,
|
||||
);
|
||||
case "gemini": {
|
||||
const apiKey = process.env["GEMINI_API_KEY"];
|
||||
if (!apiKey) throw new Error("GEMINI_API_KEY env var not set");
|
||||
if (!LLM_CONFIG.model)
|
||||
throw new Error("LLM_CONFIG.model required for gemini");
|
||||
return new GeminiAdapter(apiKey, LLM_CONFIG.model);
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unknown provider: ${LLM_CONFIG.provider as string}`);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
import type { LlmAdapter } from "./types.js";
|
||||
|
||||
interface OpenAiResponse {
|
||||
choices: Array<{ message: { content: string } }>;
|
||||
usage: {
|
||||
prompt_tokens: number;
|
||||
completion_tokens: number;
|
||||
total_tokens: number;
|
||||
};
|
||||
timings?: { prompt_ms: number; predicted_ms: number };
|
||||
}
|
||||
|
||||
export class OpenAiCompatibleAdapter implements LlmAdapter {
|
||||
private url: string;
|
||||
private apiKey: string | undefined;
|
||||
private model: string | undefined;
|
||||
|
||||
constructor(url: string, apiKey?: string, model?: string) {
|
||||
this.url = url;
|
||||
this.apiKey = apiKey;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
async call(
|
||||
words: string[],
|
||||
systemPrompt: string,
|
||||
): Promise<{
|
||||
content: string;
|
||||
promptTokens: number;
|
||||
completionTokens: number;
|
||||
totalTokens: number;
|
||||
promptTimeMs: number | null;
|
||||
completionTimeMs: number | null;
|
||||
totalTimeMs: number;
|
||||
}> {
|
||||
const payload: Record<string, unknown> = {
|
||||
messages: [
|
||||
{ role: "system", content: systemPrompt },
|
||||
{ role: "user", content: JSON.stringify(words) },
|
||||
],
|
||||
temperature: 0.1,
|
||||
top_p: 0.9,
|
||||
max_tokens: Math.ceil(words.length * 250 * 1.2),
|
||||
};
|
||||
|
||||
if (this.model) {
|
||||
payload["model"] = this.model;
|
||||
}
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
|
||||
if (this.apiKey) {
|
||||
headers["Authorization"] = `Bearer ${this.apiKey}`;
|
||||
}
|
||||
|
||||
const startTime = Date.now();
|
||||
|
||||
const response = await fetch(this.url, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
const totalTimeMs = Date.now() - startTime;
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`LLM server responded with status: ${response.status}`);
|
||||
}
|
||||
|
||||
const json = (await response.json()) as OpenAiResponse;
|
||||
|
||||
const content = json.choices[0]?.message?.content;
|
||||
if (!content) {
|
||||
throw new Error("LLM response content is empty");
|
||||
}
|
||||
|
||||
const promptTokens = json.usage.prompt_tokens;
|
||||
const completionTokens = json.usage.completion_tokens;
|
||||
|
||||
return {
|
||||
content,
|
||||
promptTokens,
|
||||
completionTokens,
|
||||
totalTokens: json.usage.total_tokens,
|
||||
promptTimeMs: json.timings?.prompt_ms ?? null,
|
||||
completionTimeMs: json.timings?.predicted_ms ?? null,
|
||||
totalTimeMs,
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue