Skip to content

Commit

Permalink
Merge pull request #257 from lmstudio-ai/ryan/fix-validator
Browse files Browse the repository at this point in the history
Fix validator not returning parsed value
  • Loading branch information
yagil authored Mar 4, 2025
2 parents 6663b21 + 0b7e721 commit 4a8ac2f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/lms-client/src/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ export class Chat extends MaybeMutable<ChatHistoryData> {
*/
export type ChatLike = ChatInput | string | Chat | ChatMessageInput | ChatHistoryData;
export const chatHistoryLikeSchema = z.union([
z.instanceof(Chat as any),
chatHistoryDataSchema,
z.string(),
chatHistoryInputSchema,
chatMessageInputSchema,
z.instanceof(Chat as any),
]) as ZodSchema<ChatLike>;

/**
Expand Down Expand Up @@ -772,8 +772,8 @@ export class ChatMessage extends MaybeMutable<ChatMessageData> {
*/
export type ChatMessageLike = ChatMessageInput | string | ChatMessage | ChatMessageData;
export const chatMessageLikeSchema = z.union([
z.instanceof(ChatMessage as any),
chatMessageInputSchema,
z.string(),
z.instanceof(ChatMessage as any),
chatMessageDataSchema,
]) as ZodSchema<ChatMessageLike>;
4 changes: 3 additions & 1 deletion packages/lms-client/src/llm/LLMDynamicHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ export interface LLMRespondOpts<TStructuredOutputType = unknown>
*/
onMessage?: (message: ChatMessage) => void;
}
const llmRespondOptsSchema = llmPredictionOptsSchema;
const llmRespondOptsSchema = llmPredictionOptsSchema.extend({
onMessage: z.function().optional(),
});

type LLMRespondExtraOpts<TStructuredOutputType = unknown> = Omit<
LLMRespondOpts<TStructuredOutputType>,
Expand Down
2 changes: 1 addition & 1 deletion packages/lms-common/src/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class Validator {
index,
}));
if (errors.length === 0) {
return values as T;
return results.map(result => (result as any).data) as T;
} else {
const erroredValues = new Set(errors.map(({ index }) => index));
const lead = leadProducer(erroredValues);
Expand Down

0 comments on commit 4a8ac2f

Please sign in to comment.