Skip to content

Commit

Permalink
fix(ai): fix error when chat without params
Browse files Browse the repository at this point in the history
  • Loading branch information
mayneyao committed Nov 26, 2024
1 parent bd31071 commit fa03eb8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion electron/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function startServer({ dist, port }: { dist: string, port: number }) {
request: c.req,
respondWith: (response: Response) => response,
} as unknown as FetchEvent, {
getDataspace: (space) => getOrSetDataSpace(space)
getDataspace: (space) => space ? getOrSetDataSpace(space) : Promise.resolve(null)
});
return response;
});
Expand Down
2 changes: 1 addition & 1 deletion worker/service-worker/ai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { handleWebLLM } from "./webllm"

export const pathname = "/api/chat"
export default async function handle(event: FetchEvent, ctx?: {
getDataspace: (space: string) => Promise<DataSpace>
getDataspace: (space: string) => Promise<DataSpace | null>
}) {
const data = (await event.request.json()) as IData
const { type } = data
Expand Down
4 changes: 2 additions & 2 deletions worker/service-worker/ai/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IData } from "./interface";
export async function handleOpenAI(
data: IData,
ctx?: {
getDataspace: (space: string) => Promise<DataSpace>
getDataspace: (space: string) => Promise<DataSpace | null>
}
) {
// only use functions on desktop app
Expand Down Expand Up @@ -57,7 +57,7 @@ export async function handleOpenAI(
return new Response('No user message found', { status: 400 });
}

const dataspace = await ctx?.getDataspace(space)
const dataspace = space && await ctx?.getDataspace(space)

if (dataspace) {
const chat = await getChatById(id, dataspace);
Expand Down

0 comments on commit fa03eb8

Please sign in to comment.