modelfusion 0.81.0 → 0.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/core/schema/ZodSchema.cjs +5 -1
- package/core/schema/ZodSchema.d.ts +1 -0
- package/core/schema/ZodSchema.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
@@ -193,7 +193,7 @@ Generate typed objects using a language model and a schema.
|
|
193
193
|
Generate a structure that matches a schema.
|
194
194
|
|
195
195
|
```ts
|
196
|
-
import {
|
196
|
+
import { zodSchema, generateStructure, openai } from "modelfusion";
|
197
197
|
|
198
198
|
const sentiment = await generateStructure(
|
199
199
|
openai
|
@@ -205,7 +205,7 @@ const sentiment = await generateStructure(
|
|
205
205
|
.asFunctionCallStructureGenerationModel({ fnName: "sentiment" })
|
206
206
|
.withInstructionPrompt(),
|
207
207
|
|
208
|
-
|
208
|
+
zodSchema(
|
209
209
|
z.object({
|
210
210
|
sentiment: z
|
211
211
|
.enum(["positive", "neutral", "negative"])
|
@@ -231,7 +231,7 @@ Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai)
|
|
231
231
|
Stream a structure that matches a schema. Partial structures before the final part are untyped JSON.
|
232
232
|
|
233
233
|
```ts
|
234
|
-
import {
|
234
|
+
import { zodSchema, openai, streamStructure } from "modelfusion";
|
235
235
|
|
236
236
|
const structureStream = await streamStructure(
|
237
237
|
openai
|
@@ -242,7 +242,7 @@ const structureStream = await streamStructure(
|
|
242
242
|
})
|
243
243
|
.withTextPrompt(),
|
244
244
|
|
245
|
-
|
245
|
+
zodSchema(
|
246
246
|
z.object({
|
247
247
|
characters: z.array(
|
248
248
|
z.object({
|
@@ -330,7 +330,7 @@ const result = await guard(
|
|
330
330
|
.asFunctionCallStructureGenerationModel({
|
331
331
|
fnName: "myFunction",
|
332
332
|
}),
|
333
|
-
|
333
|
+
zodSchema({
|
334
334
|
// ...
|
335
335
|
}),
|
336
336
|
input,
|
@@ -372,7 +372,7 @@ const calculator = new Tool({
|
|
372
372
|
name: "calculator",
|
373
373
|
description: "Execute a calculation",
|
374
374
|
|
375
|
-
parameters:
|
375
|
+
parameters: zodSchema(
|
376
376
|
z.object({
|
377
377
|
a: z.number().describe("The first number."),
|
378
378
|
b: z.number().describe("The second number."),
|
@@ -1,7 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ZodSchema = void 0;
|
3
|
+
exports.ZodSchema = exports.zodSchema = void 0;
|
4
4
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
5
|
+
function zodSchema(zodSchema) {
|
6
|
+
return new ZodSchema(zodSchema);
|
7
|
+
}
|
8
|
+
exports.zodSchema = zodSchema;
|
5
9
|
class ZodSchema {
|
6
10
|
constructor(zodSchema) {
|
7
11
|
Object.defineProperty(this, "zodSchema", {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { z } from "zod";
|
2
2
|
import { JsonSchemaProducer } from "./JsonSchemaProducer.js";
|
3
3
|
import { Schema } from "./Schema.js";
|
4
|
+
export declare function zodSchema<STRUCTURE>(zodSchema: z.Schema<STRUCTURE>): ZodSchema<STRUCTURE>;
|
4
5
|
export declare class ZodSchema<STRUCTURE> implements Schema<STRUCTURE>, JsonSchemaProducer {
|
5
6
|
readonly zodSchema: z.Schema<STRUCTURE>;
|
6
7
|
constructor(zodSchema: z.Schema<STRUCTURE>);
|
package/core/schema/ZodSchema.js
CHANGED