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 { GoogleGenAI } from "@google/genai"; |
| #2 | import { LLM, LLMResponse } from "./base"; |
| #3 | import { LLMConfig, Message } from "../types"; |
| #4 | |
| #5 | export class GoogleLLM implements LLM { |
| #6 | private google: GoogleGenAI; |
| #7 | private model: string; |
| #8 | |
| #9 | constructor(config: LLMConfig) { |
| #10 | this.google = new GoogleGenAI({ apiKey: config.apiKey }); |
| #11 | this.model = config.model || "gemini-2.0-flash"; |
| #12 | } |
| #13 | |
| #14 | async generateResponse( |
| #15 | messages: Message[], |
| #16 | responseFormat?: { type: string }, |
| #17 | tools?: any[], |
| #18 | ): Promise<string | LLMResponse> { |
| #19 | const completion = await this.google.models.generateContent({ |
| #20 | contents: messages.map((msg) => ({ |
| #21 | parts: [ |
| #22 | { |
| #23 | text: |
| #24 | typeof msg.content === "string" |
| #25 | ? msg.content |
| #26 | : JSON.stringify(msg.content), |
| #27 | }, |
| #28 | ], |
| #29 | role: msg.role === "system" ? "model" : "user", |
| #30 | })), |
| #31 | |
| #32 | model: this.model, |
| #33 | // config: { |
| #34 | // responseSchema: {}, // Add response schema if needed |
| #35 | // }, |
| #36 | }); |
| #37 | |
| #38 | const text = completion.text |
| #39 | ?.replace(/^```json\n/, "") |
| #40 | .replace(/\n```$/, ""); |
| #41 | |
| #42 | return text || ""; |
| #43 | } |
| #44 | |
| #45 | async generateChat(messages: Message[]): Promise<LLMResponse> { |
| #46 | const completion = await this.google.models.generateContent({ |
| #47 | contents: messages, |
| #48 | model: this.model, |
| #49 | }); |
| #50 | const response = completion.candidates![0].content; |
| #51 | return { |
| #52 | content: response!.parts![0].text || "", |
| #53 | role: response!.role!, |
| #54 | }; |
| #55 | } |
| #56 | } |
| #57 |