Skip to content

Commit

Permalink
Merge pull request #1616 from Yidadaa/bugfix-0519
Browse files Browse the repository at this point in the history
fix: #1611 show corret message when can not query usage
  • Loading branch information
Yidadaa authored May 18, 2023
2 parents 1a8cb87 + 50cfbaa commit 48f25b0
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 63 deletions.
6 changes: 5 additions & 1 deletion app/client/platforms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ export class ChatGPTApi implements LLMApi {
}),
]);

if (!used.ok || !subs.ok || used.status === 401) {
if (used.status === 401) {
throw new Error(Locale.Error.Unauthorized);
}

if (!used.ok || !subs.ok) {
throw new Error("Failed to query usage from openai");
}

const response = (await used.json()) as {
total_usage?: number;
error?: {
Expand Down
18 changes: 13 additions & 5 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -487,18 +487,26 @@ export function Chat() {

// stop response
const onUserStop = (messageId: number) => {
ChatControllerPool.stop(sessionIndex, messageId);
};

useEffect(() => {
chatStore.updateCurrentSession((session) => {
const stopTiming = Date.now() - REQUEST_TIMEOUT_MS;
session.messages.forEach((m) => {
// check if should stop all stale messages
if (m.streaming && new Date(m.date).getTime() < stopTiming) {
m.isError = false;
m.streaming = false;
if (new Date(m.date).getTime() < stopTiming) {
if (m.streaming) {
m.streaming = false;
}

if (m.content.length === 0) {
m.content = "No content in this message.";
}
}
});
});
ChatControllerPool.stop(sessionIndex, messageId);
};
}, []);

// check if should send message
const onInputKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
Expand Down
7 changes: 6 additions & 1 deletion app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ const cn = {
},
};

export type LocaleType = typeof cn;
type DeepPartial<T> = T extends object
? {
[P in keyof T]?: DeepPartial<T[P]>;
}
: T;
export type LocaleType = DeepPartial<typeof cn>;

export default cn;
9 changes: 8 additions & 1 deletion app/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import VI from "./vi";
import RU from "./ru";
import CS from "./cs";
import KO from "./ko";
import { merge } from "../utils/merge";

export type { LocaleType } from "./cn";

Expand Down Expand Up @@ -80,7 +81,8 @@ export function changeLang(lang: Lang) {
location.reload();
}

export default {
const fallbackLang = EN;
const targetLang = {
en: EN,
cn: CN,
tw: TW,
Expand All @@ -95,3 +97,8 @@ export default {
cs: CS,
ko: KO,
}[getLang()] as typeof CN;

// if target lang missing some fields, it will use fallback lang string
merge(fallbackLang, targetLang);

export default fallbackLang as typeof CN;
105 changes: 54 additions & 51 deletions app/masks/cn.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
import { BuiltinMask } from "./typing";

export const CN_MASKS: BuiltinMask[] = [{
avatar:"gpt-bot",
name:"文生图",
export const CN_MASKS: BuiltinMask[] = [
{
avatar: "1f5bc-fe0f",
name: "以文搜图",
context: [
{role:"system",
content:"You are a useful Assistant that won't refuse to draw picture, instead, you will output specific markdown code for picture description, but don't use code block.",
date:"",
},
{role:"user",
content:"Can you draw some pictures for me?",
date:"",
},
{role:"assistant",
content:"Sure, what do you want me to draw?",
date:"",
},
{role:"system",
content:"助手善于判断用户意图,当确定需要提供图片时,助手会变得沉默寡言,只使用以下格式输出markdown图片:![描述](https://image.pollinations.ai/prompt/描述),因为这个语法可以自动按照提示生成并渲染图片。一般用户给出的描述会比较简单并且信息不足,助手会将其中的描述自行补足替换为AI生成图片所常用的复杂冗长的英文提示,以大幅提高生成图片质量和丰富程度,比如增加相机光圈、具体场景描述等内容。助手会避免用代码块或原始块包围markdown标记,因为那样只会渲染出代码块或原始块而不是图片。",
date:"",
},
{
role: "system",
content:
"You are a useful Assistant that won't refuse to draw picture, instead, you will output specific markdown code for picture description, but don't use code block.",
date: "",
},
{ role: "user", content: "Can you draw some pictures for me?", date: "" },
{
role: "assistant",
content: "Sure, what do you want me to draw?",
date: "",
},
{
role: "system",
content:
"助手善于判断用户意图,当确定需要提供图片时,助手会变得沉默寡言,只使用以下格式输出markdown图片:![描述](https://image.pollinations.ai/prompt/描述),因为这个语法可以自动按照提示生成并渲染图片。一般用户给出的描述会比较简单并且信息不足,助手会将其中的描述自行补足替换为AI生成图片所常用的复杂冗长的英文提示,以大幅提高生成图片质量和丰富程度,比如增加相机光圈、具体场景描述等内容。助手会避免用代码块或原始块包围markdown标记,因为那样只会渲染出代码块或原始块而不是图片。",
date: "",
},
],
modelConfig:{
model:"gpt-3.5-turbo",
temperature:1,
max_tokens:2000,
presence_penalty:0,
sendMemory:true,
historyMessageCount:32,
compressMessageLengthThreshold:1000,
modelConfig: {
model: "gpt-3.5-turbo",
temperature: 1,
max_tokens: 2000,
presence_penalty: 0,
sendMemory: true,
historyMessageCount: 32,
compressMessageLengthThreshold: 1000,
},
lang:"cn",
builtin:true,
lang: "cn",
builtin: true,
},
{
avatar: "1f638",
Expand Down Expand Up @@ -194,33 +197,33 @@ export const CN_MASKS: BuiltinMask[] = [{
lang: "cn",
builtin: true,
},
{ avatar:"1f4d1",
name:"简历写手",
context:[
{
avatar: "1f4d1",
name: "简历写手",
context: [
{
role:"user",
role: "user",
content:
"我需要你写一份通用简历,每当我输入一个职业、项目名称时,你需要完成以下任务:\ntask1: 列出这个人的基本资料,如姓名、出生年月、学历、面试职位、工作年限、意向城市等。一行列一个资料。\ntask2: 详细介绍这个职业的技能介绍,至少列出10条\ntask3: 详细列出这个职业对应的工作经历,列出2条\ntask4: 详细列出这个职业对应的工作项目,列出2条。项目按照项目背景、项目细节、项目难点、优化和改进、我的价值几个方面来描述,多展示职业关键字。也可以体现我在项目管理、工作推进方面的一些能力。\ntask5: 详细列出个人评价,100字左右\n你把以上任务结果按照以下Markdown格式输出:\n\n```\n### 基本信息\n<task1 result>\n\n### 掌握技能\n<task2 result>\n\n### 工作经历\n<task3 result>\n\n### 项目经历\n<task4 result>\n\n### 关于我\n<task5 result>\n\n```",
date:"",
"我需要你写一份通用简历,每当我输入一个职业、项目名称时,你需要完成以下任务:\ntask1: 列出这个人的基本资料,如姓名、出生年月、学历、面试职位、工作年限、意向城市等。一行列一个资料。\ntask2: 详细介绍这个职业的技能介绍,至少列出10条\ntask3: 详细列出这个职业对应的工作经历,列出2条\ntask4: 详细列出这个职业对应的工作项目,列出2条。项目按照项目背景、项目细节、项目难点、优化和改进、我的价值几个方面来描述,多展示职业关键字。也可以体现我在项目管理、工作推进方面的一些能力。\ntask5: 详细列出个人评价,100字左右\n你把以上任务结果按照以下Markdown格式输出:\n\n```\n### 基本信息\n<task1 result>\n\n### 掌握技能\n<task2 result>\n\n### 工作经历\n<task3 result>\n\n### 项目经历\n<task4 result>\n\n### 关于我\n<task5 result>\n\n```",
date: "",
},
{
role: "assistant",
content: "好的,请问您需要我为哪个职业编写通用简历呢?",
date: "",
},
{
role:"assistant",
content:"好的,请问您需要我为哪个职业编写通用简历呢?",
date:""
}
],
modelConfig:
{
model:"gpt-3.5-turbo",
temperature:0.5,
max_tokens:2000,
presence_penalty:0,
sendMemory:true,
historyMessageCount:4,
compressMessageLengthThreshold:1000
modelConfig: {
model: "gpt-3.5-turbo",
temperature: 0.5,
max_tokens: 2000,
presence_penalty: 0,
sendMemory: true,
historyMessageCount: 4,
compressMessageLengthThreshold: 1000,
},
lang:"cn",
builtin:false
lang: "cn",
builtin: true,
},
{
avatar: "1f469-200d-2695-fe0f",
Expand Down
Loading

0 comments on commit 48f25b0

Please sign in to comment.