fix: replace require with dynamic imports and fix unused parameter

Co-Authored-By: Han Xiao <han.xiao@jina.ai>
This commit is contained in:
Devin AI 2025-02-05 10:06:41 +00:00
parent 40fef7b793
commit 34e3111a9e
2 changed files with 7 additions and 24 deletions

View File

@ -1,17 +1,4 @@
import { GoogleAIWrapper, LocalLLMClient } from '../utils/llm-client';
import { llmClient } from '../config';
jest.mock('../config', () => {
let mockConfig = { llmClient: null };
return {
get llmClient() {
return mockConfig.llmClient;
},
__setMockConfig: (config: { llmClient: any }) => {
mockConfig = config;
}
};
});
describe('LLM Client', () => {
const originalEnv = process.env;
@ -25,23 +12,19 @@ describe('LLM Client', () => {
process.env = originalEnv;
});
it('should use GoogleAIWrapper by default', () => {
it('should use GoogleAIWrapper by default', async () => {
process.env.LLM_PROVIDER = 'gemini';
process.env.GEMINI_API_KEY = 'test-key';
jest.isolateModules(() => {
const { llmClient } = require('../config');
expect(llmClient).toBeInstanceOf(GoogleAIWrapper);
});
const { llmClient } = await import('../config');
expect(llmClient).toBeInstanceOf(GoogleAIWrapper);
});
it('should use LocalLLMClient when configured', () => {
it('should use LocalLLMClient when configured', async () => {
process.env.LLM_PROVIDER = 'local';
process.env.LOCAL_LLM_HOSTNAME = 'localhost';
process.env.LOCAL_LLM_PORT = '8000';
process.env.LOCAL_LLM_MODEL = 'test-model';
jest.isolateModules(() => {
const { llmClient } = require('../config');
expect(llmClient).toBeInstanceOf(LocalLLMClient);
});
const { llmClient } = await import('../config');
expect(llmClient).toBeInstanceOf(LocalLLMClient);
});
});

View File

@ -3,7 +3,7 @@ import { LLMClient, LLMClientConfig } from '../../../utils/llm-client';
export class MockLLMClient implements LLMClient {
constructor(private mockResponse: string = '{"queries": ["test query"]}') {}
getGenerativeModel(_config: LLMClientConfig) {
getGenerativeModel(_: LLMClientConfig) {
return {
generateContent: async () => ({
response: {