diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts index 30664aebcc..341a17712a 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/assistant/create.operation.ts @@ -133,6 +133,24 @@ const properties: INodeProperties[] = [ type: 'collection', default: {}, options: [ + { + displayName: 'Output Randomness (Temperature)', + name: 'temperature', + default: 1, + typeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 }, + description: + 'Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive. We generally recommend altering this or temperature but not both.', + type: 'number', + }, + { + displayName: 'Output Randomness (Top P)', + name: 'topP', + default: 1, + typeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 }, + description: + 'An alternative to sampling with temperature, controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.', + type: 'number', + }, { displayName: 'Fail if Assistant Already Exists', name: 'failIfExists', @@ -176,7 +194,7 @@ export async function execute(this: IExecuteFunctions, i: number): Promise ({ + role: message._getType() === 'ai' ? 'assistant' : 'user', + content: message.content.toString(), +}); export async function execute(this: IExecuteFunctions, i: number): Promise { const credentials = await this.getCredentials('openAiApi'); @@ -182,11 +196,47 @@ export async function execute(this: IExecuteFunctions, i: number): Promise tool.type !== 'code_interpreter'); } - if (knowledgeRetrieval && !tools.find((tool) => tool.type === 'retrieval')) { + if (knowledgeRetrieval && !tools.find((tool) => tool.type === 'file_search')) { tools.push({ - type: 'retrieval', + type: 'file_search', }); } - if (knowledgeRetrieval === false && tools.find((tool) => tool.type === 'retrieval')) { - tools = tools.filter((tool) => tool.type !== 'retrieval'); + if (knowledgeRetrieval === false && tools.find((tool) => tool.type === 'file_search')) { + tools = tools.filter((tool) => tool.type !== 'file_search'); } if (removeCustomTools) { @@ -185,7 +226,7 @@ export async function execute(this: IExecuteFunctions, i: number): Promise { const { data, has_more, last_id } = await apiRequest.call(this, 'GET', '/assistants', { headers: { - 'OpenAI-Beta': 'assistants=v1', + 'OpenAI-Beta': 'assistants=v2', }, qs: { limit: 100, diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/test/OpenAi.node.test.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/test/OpenAi.node.test.ts index 87e9754551..c6b7c9ddaa 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/test/OpenAi.node.test.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/test/OpenAi.node.test.ts @@ -84,13 +84,24 @@ describe('OpenAi, Assistant resource', () => { expect(transport.apiRequest).toHaveBeenCalledWith('POST', '/assistants', { body: { description: 'description', - file_ids: [], instructions: 'some instructions', model: 'gpt-model', name: 'name', - tools: [{ type: 'code_interpreter' }, { type: 'retrieval' }], + tool_resources: { + code_interpreter: { + file_ids: [], + }, + file_search: { + vector_stores: [ + { + file_ids: [], + }, + ], + }, + }, + tools: [{ type: 'code_interpreter' }, { type: 'file_search' }], }, - headers: { 'OpenAI-Beta': 'assistants=v1' }, + headers: { 'OpenAI-Beta': 'assistants=v2' }, }); }); @@ -124,7 +135,7 @@ describe('OpenAi, Assistant resource', () => { ); expect(transport.apiRequest).toHaveBeenCalledWith('DELETE', '/assistants/assistant-id', { - headers: { 'OpenAI-Beta': 'assistants=v1' }, + headers: { 'OpenAI-Beta': 'assistants=v2' }, }); }); @@ -185,17 +196,28 @@ describe('OpenAi, Assistant resource', () => { expect(transport.apiRequest).toHaveBeenCalledTimes(2); expect(transport.apiRequest).toHaveBeenCalledWith('GET', '/assistants/assistant-id', { - headers: { 'OpenAI-Beta': 'assistants=v1' }, + headers: { 'OpenAI-Beta': 'assistants=v2' }, }); expect(transport.apiRequest).toHaveBeenCalledWith('POST', '/assistants/assistant-id', { body: { - file_ids: [], instructions: 'some instructions', model: 'gpt-model', name: 'name', - tools: [{ type: 'existing_tool' }, { type: 'code_interpreter' }, { type: 'retrieval' }], + tool_resources: { + code_interpreter: { + file_ids: [], + }, + file_search: { + vector_stores: [ + { + file_ids: [], + }, + ], + }, + }, + tools: [{ type: 'existing_tool' }, { type: 'code_interpreter' }, { type: 'file_search' }], }, - headers: { 'OpenAI-Beta': 'assistants=v1' }, + headers: { 'OpenAI-Beta': 'assistants=v2' }, }); }); });