Skip to content

Commit bffa9ad

Browse files
committed
refactor(handleTools.js): change loadTools function signature to include functions parameter
feat(handleTools.test.js): add test for loading StructuredSD tool with functions parameter
1 parent d339c29 commit bffa9ad

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

api/app/langchain/ChatAgent.js

+1
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ Only respond with your conversational reply to the following User Message:
451451
user,
452452
model,
453453
tools: this.options.tools,
454+
functions: this.functionsAgent,
454455
options: {
455456
openAIApiKey: this.openAIApiKey
456457
}

api/app/langchain/tools/util/handleTools.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ const loadToolWithAuth = async (user, authFields, ToolConstructor, options = {})
7272
};
7373
};
7474

75-
const loadTools = async ({ user, model, tools = [], options = {} }) => {
76-
const { functions } = options;
75+
const loadTools = async ({ user, model, functions = null, tools = [], options = {} }) => {
7776
const toolConstructors = {
7877
calculator: Calculator,
7978
google: GoogleSearchAPI,

api/app/langchain/tools/util/handleTools.test.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const { validateTools, loadTools } = require('./');
2424
const PluginService = require('../../../../server/services/PluginService');
2525
const { BaseChatModel } = require('langchain/chat_models/openai');
2626
const { Calculator } = require('langchain/tools/calculator');
27-
const { availableTools, OpenAICreateImage, GoogleSearchAPI } = require('../');
27+
const { availableTools, OpenAICreateImage, GoogleSearchAPI, StructuredSD } = require('../');
2828

2929
describe('Tool Handlers', () => {
3030
let fakeUser;
@@ -174,5 +174,17 @@ describe('Tool Handlers', () => {
174174
});
175175
expect(toolFunctions).toEqual({});
176176
});
177+
it('should return the StructuredTool version when using functions', async () => {
178+
process.env.SD_WEBUI_URL = mockCredential;
179+
toolFunctions = await loadTools({
180+
user: fakeUser._id,
181+
model: BaseChatModel,
182+
tools: ['stable-diffusion'],
183+
functions: true
184+
});
185+
const structuredTool = await toolFunctions['stable-diffusion']();
186+
expect(structuredTool).toBeInstanceOf(StructuredSD);
187+
delete process.env.SD_WEBUI_URL;
188+
});
177189
});
178190
});

0 commit comments

Comments
 (0)