mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-17 09:52:38 -05:00
feat(tools): add generic search tool (#2140)
This commit is contained in:
@@ -318,48 +318,49 @@ describe('GenericBlockHandler', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it.concurrent('should not process cost info for non-knowledge tools', async () => {
|
||||
// Set up non-knowledge tool
|
||||
mockBlock.config.tool = 'some_other_tool'
|
||||
mockTool.id = 'some_other_tool'
|
||||
it.concurrent(
|
||||
'should process cost info for all tools (universal cost extraction)',
|
||||
async () => {
|
||||
mockBlock.config.tool = 'some_other_tool'
|
||||
mockTool.id = 'some_other_tool'
|
||||
|
||||
mockGetTool.mockImplementation((toolId) => {
|
||||
if (toolId === 'some_other_tool') {
|
||||
return mockTool
|
||||
mockGetTool.mockImplementation((toolId) => {
|
||||
if (toolId === 'some_other_tool') {
|
||||
return mockTool
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
|
||||
const inputs = { param: 'value' }
|
||||
const mockToolResponse = {
|
||||
success: true,
|
||||
output: {
|
||||
result: 'success',
|
||||
cost: {
|
||||
input: 0.001,
|
||||
output: 0.002,
|
||||
total: 0.003,
|
||||
tokens: { prompt: 100, completion: 50, total: 150 },
|
||||
model: 'some-model',
|
||||
},
|
||||
},
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
|
||||
const inputs = { param: 'value' }
|
||||
const mockToolResponse = {
|
||||
success: true,
|
||||
output: {
|
||||
mockExecuteTool.mockResolvedValue(mockToolResponse)
|
||||
|
||||
const result = await handler.execute(mockContext, mockBlock, inputs)
|
||||
|
||||
expect(result).toEqual({
|
||||
result: 'success',
|
||||
cost: {
|
||||
input: 0.001,
|
||||
output: 0.002,
|
||||
total: 0.003,
|
||||
tokens: { prompt: 100, completion: 50, total: 150 },
|
||||
model: 'some-model',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
mockExecuteTool.mockResolvedValue(mockToolResponse)
|
||||
|
||||
const result = await handler.execute(mockContext, mockBlock, inputs)
|
||||
|
||||
// Should return original output without cost transformation
|
||||
expect(result).toEqual({
|
||||
result: 'success',
|
||||
cost: {
|
||||
input: 0.001,
|
||||
output: 0.002,
|
||||
total: 0.003,
|
||||
tokens: { prompt: 100, completion: 50, total: 150 },
|
||||
model: 'some-model',
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -104,7 +104,7 @@ export class GenericBlockHandler implements BlockHandler {
|
||||
const output = result.output
|
||||
let cost = null
|
||||
|
||||
if (block.config.tool?.startsWith('knowledge_') && output?.cost) {
|
||||
if (output?.cost) {
|
||||
cost = output.cost
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user