mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
Basic code assist support (#910)
This commit is contained in:
committed by
GitHub
parent
4e84431df3
commit
d79dafc577
@@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
EmbedContentResponse,
|
||||
EmbedContentParameters,
|
||||
GenerateContentConfig,
|
||||
Part,
|
||||
@@ -37,7 +36,6 @@ import {
|
||||
ContentGenerator,
|
||||
createContentGenerator,
|
||||
} from './contentGenerator.js';
|
||||
|
||||
import { ProxyAgent, setGlobalDispatcher } from 'undici';
|
||||
|
||||
const proxy =
|
||||
@@ -52,7 +50,7 @@ if (proxy) {
|
||||
|
||||
export class GeminiClient {
|
||||
private chat: Promise<GeminiChat>;
|
||||
private contentGenerator: ContentGenerator;
|
||||
private contentGenerator: Promise<ContentGenerator>;
|
||||
private model: string;
|
||||
private embeddingModel: string;
|
||||
private generateContentConfig: GenerateContentConfig = {
|
||||
@@ -162,7 +160,7 @@ export class GeminiClient {
|
||||
const systemInstruction = getCoreSystemPrompt(userMemory);
|
||||
|
||||
return new GeminiChat(
|
||||
this.contentGenerator,
|
||||
await this.contentGenerator,
|
||||
this.model,
|
||||
{
|
||||
systemInstruction,
|
||||
@@ -289,6 +287,7 @@ export class GeminiClient {
|
||||
model: string = 'gemini-2.0-flash',
|
||||
config: GenerateContentConfig = {},
|
||||
): Promise<Record<string, unknown>> {
|
||||
const cg = await this.contentGenerator;
|
||||
const attempt = 1;
|
||||
const startTime = Date.now();
|
||||
try {
|
||||
@@ -302,7 +301,7 @@ export class GeminiClient {
|
||||
|
||||
let inputTokenCount = 0;
|
||||
try {
|
||||
const { totalTokens } = await this.contentGenerator.countTokens({
|
||||
const { totalTokens } = await cg.countTokens({
|
||||
model,
|
||||
contents,
|
||||
});
|
||||
@@ -317,7 +316,7 @@ export class GeminiClient {
|
||||
this._logApiRequest(model, inputTokenCount);
|
||||
|
||||
const apiCall = () =>
|
||||
this.contentGenerator.generateContent({
|
||||
cg.generateContent({
|
||||
model,
|
||||
config: {
|
||||
...requestConfig,
|
||||
@@ -397,6 +396,7 @@ export class GeminiClient {
|
||||
generationConfig: GenerateContentConfig,
|
||||
abortSignal: AbortSignal,
|
||||
): Promise<GenerateContentResponse> {
|
||||
const cg = await this.contentGenerator;
|
||||
const modelToUse = this.model;
|
||||
const configToUse: GenerateContentConfig = {
|
||||
...this.generateContentConfig,
|
||||
@@ -417,7 +417,7 @@ export class GeminiClient {
|
||||
|
||||
let inputTokenCount = 0;
|
||||
try {
|
||||
const { totalTokens } = await this.contentGenerator.countTokens({
|
||||
const { totalTokens } = await cg.countTokens({
|
||||
model: modelToUse,
|
||||
contents,
|
||||
});
|
||||
@@ -432,7 +432,7 @@ export class GeminiClient {
|
||||
this._logApiRequest(modelToUse, inputTokenCount);
|
||||
|
||||
const apiCall = () =>
|
||||
this.contentGenerator.generateContent({
|
||||
cg.generateContent({
|
||||
model: modelToUse,
|
||||
config: requestConfig,
|
||||
contents,
|
||||
@@ -478,8 +478,9 @@ export class GeminiClient {
|
||||
model: this.embeddingModel,
|
||||
contents: texts,
|
||||
};
|
||||
const embedContentResponse: EmbedContentResponse =
|
||||
await this.contentGenerator.embedContent(embedModelParams);
|
||||
|
||||
const cg = await this.contentGenerator;
|
||||
const embedContentResponse = await cg.embedContent(embedModelParams);
|
||||
if (
|
||||
!embedContentResponse.embeddings ||
|
||||
embedContentResponse.embeddings.length === 0
|
||||
@@ -508,7 +509,8 @@ export class GeminiClient {
|
||||
const chat = await this.chat;
|
||||
const history = chat.getHistory(true); // Get curated history
|
||||
|
||||
const { totalTokens } = await this.contentGenerator.countTokens({
|
||||
const cg = await this.contentGenerator;
|
||||
const { totalTokens } = await cg.countTokens({
|
||||
model: this.model,
|
||||
contents: history,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user