Merge remote-tracking branch 'upstream/main'

This commit is contained in:
Hk-Gosuto
2024-07-21 09:36:44 +00:00
66 changed files with 8668 additions and 3792 deletions

View File

@@ -1,6 +1,7 @@
import {
ApiPath,
DEFAULT_API_HOST,
GoogleSafetySettingsThreshold,
ServiceProvider,
StoreKey,
} from "../constant";
@@ -12,10 +13,33 @@ import { DEFAULT_CONFIG } from "./config";
let fetchState = 0; // 0 not fetch, 1 fetching, 2 done
const DEFAULT_OPENAI_URL =
getClientConfig()?.buildMode === "export"
? DEFAULT_API_HOST + "/api/proxy/openai"
: ApiPath.OpenAI;
const isApp = getClientConfig()?.buildMode === "export";
const DEFAULT_OPENAI_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/openai"
: ApiPath.OpenAI;
const DEFAULT_GOOGLE_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/google"
: ApiPath.Google;
const DEFAULT_ANTHROPIC_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/anthropic"
: ApiPath.Anthropic;
const DEFAULT_BAIDU_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/baidu"
: ApiPath.Baidu;
const DEFAULT_BYTEDANCE_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/bytedance"
: ApiPath.ByteDance;
const DEFAULT_ALIBABA_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/alibaba"
: ApiPath.Alibaba;
console.log("DEFAULT_ANTHROPIC_URL", DEFAULT_ANTHROPIC_URL);
const DEFAULT_ACCESS_STATE = {
accessCode: "",
@@ -33,14 +57,28 @@ const DEFAULT_ACCESS_STATE = {
azureApiVersion: "2024-02-15-preview",
// google ai studio
googleUrl: "",
googleUrl: DEFAULT_GOOGLE_URL,
googleApiKey: "",
googleApiVersion: "v1",
googleSafetySettings: GoogleSafetySettingsThreshold.BLOCK_ONLY_HIGH,
// anthropic
anthropicUrl: DEFAULT_ANTHROPIC_URL,
anthropicApiKey: "",
anthropicApiVersion: "2023-06-01",
anthropicUrl: "",
// baidu
baiduUrl: DEFAULT_BAIDU_URL,
baiduApiKey: "",
baiduSecretKey: "",
// bytedance
bytedanceUrl: DEFAULT_BYTEDANCE_URL,
bytedanceApiKey: "",
// alibaba
alibabaUrl: DEFAULT_ALIBABA_URL,
alibabaApiKey: "",
// server config
needCode: true,
@@ -102,6 +140,18 @@ export const useAccessStore = createPersistStore(
return ensure(get(), ["anthropicApiKey"]);
},
isValidBaidu() {
return ensure(get(), ["baiduApiKey", "baiduSecretKey"]);
},
isValidByteDance() {
return ensure(get(), ["bytedanceApiKey"]);
},
isValidAlibaba() {
return ensure(get(), ["alibabaApiKey"]);
},
isAuthorized() {
this.fetch();
@@ -111,6 +161,9 @@ export const useAccessStore = createPersistStore(
this.isValidAzure() ||
this.isValidGoogle() ||
this.isValidAnthropic() ||
this.isValidBaidu() ||
this.isValidByteDance() ||
this.isValidAlibaba() ||
!this.enabledAccessControl() ||
(this.enabledAccessControl() && ensure(get(), ["accessCode"]))
);

View File

@@ -1,4 +1,4 @@
import { trimTopic, getMessageTextContent, getClientApi } from "../utils";
import { trimTopic, getMessageTextContent } from "../utils";
import Locale, { getLang } from "../locales";
import { showToast } from "../components/ui-lib";
@@ -9,13 +9,17 @@ import {
DEFAULT_MODELS,
DEFAULT_SYSTEM_TEMPLATE,
KnowledgeCutOffDate,
ModelProvider,
StoreKey,
SUMMARIZE_MODEL,
GEMINI_SUMMARIZE_MODEL,
MYFILES_BROWSER_TOOLS_SYSTEM_PROMPT,
} from "../constant";
import { ClientApi, RequestMessage, MultimodalContent } from "../client/api";
import { getClientApi } from "../client/api";
import type {
ClientApi,
RequestMessage,
MultimodalContent,
} from "../client/api";
import { ChatControllerPool } from "../client/controller";
import { prettyObject } from "../utils/format";
import { estimateTokenLength } from "../utils/token";
@@ -28,7 +32,6 @@ export interface ChatToolMessage {
}
import { createPersistStore } from "../utils/store";
import { FileInfo } from "../client/platforms/utils";
import { identifyDefaultClaudeModel } from "../utils/checkers";
import { collectModelsWithDefaultModel } from "../utils/model";
import { useAccessStore } from "./access";
@@ -101,13 +104,7 @@ function createEmptySession(): ChatSession {
}
function getSummarizeModel(currentModel: string) {
// if the current model does not exist in the default model
// example azure services cannot use SUMMARIZE_MODEL
const model = DEFAULT_MODELS.find((m) => m.name === currentModel);
console.log("model", model);
if (!model) return currentModel;
if (model.provider.providerType === "google") return GEMINI_SUMMARIZE_MODEL;
// if it is using gpt-* models, force to use 3.5 to summarize
// if it is using gpt-* models, force to use 4o-mini to summarize
if (currentModel.startsWith("gpt")) {
const configStore = useAppConfig.getState();
const accessStore = useAccessStore.getState();
@@ -374,7 +371,7 @@ export const useChatStore = createPersistStore(
model: modelConfig.model,
toolMessages: [],
});
var api: ClientApi = getClientApi(modelConfig.model);
const api: ClientApi = getClientApi(modelConfig.providerName);
const isEnableRAG =
session.attachFiles && session.attachFiles.length > 0;
// get recent messages
@@ -671,7 +668,7 @@ ${file.partial}
const session = get().currentSession();
const modelConfig = session.mask.modelConfig;
var api: ClientApi = getClientApi(modelConfig.model);
const api: ClientApi = getClientApi(modelConfig.providerName);
// remove error messages if any
const messages = session.messages;

View File

@@ -13,6 +13,7 @@ import {
DEFAULT_TTS_VOICE,
DEFAULT_TTS_VOICES,
StoreKey,
ServiceProvider,
} from "../constant";
import { createPersistStore } from "../utils/store";
@@ -61,6 +62,7 @@ export const DEFAULT_CONFIG = {
modelConfig: {
model: "gpt-3.5-turbo" as ModelType,
providerName: "OpenAI" as ServiceProvider,
temperature: 0.5,
top_p: 1,
max_tokens: 4000,
@@ -173,12 +175,12 @@ export const useAppConfig = createPersistStore(
for (const model of oldModels) {
model.available = false;
modelMap[model.name] = model;
modelMap[`${model.name}@${model?.provider?.id}`] = model;
}
for (const model of newModels) {
model.available = true;
modelMap[model.name] = model;
modelMap[`${model.name}@${model?.provider?.id}`] = model;
}
set(() => ({
@@ -225,7 +227,7 @@ export const useAppConfig = createPersistStore(
state.modelConfig.template =
state.modelConfig.template !== DEFAULT_INPUT_TEMPLATE
? state.modelConfig.template
: config?.template ?? DEFAULT_INPUT_TEMPLATE;
: (config?.template ?? DEFAULT_INPUT_TEMPLATE);
}
return state as any;

View File

@@ -154,7 +154,7 @@ export const usePromptStore = createPersistStore(
fetch(PROMPT_URL)
.then((res) => res.json())
.then((res) => {
let fetchPrompts = [res.en, res.cn];
let fetchPrompts = [res.en, res.tw, res.cn];
if (getLang() === "cn") {
fetchPrompts = fetchPrompts.reverse();
}
@@ -166,7 +166,7 @@ export const usePromptStore = createPersistStore(
title,
content,
createdAt: Date.now(),
} as Prompt),
}) as Prompt,
);
});
@@ -175,7 +175,8 @@ export const usePromptStore = createPersistStore(
const allPromptsForSearch = builtinPrompts
.reduce((pre, cur) => pre.concat(cur), [])
.filter((v) => !!v.title && !!v.content);
SearchService.count.builtin = res.en.length + res.cn.length;
SearchService.count.builtin =
res.en.length + res.cn.length + res.tw.length;
SearchService.init(allPromptsForSearch, userPrompts);
});
},