repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import { Groq } from "groq-sdk"; |
| #2 | import { LLM, LLMResponse } from "./base"; |
| #3 | import { LLMConfig, Message } from "../types"; |
| #4 | |
| #5 | export class GroqLLM implements LLM { |
| #6 | private client: Groq; |
| #7 | private model: string; |
| #8 | |
| #9 | constructor(config: LLMConfig) { |
| #10 | const apiKey = config.apiKey || process.env.GROQ_API_KEY; |
| #11 | if (!apiKey) { |
| #12 | throw new Error("Groq API key is required"); |
| #13 | } |
| #14 | this.client = new Groq({ apiKey }); |
| #15 | this.model = config.model || "llama3-70b-8192"; |
| #16 | } |
| #17 | |
| #18 | async generateResponse( |
| #19 | messages: Message[], |
| #20 | responseFormat?: { type: string }, |
| #21 | ): Promise<string> { |
| #22 | const response = await this.client.chat.completions.create({ |
| #23 | model: this.model, |
| #24 | messages: messages.map((msg) => ({ |
| #25 | role: msg.role as "system" | "user" | "assistant", |
| #26 | content: |
| #27 | typeof msg.content === "string" |
| #28 | ? msg.content |
| #29 | : JSON.stringify(msg.content), |
| #30 | })), |
| #31 | response_format: responseFormat as { type: "text" | "json_object" }, |
| #32 | }); |
| #33 | |
| #34 | return response.choices[0].message.content || ""; |
| #35 | } |
| #36 | |
| #37 | async generateChat(messages: Message[]): Promise<LLMResponse> { |
| #38 | const response = await this.client.chat.completions.create({ |
| #39 | model: this.model, |
| #40 | messages: messages.map((msg) => ({ |
| #41 | role: msg.role as "system" | "user" | "assistant", |
| #42 | content: |
| #43 | typeof msg.content === "string" |
| #44 | ? msg.content |
| #45 | : JSON.stringify(msg.content), |
| #46 | })), |
| #47 | }); |
| #48 | |
| #49 | const message = response.choices[0].message; |
| #50 | return { |
| #51 | content: message.content || "", |
| #52 | role: message.role, |
| #53 | }; |
| #54 | } |
| #55 | } |
| #56 |