Skip to content

Commit

Permalink
display doubao model name when select model
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Jul 9, 2024
1 parent b302354 commit 9d7e19c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
9 changes: 1 addition & 8 deletions app/api/bytedance/[...path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,10 @@ async function request(req: NextRequest) {
console.error(`[ByteDance] filter`, e);
}
}
console.log("[ByteDance request]", fetchOptions.headers, req.method);

try {
const res = await fetch(fetchUrl, fetchOptions);

console.log(
"[ByteDance response]",
res.status,
" ",
res.headers,
res.url,
);
// to prevent browser prompt for credentials
const newHeaders = new Headers(res.headers);
newHeaders.delete("www-authenticate");
Expand Down
12 changes: 4 additions & 8 deletions app/client/platforms/bytedance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
ApiPath,
ByteDance,
DEFAULT_API_HOST,
BYTEDANCE_BASE_URL,
REQUEST_TIMEOUT_MS,
} from "@/app/constant";
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store";
Expand Down Expand Up @@ -58,9 +58,7 @@ export class DoubaoApi implements LLMApi {

if (baseUrl.length === 0) {
const isApp = !!getClientConfig()?.isApp;
baseUrl = isApp
? DEFAULT_API_HOST + "/api/proxy/bytedance"
: ApiPath.ByteDance;
baseUrl = isApp ? BYTEDANCE_BASE_URL : ApiPath.ByteDance;
}

if (baseUrl.endsWith("/")) {
Expand Down Expand Up @@ -94,19 +92,17 @@ export class DoubaoApi implements LLMApi {
},
};

const shouldStream = !!options.config.stream;
const requestPayload: RequestPayload = {
messages,
stream: options.config.stream,
stream: shouldStream,
model: modelConfig.model,
temperature: modelConfig.temperature,
presence_penalty: modelConfig.presence_penalty,
frequency_penalty: modelConfig.frequency_penalty,
top_p: modelConfig.top_p,
};

console.log("[Request] ByteDance payload: ", requestPayload);

const shouldStream = !!options.config.stream;
const controller = new AbortController();
options.onController?.(controller);

Expand Down
26 changes: 23 additions & 3 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ export function ChatActions(props: {
return filteredModels;
}
}, [allModels]);
const currentModelName = useMemo(() => {
const model = models.find(
(m) =>
m.name == currentModel &&
m?.provider?.providerName == currentProviderName,
);
return model?.displayName ?? "";
}, [models, currentModel, currentProviderName]);
const [showModelSelector, setShowModelSelector] = useState(false);
const [showUploadImage, setShowUploadImage] = useState(false);

Expand All @@ -489,7 +497,11 @@ export function ChatActions(props: {
session.mask.modelConfig.providerName = nextModel?.provider
?.providerName as ServiceProvider;
});
showToast(nextModel.name);
showToast(
nextModel?.provider?.providerName == "ByteDance"
? nextModel.displayName
: nextModel.name,
);
}
}, [chatStore, currentModel, models]);

Expand Down Expand Up @@ -571,7 +583,7 @@ export function ChatActions(props: {

<ChatAction
onClick={() => setShowModelSelector(true)}
text={currentModel}
text={currentModelName}
icon={<RobotIcon />}
/>

Expand All @@ -596,7 +608,15 @@ export function ChatActions(props: {
providerName as ServiceProvider;
session.mask.syncGlobalConfig = false;
});
showToast(model);
if (providerName == "ByteDance") {
const selectedModel = models.find(
(m) =>
m.name == model && m?.provider.providerName == providerName,
);
showToast(selectedModel?.displayName ?? "");
} else {
showToast(model);
}
}}
/>
)}
Expand Down

0 comments on commit 9d7e19c

Please sign in to comment.