Skip to content

Commit

Permalink
fix: history parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Apr 10, 2024
1 parent 305c071 commit eb0862b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/backend/server/src/plugins/copilot/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ChatMessageSchema,
getTokenEncoder,
PromptMessage,
PromptMessageSchema,
PromptParams,
} from './types';

Expand Down Expand Up @@ -211,7 +212,7 @@ export class ChatSessionService {
}

private calculateTokenSize(
messages: ChatMessage[],
messages: PromptMessage[],
model: AvailableModel
): number {
const encoder = getTokenEncoder(model);
Expand All @@ -238,7 +239,7 @@ export class ChatSessionService {
workspaceId,
docId: workspaceId === options?.docId ? undefined : options?.docId,
prompt: {
action: options?.action ? { not: null } : { equals: null },
action: options?.action ? { not: null } : null,
},
},
select: { id: true },
Expand All @@ -259,7 +260,7 @@ export class ChatSessionService {
workspaceId: workspaceId,
docId: workspaceId === docId ? undefined : docId,
prompt: {
action: options?.action ? { not: null } : { equals: null },
action: options?.action ? { not: null } : null,
},
id: options?.sessionId ? { equals: options.sessionId } : undefined,
},
Expand All @@ -284,7 +285,7 @@ export class ChatSessionService {
sessions
.map(({ id, prompt, messages }) => {
try {
const ret = ChatMessageSchema.array().safeParse(messages);
const ret = PromptMessageSchema.array().safeParse(messages);
if (ret.success) {
const tokens = this.calculateTokenSize(
ret.data,
Expand All @@ -296,6 +297,10 @@ export class ChatSessionService {
tokens,
messages: ret.data,
};
} else {
this.logger.error(
`Unexpected message schema: ${JSON.stringify(ret.error)}`
);
}
} catch (e) {
this.logger.error('Unexpected error in listHistories', e);
Expand Down

0 comments on commit eb0862b

Please sign in to comment.