Google LLM Bridge
Google Generative AI(Gemini)์ llm-bridge-spec ๊ณตํต ์ธํฐํ์ด์ค๋ฅผ ์ฐ๊ฒฐํ๋ ์ด๋ํฐ์
๋๋ค. ๋ชจ๋ธ, ๊ฐ๊ฒฉ, ์ปจํ
์คํธ ์ ๋ณด์ ์์ฑ ์ต์
์ ํ๊ณณ์์ ๊ด๋ฆฌํ์ฌ ์ ๋ชจ๋ธ์ด ์ถ๊ฐ๋๋๋ผ๋ ์ต์ํ์ ์์ ์ผ๋ก ํ์ฅํ ์ ์์ต๋๋ค.
์ฃผ์ ํน์ง
- ํ์
์์ ํ ์ค์ :
GoogleModelEnum๊ณผ Zod ์คํค๋ง๋ก ๋ชจ๋ธ๊ณผ ์ต์
์ ๊ฒ์ฆํ๊ณ ๊ธฐ๋ณธ๊ฐ์ ์ ๊ณตํฉ๋๋ค.
- ํ๋ถํ ์์ฑ ์ต์
: ํ ํฐ ํ๋, ์ํ๋ง ํ๋ผ๋ฏธํฐ, JSON ์๋ต ์คํค๋ง, Safety ์ค์ ๋ฑ์ ๊ทธ๋๋ก ์ ๋ฌํฉ๋๋ค.
- ๋๊ตฌ ํธ์ถ & ์คํธ๋ฆฌ๋ฐ ์ง์: Gemini Function Calling ์๋ต์
toolCalls๋ก ๋ณํํ๊ณ , ์คํธ๋ฆผ ๋ชจ๋์์๋ ์ฆ๋ถ ํ
์คํธ์ ์ฌ์ฉ๋์ ์์ฐจ์ ์ผ๋ก ์ ๊ณตํฉ๋๋ค.
- ์ผ๊ด๋ ๋ฉํ๋ฐ์ดํฐ: ์ปจํ
์คํธ ์๋์ฐ, ์ถ๋ ฅ ํ ํฐ ํ๋, ๊ฐ๊ฒฉ ์ ๋ณด๋ฅผ ์ค์์์ ๊ด๋ฆฌํ๊ณ ๋งค๋ํ์คํธยท๋ฌธ์์ ์ฐ๋ํฉ๋๋ค.
์ค์น
pnpm add google-llm-bridge llm-bridge-spec @google/generative-ai zod
๋น ๋ฅธ ์์
import { createGoogleAIBridge, GoogleModelEnum } from 'google-llm-bridge';
const bridge = createGoogleAIBridge({
apiKey: process.env.GOOGLE_API_KEY!,
model: GoogleModelEnum.GEMINI_1_5_FLASH,
temperature: 0.4,
maxOutputTokens: 2048,
safetySettings: [{ category: 'HARM_CATEGORY_HATE_SPEECH', threshold: 'BLOCK_LOW_AND_ABOVE' }],
});
const response = await bridge.invoke({
messages: [
{ role: 'system', content: [{ contentType: 'text', value: 'You are a concise assistant.' }] },
{ role: 'user', content: [{ contentType: 'text', value: '์์ธ ๋ ์จ๋ฅผ ์๋ ค์ค.' }] },
],
tools: [
{
name: 'getWeather',
description: 'Retrieve the weather forecast',
parameters: {
type: 'object',
properties: { city: { type: 'string' } },
required: ['city'],
},
},
],
});
console.log(response.content.value);
if (response.toolCalls?.length) {
console.log('tool call arguments:', response.toolCalls[0].arguments);
}
์คํธ๋ฆฌ๋ฐ ์ฌ์ฉ ์์
const stream = bridge.invokeStream({
messages: [
{ role: 'user', content: [{ contentType: 'text', value: '10์ค ์ด๋ด๋ก ์๊ธฐ์๊ฐํด์ค' }] },
],
});
for await (const chunk of stream) {
if (chunk.content.value) {
process.stdout.write(chunk.content.value);
}
}
์ค์ ์ต์
์์ฝ
model | GoogleModelEnum ์ค ํ๋ (๊ธฐ๋ณธ๊ฐ gemini-1.5-flash) |
temperature, topP, topK | ์ํ๋ง ํ๋ผ๋ฏธํฐ |
maxOutputTokens, stopSequences, candidateCount | ์ถ๋ ฅ ์ ์ด ์ต์
|
responseMimeType, responseSchema | JSON ์ถ๋ ฅ ๊ฐ์ ยท์คํค๋ง ์ ์ |
presencePenalty, frequencyPenalty | ๋ฐ๋ณต ์ต์ ๊ณ์ |
safetySettings | Safety ํํฐ ๊ธฐ์ค(์นดํ
๊ณ ๋ฆฌ/์๊ณ๊ฐ) |
๋ชจ๋ธ ์คํ ๋ฌธ์
์ง์๋๋ ๋ชจ๋ธ๊ณผ ์ต์ ์คํ์ docs/models.md์์ ํ์ธํ ์ ์์ต๋๋ค. ๋ฌธ์์ ์ ๋ฆฌ๋ ์ ๋ณด๋ google-models.ts์ MODEL_METADATA๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์๋์ผ๋ก ์ ์ง๋ฉ๋๋ค.