From b0dfc2f01914ca8fab1dc579b64577e7e975f95b Mon Sep 17 00:00:00 2001 From: tbxark Date: Tue, 31 Dec 2024 09:52:38 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/cn/CONFIG.md | 37 ++++++++++++++++++++++++++++--------- doc/en/CONFIG.md | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 18 deletions(-) diff --git a/doc/cn/CONFIG.md b/doc/cn/CONFIG.md index d230d58f..e5b5601c 100644 --- a/doc/cn/CONFIG.md +++ b/doc/cn/CONFIG.md @@ -230,6 +230,25 @@ COMMAND_DESCRIPTION_cn2en = '将对话内容翻译成英文' 如果你想将自定义命令绑定到telegram的菜单中,你可以添加如下环境变量`COMMAND_SCOPE_azure = "all_private_chats,all_group_chats,all_chat_administrators"`,这样插件就会在所有的私聊,群聊和群组中生效。 +### 生成辅助函数 +```js +function stringify(obj) { + const res = {} + for(const key of Object.keys(obj)) { + res[key] = JSON.stringify(obj[key]) + } + return JSON.stringify(res) +} + +console.log(`/setenvs ${stringify( + { + "AI_PROVIDER": "openai", + "OPENAI_CHAT_MODELS_LIST": ["gpt4", "gpt3", "gpt2", "gpt1"] + } +)}`) + +// output: /setenvs {"AI_PROVIDER":"\"openai\"","OPENAI_CHAT_MODELS_LIST":"[\"gpt4\",\"gpt3\",\"gpt2\",\"gpt1\"]"} +``` ## 模型列表 @@ -238,12 +257,12 @@ COMMAND_DESCRIPTION_cn2en = '将对话内容翻译成英文' 当前支持从URL获取模型列表的AI提供商有 `openai, workers, mistral, cohere`。只支持 json 数组的AI提供商有 `azure, gemini, anthropic`。 当支持从URL获取模型列表的AI提供商的模型列表配置项为空时候,会默认根据其 base api 自动拼接获取模型列表的URL。 -| AI提供商 | 模型列表配置项 | 默认值 | 自动拼接生成的值 | -|:----------|--------------------------------|-----------------------------------------------------------|------------------------------------------------------------------------------------------------------------------| -| openai | OPENAI_CHAT_MODELS_LIST | `` | `${OPENAI_API_BASE}/models` | -| workers | WORKERS_CHAT_MODELS_LIST | `` | `https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/models/search?task=Text%20Generation` | -| mistral | MISTRAL_CHAT_MODELS_LIST | `` | `${MISTRAL_API_BASE}/models` | -| cohere | COHERE_CHAT_MODELS_LIST | `` | `https://api.cohere.com/v1/models` | -| azure | AZURE_CHAT_MODELS_LIST | `[]` | | -| gemini | GOOGLE_COMPLETIONS_MODELS_LIST | `` | `${context.GOOGLE_API_BASE}/v1beta/models` | -| anthropic | ANTHROPIC_CHAT_MODELS_LIST | `["claude-3-5-sonnet-latest", "claude-3-5-haiku-latest"]` | | +| AI提供商 | 模型列表配置项 | 自动拼接生成的值 | +|:----------|--------------------------------|------------------------------------------------------------------------------------------------------------------| +| openai | OPENAI_CHAT_MODELS_LIST | `${OPENAI_API_BASE}/models` | +| workers | WORKERS_CHAT_MODELS_LIST | `https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/models/search?task=Text%20Generation` | +| mistral | MISTRAL_CHAT_MODELS_LIST | `${MISTRAL_API_BASE}/models` | +| cohere | COHERE_CHAT_MODELS_LIST | `https://api.cohere.com/v1/models` | +| azure | AZURE_CHAT_MODELS_LIST | `https://${context.AZURE_RESOURCE_NAME}.openai.azure.com/openai/models?api-version=${context.AZURE_API_VERSION}` | +| gemini | GOOGLE_COMPLETIONS_MODELS_LIST | `${GOOGLE_API_BASE}/v1beta/models` | +| anthropic | ANTHROPIC_CHAT_MODELS_LIST | `${ANTHROPIC_API_BASE}/models` | diff --git a/doc/en/CONFIG.md b/doc/en/CONFIG.md index 5636cd99..8c095b4b 100644 --- a/doc/en/CONFIG.md +++ b/doc/en/CONFIG.md @@ -232,6 +232,25 @@ COMMAND_DESCRIPTION_cn2en = 'Translate the conversation content into English.' If you want to bind custom commands to the menu of Telegram, you can add the following environment variable `COMMAND_SCOPE_azure = "all_private_chats,all_group_chats,all_chat_administrators"`, so that the plugin will take effect in all private chats, group chats and groups. +### Config generation function +```js +function stringify(obj) { + const res = {} + for(const key of Object.keys(obj)) { + res[key] = JSON.stringify(obj[key]) + } + return JSON.stringify(res) +} + +console.log(`/setenvs ${stringify( + { + "AI_PROVIDER": "openai", + "OPENAI_CHAT_MODELS_LIST": ["gpt4", "gpt3", "gpt2", "gpt1"] + } +)}`) + +// output: /setenvs {"AI_PROVIDER":"\"openai\"","OPENAI_CHAT_MODELS_LIST":"[\"gpt4\",\"gpt3\",\"gpt2\",\"gpt1\"]"} +``` ## Model List @@ -240,12 +259,12 @@ The supported configuration items for the models list are of type URL or json ar Current AI providers that support fetching the model list from a URL are `openai, workers, mistral, cohere`. AI providers that only support json arrays are `azure, gemini, anthropic`. When the model list configuration is empty for an AI provider that supports fetching the model list from a URL, the URL for fetching the model list will be automatically spliced according to its base api by default. -| AI provider | Model List Configuration Key | Default value | Automatically generated value | -|:------------|--------------------------------|-----------------------------------------------------------|------------------------------------------------------------------------------------------------------------------| -| openai | OPENAI_CHAT_MODELS_LIST | `` | `${OPENAI_API_BASE}/models` | -| workers | WORKERS_CHAT_MODELS_LIST | `` | `https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/models/search?task=Text%20Generation` | -| mistral | MISTRAL_CHAT_MODELS_LIST | `` | `${MISTRAL_API_BASE}/models` | -| cohere | COHERE_CHAT_MODELS_LIST | `` | `https://api.cohere.com/v1/models` | -| azure | AZURE_CHAT_MODELS_LIST | `[]` | | -| gemini | GOOGLE_COMPLETIONS_MODELS_LIST | `` | `${context.GOOGLE_API_BASE}/v1beta/models` | -| anthropic | ANTHROPIC_CHAT_MODELS_LIST | `["claude-3-5-sonnet-latest", "claude-3-5-haiku-latest"]` | | +| AI provider | Model List Configuration Key | Automatically generated value | +|:------------|--------------------------------|------------------------------------------------------------------------------------------------------------------| +| openai | OPENAI_CHAT_MODELS_LIST | `${OPENAI_API_BASE}/models` | +| workers | WORKERS_CHAT_MODELS_LIST | `https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/models/search?task=Text%20Generation` | +| mistral | MISTRAL_CHAT_MODELS_LIST | `${MISTRAL_API_BASE}/models` | +| cohere | COHERE_CHAT_MODELS_LIST | `https://api.cohere.com/v1/models` | +| azure | AZURE_CHAT_MODELS_LIST | `https://${context.AZURE_RESOURCE_NAME}.openai.azure.com/openai/models?api-version=${context.AZURE_API_VERSION}` | +| gemini | GOOGLE_COMPLETIONS_MODELS_LIST | `${GOOGLE_API_BASE}/v1beta/models` | +| anthropic | ANTHROPIC_CHAT_MODELS_LIST | `${ANTHROPIC_API_BASE}/models` |