Skip to content

Commit

Permalink
chore: change the logo
Browse files Browse the repository at this point in the history
  • Loading branch information
xingwanying committed Nov 18, 2024
1 parent b31e62a commit 8c45a30
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 117 deletions.
4 changes: 2 additions & 2 deletions assistant/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@petercatai/assistant",
"version": "1.0.7",
"description": "Peter Cat Assistant Application",
"version": "1.0.9",
"description": "PeterCat Assistant Application",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"style": "dist/esm/style.css",
Expand Down
116 changes: 61 additions & 55 deletions assistant/src/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { isEmpty, map } from 'lodash';
import React, {
ReactNode,
memo,
useCallback,
useEffect,
useRef,
useState,
Expand Down Expand Up @@ -89,6 +90,65 @@ const Chat: FC<ChatProps> = memo(
starters: starters,
});

const request = useCallback(
async (messages: any[]) => {
const newMessages = messages
.filter(
(item) => item.role !== Role.tool && item.role !== Role.knowledge,
)
.map((message) => {
if (message.role === Role.user) {
try {
return {
role: message.role,
// @ts-ignore
content: JSON.parse(message?.content),
};
} catch (e) {
return message;
}
} else {
const originMessage = convertChunkToJson(
message?.content as string,
) as any;
const text =
typeof originMessage === 'string'
? originMessage
: originMessage.message;
return {
role: message.role,
content: [
{
type: 'text',
text: text,
},
],
};
}
}) as Message[];

try {
const response = await streamChat(
newMessages,
apiDomain,
apiUrl,
prompt,
token,
);
return handleStream(response);
} catch (e: any) {
// 处理请求错误,例如网络错误
return new Response(
`data: ${JSON.stringify({
status: 'error',
message: e.message,
})}`,
);
}
},
[apiDomain, apiUrl, prompt, token],
);

useEffect(() => {
setBotInfo({
assistantMeta: {
Expand Down Expand Up @@ -394,61 +454,7 @@ const Chat: FC<ChatProps> = memo(
}
return [];
}}
request={async (messages) => {
const newMessages = messages
.filter(
(item) =>
item.role !== Role.tool && item.role !== Role.knowledge,
)
.map((message) => {
if (message.role === Role.user) {
try {
return {
role: message.role,
// @ts-ignore
content: JSON.parse(message?.content),
};
} catch (e) {
return message;
}
} else {
const originMessage = convertChunkToJson(
message?.content as string,
) as any;
const text =
typeof originMessage === 'string'
? originMessage
: originMessage.message;
return {
role: message.role,
content: [
{
type: 'text',
text: text,
},
],
};
}
}) as Message[];
try {
const response = await streamChat(
newMessages,
apiDomain,
apiUrl,
prompt,
token,
);
return handleStream(response);
} catch (e: any) {
// catch query error,such as network error. then return error response for message render
return new Response(
`data: ${JSON.stringify({
status: 'error',
message: e.message,
})}`,
);
}
}}
request={request}
inputAreaRender={(
_: ReactNode,
onMessageSend: (message: string) => void | Promise<any>,
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@fullpage/react-fullpage": "^0.1.42",
"@next/bundle-analyzer": "^13.4.19",
"@nextui-org/react": "^2.2.9",
"@petercatai/assistant": "^1.0.7",
"@petercatai/assistant": "^1.0.9",
"@sentry/nextjs": "^8.28.0",
"@supabase/supabase-js": "^2.32.0",
"@tanstack/react-query": "^5.17.19",
Expand Down
Loading

0 comments on commit 8c45a30

Please sign in to comment.