Skip to content

Commit

Permalink
新增对gemini-2.0-flash-exp联网功能的适配,去除了气泡时间戳
Browse files Browse the repository at this point in the history
  • Loading branch information
tianzhentech committed Jan 20, 2025
1 parent aa06e3c commit e90d3fa
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 76 deletions.
36 changes: 29 additions & 7 deletions app/client/platforms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,39 @@ export class ChatGPTApi implements LLMApi {
}
if (shouldStream) {
let index = -1;
const [tools, funcs] = usePluginStore
const session = useChatStore.getState().currentSession();
const [_, funcs] = usePluginStore
.getState()
.getAsTools(
useChatStore.getState().currentSession().mask?.plugin || [],
);
// console.log("getAsTools", tools, funcs);
.getAsTools(session.mask?.plugin || []);

// 添加联网状态日志
console.log(
"[Chat] Web Access:",
session.mask?.plugin?.includes("googleSearch")
? "Enabled"
: "Disabled",
);

// 只有当用户选择了 googleSearch 时才创建 tools
const tools = session.mask?.plugin?.includes("googleSearch")
? [
{
type: "function",
function: {
name: "googleSearch",
},
},
]
: undefined;

stream(
chatPath,
requestPayload,
{
...requestPayload,
...(tools ? { tools } : {}),
},
getHeaders(),
tools as any,
tools || [], // 如果 tools 未定义,传入空数组
funcs,
controller,
// parseSSE
Expand Down
71 changes: 38 additions & 33 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -641,25 +641,19 @@ export function ChatActions(props: {
icon: <Avatar model={m.name} />,
}))}
onClose={() => setShowModelSelector(false)}
onSelection={(s) => {
if (s.length === 0) return;
const [model, providerName] = getModelProvider(s[0]);
onSelection={(m) => {
if (m.length === 0) return;
const [model, providerName] = getModelProvider(m[0]);
chatStore.updateTargetSession(session, (session) => {
session.mask.modelConfig.model = model as ModelType;
session.mask.modelConfig.providerName =
providerName as ServiceProvider;
session.mask.syncGlobalConfig = false;
// 如果切换到非 gemini-2.0-flash-exp 模型,清除插件选择
if (model !== "gemini-2.0-flash-exp") {
session.mask.plugin = [];
}
});
if (providerName == "ByteDance") {
const selectedModel = models.find(
(m) =>
m.name == model &&
m?.provider?.providerName == providerName,
);
showToast(selectedModel?.displayName ?? "");
} else {
showToast(model);
}
showToast(model);
}}
showSearch={config.enableModelSearch ?? false}
/>
Expand Down Expand Up @@ -749,26 +743,35 @@ export function ChatActions(props: {
/>
)}

{showPlugins(currentProviderName, currentModel) &&
config.enablePlugins && (
<ChatAction
onClick={() => {
if (pluginStore.getAll().length == 0) {
navigate(Path.Plugins);
} else {
setShowPluginSelector(true);
}
}}
text={Locale.Plugin.Name}
icon={<PluginIcon />}
/>
)}
{showPlugins(currentProviderName, currentModel) && (
<ChatAction
onClick={() => {
if (currentModel === "gemini-2.0-flash-exp") {
setShowPluginSelector(true);
} else {
navigate(Path.Plugins);
}
}}
text={Locale.Plugin.Name}
icon={<PluginIcon />}
/>
)}
{showPluginSelector && (
<SimpleMultipleSelector
items={pluginStore.getAll().map((item) => ({
title: `${item?.title}@${item?.version}`,
value: item?.id,
}))}
items={[
...(currentModel === "gemini-2.0-flash-exp"
? [
{
title: Locale.Plugin.EnableWeb,
value: "googleSearch",
},
]
: []),
...pluginStore.getAll().map((item) => ({
title: `${item?.title}@${item?.version}`,
value: item?.id,
})),
]}
defaultSelectedValue={chatStore.currentSession().mask?.plugin}
onClose={() => setShowPluginSelector(false)}
onSelection={(s) => {
Expand Down Expand Up @@ -1988,7 +1991,9 @@ function _Chat() {
<div className={styles["chat-message-action-date"]}>
{isContext
? Locale.Chat.IsContext
: message.date.toLocaleString()}
: message.role === "system"
? message.date.toLocaleString()
: ""}
</div>
</div>
</div>
Expand Down
15 changes: 0 additions & 15 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1626,21 +1626,6 @@ export function Settings() {
/>
</ListItem>

<ListItem
title={Locale.Settings.EnablePlugins.Title}
subTitle={Locale.Settings.EnablePlugins.SubTitle}
>
<input
type="checkbox"
checked={config.enablePlugins}
onChange={(e) =>
updateConfig(
(config) => (config.enablePlugins = e.currentTarget.checked),
)
}
/>
</ListItem>

<ListItem
title={Locale.Settings.EnableShortcuts.Title}
subTitle={Locale.Settings.EnableShortcuts.SubTitle}
Expand Down
1 change: 1 addition & 0 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ const cn = {
},
Plugin: {
Name: "插件",
EnableWeb: "开启联网",
Page: {
Title: "插件",
SubTitle: (count: number) => `${count} 个插件`,
Expand Down
3 changes: 2 additions & 1 deletion app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,8 @@ const en: LocaleType = {
},
},
Plugin: {
Name: "Plugin",
Name: "Plugins",
EnableWeb: "Enable Web Access",
Page: {
Title: "Plugins",
SubTitle: (count: number) => `${count} plugins`,
Expand Down
24 changes: 5 additions & 19 deletions app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useEffect, useState } from "react";
import { showToast } from "./components/ui-lib";
import Locale from "./locales";
import { RequestMessage } from "./client/api";
import { ServiceProvider } from "./constant";
// import { fetch as tauriFetch, ResponseType } from "@tauri-apps/api/http";
import { fetch as tauriStreamFetch } from "./utils/stream";

Expand All @@ -13,8 +12,8 @@ export function trimTopic(topic: string) {
return (
topic
// fix for gemini
.replace(/^["*]+|["*]+$/g, "")
.replace(/[",.!?*]*$/, "")
.replace(/^["""*]+|["""*]+$/g, "")
.replace(/["""",.!?*]*$/, "")
);
}

Expand Down Expand Up @@ -283,22 +282,9 @@ export function isDalle3(model: string) {
return "dall-e-3" === model;
}

export function showPlugins(provider: ServiceProvider, model: string) {
if (
provider == ServiceProvider.OpenAI ||
provider == ServiceProvider.Azure ||
provider == ServiceProvider.Moonshot ||
provider == ServiceProvider.ChatGLM
) {
return true;
}
if (provider == ServiceProvider.Anthropic && !model.includes("claude-2")) {
return true;
}
if (provider == ServiceProvider.Google && !model.includes("vision")) {
return true;
}
return false;
export function showPlugins(providerName?: string, model?: string) {
// 只在 gemini-2.0-flash-exp 模型下显示插件按钮
return model === "gemini-2.0-flash-exp";
}

export function fetch(
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"package": {
"productName": "NeatChat",
"version": "1.1.8-preview.4"
"version": "1.1.8"
},
"tauri": {
"allowlist": {
Expand Down

0 comments on commit e90d3fa

Please sign in to comment.