File size: 2,310 Bytes
6aaf221 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
// src/chatwrapper.ts
import {
AuthType,
createContentGeneratorConfig,
createContentGenerator,
} from '@google/gemini-cli-core/dist/src/core/contentGenerator.js';
/* ------------------------------------------------------------------ */
/* 1. Build the ContentGenerator exactly like the CLI does */
/* ------------------------------------------------------------------ */
let modelName: string; // we'll fill this once
const generatorPromise = (async () => {
// Pass undefined for model so the helper falls back to DEFAULT_GEMINI_MODEL
const cfg = await createContentGeneratorConfig(
undefined, // let helper pick default (Gemini-2.5-Pro)
AuthType.USE_GEMINI // same mode the CLI defaults to
);
modelName = cfg.model; // remember the actual model string
return await createContentGenerator(cfg);
})();
/* ------------------------------------------------------------------ */
/* 2. Helpers consumed by server.ts */
/* ------------------------------------------------------------------ */
type GenConfig = Record<string, unknown>;
export async function sendChat({
contents,
generationConfig = {},
}: {
contents: any[];
generationConfig?: GenConfig;
tools?: unknown; // accepted but ignored for now
}) {
const generator: any = await generatorPromise;
return await generator.generateContent({
model: modelName,
contents,
config: generationConfig,
});
}
export async function* sendChatStream({
contents,
generationConfig = {},
}: {
contents: any[];
generationConfig?: GenConfig;
tools?: unknown;
}) {
const generator: any = await generatorPromise;
const stream = await generator.generateContentStream({
model: modelName,
contents,
config: generationConfig,
});
for await (const chunk of stream) yield chunk;
}
/* ------------------------------------------------------------------ */
/* 3. Minimal stubs so server.ts compiles (extend later) */
/* ------------------------------------------------------------------ */
export function listModels() {
return [{ id: modelName }];
}
export async function embed(_input: unknown) {
throw new Error('Embeddings endpoint not implemented yet.');
}
|