|
| 1 | +import { RuntOpenAIClient } from "./openai-client.ts"; |
| 2 | +import type { OpenAIConfig } from "./openai-client.ts"; |
| 3 | +import type { AiModel } from "@runt/lib"; |
| 4 | +import { logger, VERSION } from "@runt/lib"; |
| 5 | + |
| 6 | +export class GroqClient extends RuntOpenAIClient { |
| 7 | + override provider: string = "groq"; |
| 8 | + override defaultConfig: OpenAIConfig = { |
| 9 | + baseURL: "https://api.groq.com/openai/v1", |
| 10 | + }; |
| 11 | + |
| 12 | + override getConfigMessage(): string { |
| 13 | + const configMessage = `# Groq Configuration Required |
| 14 | + |
| 15 | +Groq API key not found. Please set \`GROQ_API_KEY\` environment variable.`; |
| 16 | + return configMessage; |
| 17 | + } |
| 18 | + |
| 19 | + override discoverAiModels(): Promise<AiModel[]> { |
| 20 | + if (!this.isReady()) { |
| 21 | + logger.warn( |
| 22 | + `${this.provider} client not ready, returning empty models list`, |
| 23 | + ); |
| 24 | + return Promise.resolve([]); |
| 25 | + } |
| 26 | + const groqModels: AiModel[] = [ |
| 27 | + { |
| 28 | + provider: "groq", |
| 29 | + name: "moonshotai/kimi-k2-instruct-0905", |
| 30 | + displayName: "Kimi K2 Instruct 0905", |
| 31 | + capabilities: ["completion", "tools", "thinking"], |
| 32 | + }, |
| 33 | + { |
| 34 | + provider: "groq", |
| 35 | + name: "moonshotai/kimi-k2-instruct", |
| 36 | + displayName: "Kimi K2 Instruct", |
| 37 | + capabilities: ["completion", "tools", "thinking"], |
| 38 | + }, |
| 39 | + { |
| 40 | + provider: "groq", |
| 41 | + name: "llama3-8b-8192", |
| 42 | + displayName: "Llama 3.1 8B", |
| 43 | + capabilities: ["completion", "tools", "thinking"], |
| 44 | + }, |
| 45 | + { |
| 46 | + provider: "groq", |
| 47 | + name: "llama3-70b-8192", |
| 48 | + displayName: "Llama 3.1 70B", |
| 49 | + capabilities: ["completion", "tools", "thinking"], |
| 50 | + }, |
| 51 | + { |
| 52 | + provider: "groq", |
| 53 | + name: "mixtral-8x7b-32768", |
| 54 | + displayName: "Mixtral 8x7B", |
| 55 | + capabilities: ["completion", "tools"], |
| 56 | + }, |
| 57 | + { |
| 58 | + provider: "groq", |
| 59 | + name: "gemma2-9b-it", |
| 60 | + displayName: "Gemma 2 9B", |
| 61 | + capabilities: ["completion", "tools"], |
| 62 | + }, |
| 63 | + ]; |
| 64 | + return Promise.resolve(groqModels); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +export class AnacondaAIClient extends GroqClient { |
| 69 | + override provider: string = "anaconda"; |
| 70 | + override envPrefix: string = "RUNT"; |
| 71 | + override defaultConfig: OpenAIConfig = { |
| 72 | + baseURL: "https://anaconda.com/api/assistant/v3/groq", |
| 73 | + defaultHeaders: { |
| 74 | + "X-Client-Version": VERSION, |
| 75 | + "X-Client-Source": "anaconda-runt-dev", |
| 76 | + }, |
| 77 | + }; |
| 78 | + |
| 79 | + override async discoverAiModels(): Promise<AiModel[]> { |
| 80 | + const models = await super.discoverAiModels(); |
| 81 | + |
| 82 | + for (const model of models) { |
| 83 | + model.provider = "anaconda"; |
| 84 | + } |
| 85 | + |
| 86 | + return models; |
| 87 | + } |
| 88 | + |
| 89 | + override getConfigMessage(): string { |
| 90 | + const configMessage = `# Anaconda/Runt Configuration Required |
| 91 | + |
| 92 | +RUNT API key not found. Please set \`RUNT_API_KEY\` environment variable.`; |
| 93 | + return configMessage; |
| 94 | + } |
| 95 | +} |
0 commit comments