From 895543355fd054b3abd2aa348948da64be5da0c2 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Wed, 20 Mar 2024 21:06:30 +0900 Subject: [PATCH] Add support for JSON values in additionalParams --- src/lang/en.ts | 2 +- src/ts/process/request.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lang/en.ts b/src/lang/en.ts index a2fadca7..831b6010 100644 --- a/src/lang/en.ts +++ b/src/lang/en.ts @@ -117,7 +117,7 @@ export const languageEnglish = { requestretrys: "This option is used to set the number of request retrys when request fails.", emotionPrompt: "This option is used to set the prompt that is used to detect emotion. if it is blank, it will use the default prompt.", removePunctuationHypa: "If enabled, it will remove punctuation before executing HypaMemory.", - additionalParams: "Additional parameters that would be added to the request body. if you want to exclude some parameters, you can put `{{none}}` to the value. if you want to add a header instead of body, you can put `header::` in front of the key like `header::Authorization`.", + additionalParams: "Additional parameters that would be added to the request body. if you want to exclude some parameters, you can put `{{none}}` to the value. if you want to add a header instead of body, you can put `header::` in front of the key like `header::Authorization`. if you want value as json, you can put `json::` in front of the value like `json::{\"key\":\"value\"}`. otherwise, type of the value would be determined automatically.", }, setup: { chooseProvider: "Choose AI Provider", diff --git a/src/ts/process/request.ts b/src/ts/process/request.ts index beca2cd1..6e3d1dc6 100644 --- a/src/ts/process/request.ts +++ b/src/ts/process/request.ts @@ -631,10 +631,13 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model' key = key.replace('header::', '') headers[key] = value } + else if(value.startsWith('json::')){ + value = value.replace('json::', '') + try { + body[key] = JSON.parse(value) + } catch (error) {} + } else if(isNaN(parseFloat(value))){ - if(value.startsWith('"') && value.endsWith('"')){ - value = value.slice(1, -1) - } body[key] = value } else{