show response model name
This commit is contained in:
@@ -28,6 +28,7 @@ export default function ChatBOX(props: {
|
||||
const client = new ChatGPT(chatStore.apiKey);
|
||||
|
||||
const _completeWithStreamMode = async (response: Response) => {
|
||||
chatStore.streamMode = true;
|
||||
// call api, return reponse text
|
||||
console.log("response", response);
|
||||
const reader = response.body?.getReader();
|
||||
@@ -60,7 +61,10 @@ export default function ChatBOX(props: {
|
||||
return JSON.parse(line.trim().slice("data: ".length));
|
||||
})
|
||||
.filter((i) => i);
|
||||
// console.log("jsons", jsons);
|
||||
console.log("jsons", jsons);
|
||||
for (const { model } of jsons) {
|
||||
if (model) chatStore.responseModelName = model;
|
||||
}
|
||||
const chunkText = jsons
|
||||
.map((j) => j.choices[0].delta.content ?? "")
|
||||
.join("");
|
||||
@@ -92,7 +96,9 @@ export default function ChatBOX(props: {
|
||||
};
|
||||
|
||||
const _completeWithFetchMode = async (response: Response) => {
|
||||
chatStore.streamMode = false;
|
||||
const data = (await response.json()) as FetchResponse;
|
||||
chatStore.responseModelName = data.model ?? "";
|
||||
const content = client.processFetchResponse(data);
|
||||
chatStore.history.push({ role: "assistant", content });
|
||||
setShowGenerating(false);
|
||||
@@ -113,10 +119,8 @@ export default function ChatBOX(props: {
|
||||
const response = await client._fetch(chatStore.streamMode);
|
||||
const contentType = response.headers.get("content-type");
|
||||
if (contentType === "text/event-stream") {
|
||||
chatStore.streamMode = true;
|
||||
await _completeWithStreamMode(response);
|
||||
} else if (contentType === "application/json") {
|
||||
chatStore.streamMode = false;
|
||||
await _completeWithFetchMode(response);
|
||||
} else {
|
||||
throw `unknown response content type ${contentType}`;
|
||||
@@ -148,6 +152,7 @@ export default function ChatBOX(props: {
|
||||
console.log("empty message");
|
||||
return;
|
||||
}
|
||||
chatStore.responseModelName = "";
|
||||
chatStore.history.push({ role: "user", content: inputMsg.trim() });
|
||||
// manually calculate token length
|
||||
chatStore.totalTokens += client.calculate_token_length(inputMsg.trim());
|
||||
@@ -243,6 +248,11 @@ export default function ChatBOX(props: {
|
||||
...
|
||||
</p>
|
||||
)}
|
||||
{chatStore.responseModelName && (
|
||||
<p className="p-2 my-2 text-center opacity-50 dark:text-white">
|
||||
Generated by {chatStore.responseModelName}
|
||||
</p>
|
||||
)}
|
||||
{showRetry && (
|
||||
<p className="text-right p-2 my-2 dark:text-white">
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user