n8n-io / n8n

Free and source-available fair-code licensed workflow automation tool. Easily automate tasks across different services.
https://n8n.io
Other
47.5k stars 7.15k forks source link

Bug: OpenAi Assistant usage removes function #8640

Closed demsr closed 7 months ago

demsr commented 8 months ago

Bug Description

Using the "OpenAi Assistant" Block with an existing assistant which has a custom function has the result of this function being deleted/removed.

To Reproduce

  1. Create Assistant with a function in OpenAi Playground
  2. Use Assistant with n8n Block
  3. Refresh Assistant in OpenAi
  4. Function is deleted

Expected behavior

Using the n8n block should not alter the assistant

Operating System

Ubuntu 22.04

n8n Version

1.27.2

Node.js Version

18.19.0

Database

SQLite (default)

Execution mode

main (default)

Joffcom commented 8 months ago

Hey @demsr,

Thanks for the report, I have followed the steps you have provided and I have not been able to reproduce this. When you say "Use Assistant with n8n Block" what do you mean?

For my test I created a new Assistant and used the get_weather function, I then added the OpenAI node and selected Assistant > Message an Assistant and sent a message, after that I refreshed the Assistants in OpenAI and check it and the function is still there.

I have just quickly checked the code for the OpenAI node and we technically lack the code to delete a function from an Assitant but we can delete the entire assistant so it sounds like maybe something is happening outside of n8n.

demsr commented 8 months ago

Hey @Joffcom,

thanks for the reply. My setup looks like the following, and the "function" is just gone after i run the workflow and refresh the openai assistant page...

image image

image

demsr commented 8 months ago

After updating to prerelease version 1.29.0 the function is no longer removed. But it also isn't running my function or any other function like "get weather" at all... just responding with text...

Joffcom commented 8 months ago

How are you calling the function? Have you tested the same prompt in the playground and in n8n?

demsr commented 8 months ago

This is my playground response: image

and this is the n8n response: image

But the important part is, the playground response contains a "function call"

get_weather({ "location": "San Francisco, CA", "unit": "c" }))

which is returned by the openai api to call some other function on my end

Joffcom commented 8 months ago

Hey @demsr,

That looks right to me as you don't have a tool in the output to process the function. You can find an example on how to use the assistant here: https://n8n.io/workflows/2098-chat-with-openai-assistant-by-adding-a-memory/

pausanchez commented 8 months ago

Hey @Joffcom

Seems that the original function in the Assistant is "updated", once the workflow is triggered.

Here is the original function in the Open AI playground before the workflow in n8n is triggered

Screenshot 2024-02-25 at 12 48 04

And here is the same function after the workflow in n8n is triggered

Screenshot 2024-02-25 at 12 46 20

Here is the workflow used:

Screenshot 2024-02-25 at 12 49 26

Hope this helps!

Joffcom commented 8 months ago

Can you share the json for the workflow? We should lack the code to make the change so I suspect OpenAI is changing it to match

pausanchez commented 8 months ago

Hi @Joffcom sure here it is:

{ "name": "Chat with OpenAI Assistant (by adding a memory)", "nodes": [ { "parameters": { "assistantId": "asst_w3oOSRZQoUsUTbxsrTCW4SlG", "text": "Which is the weather in Berlin?", "options": {} }, "id": "087ae6e2-b333-4a30-9010-c78050203961", "name": "OpenAI Assistant", "type": "@n8n/n8n-nodes-langchain.openAiAssistant", "position": [ 1140, 240 ], "typeVersion": 1, "credentials": { "openAiApi": { "id": "johJrN2VFbKtFVqp", "name": "OpenAi account" } } }, { "parameters": { "content": "## Try me out\n1. In the OpenAI Assistant node, make sure your OpenAI credentials are set and choose an assistant to use (you'll need to create one if you don't have one already)\n2. Click the 'Chat' button below\n\n - In the first message, tell the AI what your name is\n - In a second message, ask the AI what your name is", "height": 300.48941882630095 }, "id": "3b72a676-aaa2-472a-b055-1fed03f52101", "name": "Sticky Note4", "type": "n8n-nodes-base.stickyNote", "position": [ 280, 420 ], "typeVersion": 1 }, { "parameters": { "name": "get_current_weather", "description": "Get the current weather", "workflowId": "E8bUghl4j3Tnk4GV" }, "id": "8996f5f7-5be5-4e68-87ad-03822ff9b87a", "name": "Custom n8n Workflow Tool", "type": "@n8n/n8n-nodes-langchain.toolWorkflow", "typeVersion": 1, "position": [ 1060, 480 ] }, { "parameters": {}, "id": "192e7948-9bf0-4298-81b7-f51dc57bc843", "name": "Execute Workflow Trigger", "type": "n8n-nodes-base.executeWorkflowTrigger", "typeVersion": 1, "position": [ 1180, 700 ] }, { "parameters": { "jsCode": "return {\n 'response': {\"temperature\":\"30 degrees celsius\"}\n}" }, "id": "7238d43a-f4bb-494d-a0fe-9212f892dfb2", "name": "Code", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1420, 700 ] }, { "parameters": { "httpMethod": "POST", "path": "17df09fd-1835-4fe5-b20f-074b9ccac653", "responseMode": "responseNode", "options": {} }, "id": "a31409a5-766f-4ac4-afe8-d4c38cdc5cde", "name": "Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 1.1, "position": [ 880, 260 ], "webhookId": "17df09fd-1835-4fe5-b20f-074b9ccac653" }, { "parameters": { "options": {} }, "id": "944542cb-c867-48a7-a4a7-75a1fc717a5d", "name": "Respond to Webhook", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1, "position": [ 1520, 240 ] } ], "pinData": { "Webhook": [ { "json": {} } ] }, "connections": { "OpenAI Assistant": { "main": [ [ { "node": "Respond to Webhook", "type": "main", "index": 0 } ] ] }, "Custom n8n Workflow Tool": { "ai_tool": [ [ { "node": "OpenAI Assistant", "type": "ai_tool", "index": 0 } ] ] }, "Execute Workflow Trigger": { "main": [ [ { "node": "Code", "type": "main", "index": 0 } ] ] }, "Webhook": { "main": [ [ { "node": "OpenAI Assistant", "type": "main", "index": 0 } ] ] } }, "active": true, "settings": { "saveDataSuccessExecution": "all", "saveManualExecutions": false, "callerPolicy": "workflowsFromSameOwner", "executionTimeout": -1, "executionOrder": "v0" }, "versionId": "d732bd5e-1a93-43d5-b81d-50ce535a2754", "meta": { "templateId": "2098", "templateCredsSetupCompleted": true, "instanceId": "31bb2c205aa65c1befb6f5a8902d0d96a7d208528cbe91e9e075b4ef47dc875e" }, "id": "E8bUghl4j3Tnk4GV", "tags": [] }

pausanchez commented 8 months ago

Could this be related? https://platform.openai.com/docs/api-reference/assistants/modifyAssistant

Screenshot 2024-02-25 at 14 05 04

Joffcom commented 8 months ago

Hey @pausanchez,

That could be it, Looking at the updated node again and it looks lime we might actually only use code_interpreter and retrieval rather than functions. I have created NODE-1171 as the internal dev ticket to look into this further.

janober commented 7 months ago

Fix got released with n8n@1.34.0