diff --git a/imports/workflows/ollama-chat-cleanup.json b/imports/workflows/ollama-chat-cleanup.json index 5c59c89..64cf177 100644 --- a/imports/workflows/ollama-chat-cleanup.json +++ b/imports/workflows/ollama-chat-cleanup.json @@ -27,8 +27,8 @@ "position": [300, 300], "credentials": { "postgres": { - "id": "SETUP_REQUIRED", - "name": "n8n PostgreSQL" + "id": "pnmeNZ3ONDWrQP8M", + "name": "Postgres account" } } }, diff --git a/imports/workflows/ollama-chat-delete.json b/imports/workflows/ollama-chat-delete.json index 82f9b50..6aa7ef1 100644 --- a/imports/workflows/ollama-chat-delete.json +++ b/imports/workflows/ollama-chat-delete.json @@ -19,10 +19,8 @@ { "parameters": { "operation": "executeQuery", - "query": "DELETE FROM chat_sessions WHERE session_id = $1 RETURNING session_id", - "additionalFields": { - "queryParams": "={{ JSON.stringify([$json.body.session_id]) }}" - } + "query": "=DELETE FROM chat_sessions WHERE session_id = '{{ $json.body.session_id }}' RETURNING session_id", + "additionalFields": {} }, "id": "node-pg-004", "name": "Delete Session", @@ -31,8 +29,8 @@ "position": [300, 300], "credentials": { "postgres": { - "id": "SETUP_REQUIRED", - "name": "n8n PostgreSQL" + "id": "pnmeNZ3ONDWrQP8M", + "name": "Postgres account" } } }, diff --git a/imports/workflows/ollama-chatbot.json b/imports/workflows/ollama-chatbot.json index 64dfa38..486ad43 100644 --- a/imports/workflows/ollama-chatbot.json +++ b/imports/workflows/ollama-chatbot.json @@ -29,10 +29,8 @@ { "parameters": { "operation": "executeQuery", - "query": "SELECT messages FROM chat_sessions WHERE session_id = $1", - "additionalFields": { - "queryParams": "={{ JSON.stringify([$json.session_id]) }}" - } + "query": "=WITH ensure AS (INSERT INTO chat_sessions (session_id, messages) VALUES ('{{ $json.session_id }}', '[]') ON CONFLICT (session_id) DO NOTHING) SELECT COALESCE(messages, '[]'::jsonb) AS messages FROM chat_sessions WHERE session_id = '{{ $json.session_id }}'", + "additionalFields": {} }, "id": "node-pg-001", "name": "Load History", @@ -41,8 +39,8 @@ "position": [500, 300], "credentials": { "postgres": { - "id": "SETUP_REQUIRED", - "name": "n8n PostgreSQL" + "id": "pnmeNZ3ONDWrQP8M", + "name": "Postgres account" } } }, @@ -74,7 +72,7 @@ }, { "parameters": { - "jsCode": "const build = $('Build Messages').first().json;\nconst resp = $input.first().json;\nconst answer = resp.message.content;\nconst updatedMessages = [...build.messages, { role: 'assistant', content: answer }];\nreturn [{ json: { session_id: build.session_id, messages: updatedMessages, answer, model: resp.model } }];" + "jsCode": "const build = $('Build Messages').first().json;\nconst resp = $input.first().json;\nconst answer = resp.message.content;\nconst updatedMessages = [...build.messages, { role: 'assistant', content: answer }];\nconst m = JSON.stringify(updatedMessages).replace(/'/g, \"''\");\nconst upsert_query = `INSERT INTO chat_sessions (session_id, messages, updated_at) VALUES ('${build.session_id}', '${m}'::jsonb, NOW()) ON CONFLICT (session_id) DO UPDATE SET messages = '${m}'::jsonb, updated_at = NOW()`;\nreturn [{ json: { session_id: build.session_id, answer, model: resp.model, upsert_query } }];" }, "id": "node-cd-003", "name": "Append Response", @@ -85,10 +83,8 @@ { "parameters": { "operation": "executeQuery", - "query": "INSERT INTO chat_sessions (session_id, messages, updated_at) VALUES ($1, $2::jsonb, NOW()) ON CONFLICT (session_id) DO UPDATE SET messages = $2::jsonb, updated_at = NOW()", - "additionalFields": { - "queryParams": "={{ JSON.stringify([$json.session_id, JSON.stringify($json.messages)]) }}" - } + "query": "={{ $json.upsert_query }}", + "additionalFields": {} }, "id": "node-pg-002", "name": "Save History", @@ -97,8 +93,8 @@ "position": [1300, 300], "credentials": { "postgres": { - "id": "SETUP_REQUIRED", - "name": "n8n PostgreSQL" + "id": "pnmeNZ3ONDWrQP8M", + "name": "Postgres account" } } },