Skip to content

Commit

Permalink
fix: mock both language models and safe generator
Browse files Browse the repository at this point in the history
Co-Authored-By: Han Xiao <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and hanxiao committed Feb 13, 2025
1 parent ed75cf4 commit ef72ac3
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/tools/__tests__/evaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,42 @@ jest.mock('@ai-sdk/google', () => ({
GoogleChatLanguageModel: jest.fn()
}));

// Mock the safe generator to prevent actual API calls
jest.mock('../../utils/safe-generator', () => ({
ObjectGeneratorSafe: jest.fn().mockImplementation(() => ({
// Mock the language models
jest.mock('@ai-sdk/google', () => ({
GoogleChatLanguageModel: jest.fn().mockImplementation(() => ({
generateObject: jest.fn().mockImplementation(async () => ({
object: mockEvalResponse,
usage: { totalTokens: 0, promptTokens: 0, completionTokens: 0 }
}))
}))
}));

// Mock the safe generator to prevent actual API calls
jest.mock('../../utils/safe-generator', () => ({
ObjectGeneratorSafe: jest.fn().mockImplementation(() => ({
generateObject: jest.fn().mockImplementation(async (params: any) => {
const { schema } = params;
// Return different responses based on the schema
if (schema.description?.includes('question requires freshness')) {
return {
object: {
needsFreshness: false,
needsPlurality: false,
reasoning: 'Simple test question',
languageStyle: 'plain English'
},
usage: { totalTokens: 0, promptTokens: 0, completionTokens: 0 }
};
}
// Default response for other schemas
return {
object: mockEvalResponse,
usage: { totalTokens: 0, promptTokens: 0, completionTokens: 0 }
};
})
}))
}));

// Mock safe generator to prevent actual API calls
jest.mock('../../utils/safe-generator', () => ({
ObjectGeneratorSafe: jest.fn().mockImplementation(() => ({
Expand Down

0 comments on commit ef72ac3

Please sign in to comment.