From e2f45deb4b7255b5e04296692fb51ce8965b0945 Mon Sep 17 00:00:00 2001 From: Pablo Reyes Date: Mon, 28 Oct 2024 10:40:56 +0100 Subject: [PATCH 1/6] Include "assistant" as a valid role for the conversation history --- .../chat/isValidConversationHistory.ts | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts b/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts index 24c1d79..51b529e 100644 --- a/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts +++ b/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts @@ -1,31 +1,28 @@ export const isValidConversationHistory = (history: any) => { if (!Array.isArray(history)) { return { - success: false, - error: 'payload.conversationHistory is not an array', - }; - } - - if (history.some((item: any) => { - if (typeof item !== 'object' || item === null) { - return true; - } + success: false, + error: "payload.conversationHistory is not an array", + }; + } - if ( - (item.role !== 'user' && item.role !== 'ai' && item.role !== 'system') || - typeof item.message !== 'string' - ) { - return true; - } - })) { - return { - success: false, - error: 'payload.conversationHistory contains invalid items', - }; + if (history.some((item: any) => { + if (typeof item !== "object" || item === null) { + return true; } + if (!["user", "ai", "system", "assistant"].includes(item.role) || typeof item.message !== "string") { + return true; + } + })) { return { - success: true, - history, + success: false, + error: "payload.conversationHistory contains invalid items" }; + } + + return { + success: true, + history + }; }; \ No newline at end of file From 41c790cf1e0739fcf774dbef9ea25e99a1b5d4d4 Mon Sep 17 00:00:00 2001 From: Pablo Reyes Date: Mon, 28 Oct 2024 10:52:03 +0100 Subject: [PATCH 2/6] Revert "Include "assistant" as a valid role for the conversation history" This reverts commit e2f45deb4b7255b5e04296692fb51ce8965b0945. --- .../chat/isValidConversationHistory.ts | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts b/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts index 51b529e..24c1d79 100644 --- a/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts +++ b/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts @@ -1,28 +1,31 @@ export const isValidConversationHistory = (history: any) => { if (!Array.isArray(history)) { return { - success: false, - error: "payload.conversationHistory is not an array", - }; - } - - if (history.some((item: any) => { - if (typeof item !== "object" || item === null) { - return true; + success: false, + error: 'payload.conversationHistory is not an array', + }; } - if (!["user", "ai", "system", "assistant"].includes(item.role) || typeof item.message !== "string") { - return true; - } + if (history.some((item: any) => { + if (typeof item !== 'object' || item === null) { + return true; + } + + if ( + (item.role !== 'user' && item.role !== 'ai' && item.role !== 'system') || + typeof item.message !== 'string' + ) { + return true; + } })) { + return { + success: false, + error: 'payload.conversationHistory contains invalid items', + }; + } + return { - success: false, - error: "payload.conversationHistory contains invalid items" + success: true, + history, }; - } - - return { - success: true, - history - }; }; \ No newline at end of file From d35805c39c73dbd95639c63cf735fdde364d6bab Mon Sep 17 00:00:00 2001 From: Pablo Reyes Date: Mon, 28 Oct 2024 10:56:29 +0100 Subject: [PATCH 3/6] Include "assistant" as a valid role for the conversation history --- .../express/validators/chat/isValidConversationHistory.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts b/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts index 24c1d79..87b222f 100644 --- a/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts +++ b/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts @@ -11,10 +11,7 @@ export const isValidConversationHistory = (history: any) => { return true; } - if ( - (item.role !== 'user' && item.role !== 'ai' && item.role !== 'system') || - typeof item.message !== 'string' - ) { + if (['user', 'ai', 'system', 'assistant'].includes(item.role) || typeof item.message !== 'string') { return true; } })) { From 150dd2f1b7a9497a3445a702d4b6b27c86c84746 Mon Sep 17 00:00:00 2001 From: Pablo Reyes Date: Tue, 29 Oct 2024 14:43:33 +0100 Subject: [PATCH 4/6] Fix typo with --api-key option. Should be --apiKey --- packages/node/server/src/serve/displayHelp.ts | 2 +- pipeline/npm/server/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/node/server/src/serve/displayHelp.ts b/packages/node/server/src/serve/displayHelp.ts index a329ad7..665e784 100644 --- a/packages/node/server/src/serve/displayHelp.ts +++ b/packages/node/server/src/serve/displayHelp.ts @@ -12,7 +12,7 @@ export const displayHelp = () => { ' Only OpenAPI is supported at the moment'); log(''); log('Optional:'); - log(' --api-key The API key to use for the AI backend\n' + + log(' --apiKey The API key to use for the AI backend\n' + ' Default: Read from environment variable (e.g. OPENAI_API_KEY)\n'); log(' --port [port] Port to use for HTTP server - Default: Random value between 8000 and 8999'); log(' --cors Enable CORS for the specified origin - Default: "*"'); diff --git a/pipeline/npm/server/README.md b/pipeline/npm/server/README.md index 509c2a4..f671e40 100644 --- a/pipeline/npm/server/README.md +++ b/pipeline/npm/server/README.md @@ -40,7 +40,7 @@ Required: Only OpenAPI is supported at the moment Optional: - --api-key The API key to use for the AI backend + --apiKey The API key to use for the AI backend Default: Read from environment variable (e.g. OPENAI_API_KEY) --port [port] Port to use for HTTP server - Default: Random value between 8000 and 8999 From 7bd63daa34d7a0be27d8e6f54983bbf064d832b6 Mon Sep 17 00:00:00 2001 From: Pablo Reyes Date: Tue, 29 Oct 2024 14:44:37 +0100 Subject: [PATCH 5/6] Fix Role "assistant" not recognized in chat history --- .../src/express/validators/chat/isValidConversationHistory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts b/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts index 87b222f..0246f63 100644 --- a/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts +++ b/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts @@ -11,7 +11,7 @@ export const isValidConversationHistory = (history: any) => { return true; } - if (['user', 'ai', 'system', 'assistant'].includes(item.role) || typeof item.message !== 'string') { + if (!['user', 'ai', 'system', 'assistant'].includes(item.role) || typeof item.message !== 'string') { return true; } })) { From 59adff85c0eea0547ffd14721903c94a2b8a0526 Mon Sep 17 00:00:00 2001 From: Pablo Reyes Date: Tue, 29 Oct 2024 14:52:51 +0100 Subject: [PATCH 6/6] Typos. "OpenAPI" should be "OpenAI" --- packages/node/server/src/serve/displayHelp.ts | 4 ++-- pipeline/npm/server/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/node/server/src/serve/displayHelp.ts b/packages/node/server/src/serve/displayHelp.ts index 665e784..b2a484b 100644 --- a/packages/node/server/src/serve/displayHelp.ts +++ b/packages/node/server/src/serve/displayHelp.ts @@ -8,8 +8,8 @@ export const displayHelp = () => { log(' @nlbridge/server [params]'); log(''); log('Required:'); - log(' --api The AI backend to use\n' + - ' Only OpenAPI is supported at the moment'); + log(' --api The AI backend to use\n' + + ' Only OpenAI is supported at the moment'); log(''); log('Optional:'); log(' --apiKey The API key to use for the AI backend\n' + diff --git a/pipeline/npm/server/README.md b/pipeline/npm/server/README.md index f671e40..052c22b 100644 --- a/pipeline/npm/server/README.md +++ b/pipeline/npm/server/README.md @@ -36,8 +36,8 @@ Usage: @nlbridge/server [params] Required: - --api The AI backend to use - Only OpenAPI is supported at the moment + --api The AI backend to use + Only OpenAI is supported at the moment Optional: --apiKey The API key to use for the AI backend