From 9d714ee326b8fc028cb753f28f52deb71d65ba0f Mon Sep 17 00:00:00 2001 From: TBXark Date: Sat, 7 Oct 2023 17:21:29 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E5=A4=8DAI=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=90=8D=E5=AD=97=E4=B8=BACF=E9=BB=98=E8=AE=A4=E5=90=8D?= =?UTF-8?q?=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 12 ++++++------ dist/timestamp | 2 +- doc/CONFIG.md | 2 +- src/env.js | 4 ++-- src/workers-ai.js | 6 +++--- wrangler-example.toml | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index a54f3807..f385c236 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "92f35a1", "timestamp": 1696670020} +{"sha": "0ab2830", "timestamp": 1696670444} diff --git a/dist/index.js b/dist/index.js index bd435cf6..2517ddec 100644 --- a/dist/index.js +++ b/dist/index.js @@ -41,9 +41,9 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1696670020, + BUILD_TIMESTAMP: 1696670444, // 当前版本 commit id - BUILD_VERSION: "92f35a1", + BUILD_VERSION: "0ab2830", I18N: null, LANGUAGE: "zh-cn", // 使用流模式 @@ -72,7 +72,7 @@ var CONST = { }; var DATABASE = null; var API_GUARD = null; -var AI_LLM = null; +var AI = null; var ENV_VALUE_TYPE = { API_KEY: [], AZURE_API_KEY: "string", @@ -81,7 +81,7 @@ var ENV_VALUE_TYPE = { function initEnv(env, i18n2) { DATABASE = env.DATABASE; API_GUARD = env.API_GUARD; - AI_LLM = env.AI_LLM; + AI = env.AI; for (const key in ENV) { if (env[key]) { switch (ENV_VALUE_TYPE[key] ? typeof ENV_VALUE_TYPE[key] : typeof ENV[key]) { @@ -1341,10 +1341,10 @@ var Ai = class { // src/workers-ai.js function isWorkersAIEnable(context) { - return AI_LLM !== null; + return AI !== null; } async function requestCompletionsFromWorkersAI(message, history, context, onStream) { - const ai = new Ai(AI_LLM); + const ai = new Ai(AI); const model = ENV.WORKERS_AI_MODEL; const request = { messages: [...history || [], { role: "user", content: message }] diff --git a/dist/timestamp b/dist/timestamp index b44038ee..5a60800f 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1696670020 +1696670444 diff --git a/doc/CONFIG.md b/doc/CONFIG.md index c0ac596f..69bf3e4f 100644 --- a/doc/CONFIG.md +++ b/doc/CONFIG.md @@ -76,7 +76,7 @@ ### Workers AI 配置 -在 `项目主页-Settings-Variables-AI Bindings` 添加 `AI_LLM = Workers AI Catalog` +在 `项目主页-Settings-Variables-AI Bindings` 添加 `AI = Workers AI Catalog` ### 支持命令 diff --git a/src/env.js b/src/env.js index 630664f8..133bfb2d 100644 --- a/src/env.js +++ b/src/env.js @@ -125,7 +125,7 @@ export const CONST = { export let DATABASE = null; export let API_GUARD = null; -export let AI_LLM = null; +export let AI = null; const ENV_VALUE_TYPE = { API_KEY: [], @@ -146,7 +146,7 @@ const ENV_VALUE_TYPE = { export function initEnv(env, i18n) { DATABASE = env.DATABASE; API_GUARD = env.API_GUARD; - AI_LLM = env.AI_LLM; + AI = env.AI; for (const key in ENV) { if (env[key]) { switch (ENV_VALUE_TYPE[key]?typeof ENV_VALUE_TYPE[key]:(typeof ENV[key])) { diff --git a/src/workers-ai.js b/src/workers-ai.js index ad2caa93..b029b013 100644 --- a/src/workers-ai.js +++ b/src/workers-ai.js @@ -1,4 +1,4 @@ -import {ENV, AI_LLM} from './env.js'; +import {ENV, AI} from './env.js'; import {Ai} from './vendors/cloudflare-ai.js'; @@ -7,7 +7,7 @@ import {Ai} from './vendors/cloudflare-ai.js'; * @return {boolean} */ export function isWorkersAIEnable(context) { - return AI_LLM !== null; + return AI !== null; // return ENV.WORKERS_AI_MODEL !== null; } @@ -22,7 +22,7 @@ export function isWorkersAIEnable(context) { * @return {Promise} */ export async function requestCompletionsFromWorkersAI(message, history, context, onStream) { - const ai = new Ai(AI_LLM); + const ai = new Ai(AI); const model = ENV.WORKERS_AI_MODEL; const request = { messages: [...history || [], {role: 'user', content: message}], diff --git a/wrangler-example.toml b/wrangler-example.toml index a8e67953..f9493879 100644 --- a/wrangler-example.toml +++ b/wrangler-example.toml @@ -13,7 +13,7 @@ kv_namespaces = [ # 如果使用openai则注释这一段 #[ai] -#binding = "AI_LLM" +#binding = "AI" [vars]