MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / callGemini

Function callGemini

uai/uai.ts:159–186  ·  view source on GitHub ↗
(
    provider: Provider,
    prompt: string,
    content: string,
    timeout: number
)

Source from the content-addressed store, hash-verified

157): Promise<string> {
158 const url = `${trimBase(provider.base_url)}/v1beta/models/${provider.model}:generateContent`;
159 const headers: Record<string, string> = { "Content-Type": "application/json" };
160 const params: Record<string, string> = {};
161
162 if (provider.auth_method === "query_param" || provider.auth_method === "bearer_token") {
163 params["key"] = provider.api_key;
164 }
165 if (provider.auth_method === "api_key_header") {
166 headers["x-goog-api-key"] = provider.api_key;
167 }
168
169 const response = await axios.post(
170 url,
171 {
172 contents: [{ role: "user", parts: [{ text: `${prompt}\n\n${content}` }] }]
173 },
174 { headers, params, timeout }
175 );
176
177 const parts = response.data?.candidates?.[0]?.content?.parts || [];
178 return parts.map((p: any) => p.text || "").join("");
179}
180
181async function callAI(provider: Provider, prompt: string, content: string, timeout: number): Promise<string> {
182 if (provider.type === "gemini") {
183 return await callGemini(provider, prompt, content, timeout);
184 }
185 return await callOpenAI(provider, prompt, content, timeout);
186}
187
188// ========== 消息收集 ==========
189type MessageData = { time: string; sender: string; text: string };

Callers 1

callAIFunction · 0.70

Calls 1

trimBaseFunction · 0.85

Tested by

no test coverage detected