modelfusion 0.81.0 → 0.83.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 CHANGED
@@ -193,9 +193,10 @@ 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 { ZodSchema, generateStructure, openai } from "modelfusion";
196
+ import { zodSchema, generateStructure, openai } from "modelfusion";
197
197
 
198
198
  const sentiment = await generateStructure(
199
+ // model:
199
200
  openai
200
201
  .ChatTextGenerator({
201
202
  model: "gpt-3.5-turbo",
@@ -205,7 +206,8 @@ const sentiment = await generateStructure(
205
206
  .asFunctionCallStructureGenerationModel({ fnName: "sentiment" })
206
207
  .withInstructionPrompt(),
207
208
 
208
- new ZodSchema(
209
+ // schema:
210
+ zodSchema(
209
211
  z.object({
210
212
  sentiment: z
211
213
  .enum(["positive", "neutral", "negative"])
@@ -213,6 +215,7 @@ const sentiment = await generateStructure(
213
215
  })
214
216
  ),
215
217
 
218
+ // prompt:
216
219
  {
217
220
  system:
218
221
  "You are a sentiment evaluator. " +
@@ -224,14 +227,14 @@ const sentiment = await generateStructure(
224
227
  );
225
228
  ```
226
229
 
227
- Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai)
230
+ Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai), [Ollama](https://modelfusion.dev//integration/model-provider/ollama)
228
231
 
229
232
  #### streamStructure
230
233
 
231
234
  Stream a structure that matches a schema. Partial structures before the final part are untyped JSON.
232
235
 
233
236
  ```ts
234
- import { ZodSchema, openai, streamStructure } from "modelfusion";
237
+ import { zodSchema, openai, streamStructure } from "modelfusion";
235
238
 
236
239
  const structureStream = await streamStructure(
237
240
  openai
@@ -242,7 +245,7 @@ const structureStream = await streamStructure(
242
245
  })
243
246
  .withTextPrompt(),
244
247
 
245
- new ZodSchema(
248
+ zodSchema(
246
249
  z.object({
247
250
  characters: z.array(
248
251
  z.object({
@@ -270,7 +273,7 @@ for await (const part of structureStream) {
270
273
  }
271
274
  ```
272
275
 
273
- Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai)
276
+ Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai), [Ollama](https://modelfusion.dev//integration/model-provider/ollama)
274
277
 
275
278
  ### [Embed Value](https://modelfusion.dev/guide/function/embed)
276
279
 
@@ -330,7 +333,7 @@ const result = await guard(
330
333
  .asFunctionCallStructureGenerationModel({
331
334
  fnName: "myFunction",
332
335
  }),
333
- new ZodSchema({
336
+ zodSchema({
334
337
  // ...
335
338
  }),
336
339
  input,
@@ -372,7 +375,7 @@ const calculator = new Tool({
372
375
  name: "calculator",
373
376
  description: "Execute a calculation",
374
377
 
375
- parameters: new ZodSchema(
378
+ parameters: zodSchema(
376
379
  z.object({
377
380
  a: z.number().describe("The first number."),
378
381
  b: z.number().describe("The second number."),
@@ -591,15 +594,15 @@ const image = await generateImage(
591
594
  .ImageGenerator({
592
595
  //...
593
596
  })
594
- .withBasicPrompt(),
597
+ .withTextPrompt(),
595
598
  "the wicked witch of the west in the style of early 19th century painting"
596
599
  );
597
600
  ```
598
601
 
599
- | Prompt Format | Basic Text Prompt |
600
- | ------------- | ----------------- |
601
- | Automatic1111 | ✅ |
602
- | Stability | ✅ |
602
+ | Prompt Format | Text Prompt |
603
+ | ------------- | ----------- |
604
+ | Automatic1111 | ✅ |
605
+ | Stability | ✅ |
603
606
 
604
607
  ### Metadata and original responses
605
608
 
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UncheckedSchema = void 0;
3
+ exports.UncheckedSchema = exports.uncheckedSchema = void 0;
4
+ function uncheckedSchema(jsonSchema) {
5
+ return new UncheckedSchema(jsonSchema);
6
+ }
7
+ exports.uncheckedSchema = uncheckedSchema;
4
8
  class UncheckedSchema {
5
9
  constructor(jsonSchema) {
6
10
  Object.defineProperty(this, "jsonSchema", {
@@ -1,5 +1,6 @@
1
1
  import { JsonSchemaProducer } from "./JsonSchemaProducer.js";
2
2
  import { Schema } from "./Schema.js";
3
+ export declare function uncheckedSchema<STRUCTURE>(jsonSchema?: unknown): UncheckedSchema<STRUCTURE>;
3
4
  export declare class UncheckedSchema<STRUCTURE> implements Schema<STRUCTURE>, JsonSchemaProducer {
4
5
  private readonly jsonSchema?;
5
6
  constructor(jsonSchema?: unknown);
@@ -1,3 +1,6 @@
1
+ export function uncheckedSchema(jsonSchema) {
2
+ return new UncheckedSchema(jsonSchema);
3
+ }
1
4
  export class UncheckedSchema {
2
5
  constructor(jsonSchema) {
3
6
  Object.defineProperty(this, "jsonSchema", {
@@ -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>);
@@ -1,4 +1,7 @@
1
1
  import { zodToJsonSchema } from "zod-to-json-schema";
2
+ export function zodSchema(zodSchema) {
3
+ return new ZodSchema(zodSchema);
4
+ }
2
5
  export class ZodSchema {
3
6
  constructor(zodSchema) {
4
7
  Object.defineProperty(this, "zodSchema", {
@@ -4,7 +4,7 @@ import { MultiModalInput } from "./Content.js";
4
4
  * the role and behavior of the language model.
5
5
  * The instruction is a multi-model input (`array` of content).
6
6
  */
7
- export interface InstructionPrompt {
7
+ export interface MultiModalInstructionPrompt {
8
8
  /**
9
9
  * Optional system message to provide context for the language model. Note that for some models,
10
10
  * changing the system message can impact the results, because the model may be trained on the default system message.
@@ -53,7 +53,7 @@ class Automatic1111ImageGenerationModel extends AbstractModel_js_1.AbstractModel
53
53
  base64Image: response.images[0],
54
54
  };
55
55
  }
56
- withBasicPrompt() {
56
+ withTextPrompt() {
57
57
  return this.withPromptFormat((0, Automatic1111ImageGenerationPrompt_js_1.mapBasicPromptToAutomatic1111Format)());
58
58
  }
59
59
  withPromptFormat(promptFormat) {
@@ -25,7 +25,7 @@ export declare class Automatic1111ImageGenerationModel extends AbstractModel<Aut
25
25
  };
26
26
  base64Image: string;
27
27
  }>;
28
- withBasicPrompt(): PromptFormatImageGenerationModel<string, Automatic1111ImageGenerationPrompt, Automatic1111ImageGenerationSettings, this>;
28
+ withTextPrompt(): PromptFormatImageGenerationModel<string, Automatic1111ImageGenerationPrompt, Automatic1111ImageGenerationSettings, this>;
29
29
  withPromptFormat<INPUT_PROMPT>(promptFormat: PromptFormat<INPUT_PROMPT, Automatic1111ImageGenerationPrompt>): PromptFormatImageGenerationModel<INPUT_PROMPT, Automatic1111ImageGenerationPrompt, Automatic1111ImageGenerationSettings, this>;
30
30
  withSettings(additionalSettings: Automatic1111ImageGenerationSettings): this;
31
31
  }
@@ -50,7 +50,7 @@ export class Automatic1111ImageGenerationModel extends AbstractModel {
50
50
  base64Image: response.images[0],
51
51
  };
52
52
  }
53
- withBasicPrompt() {
53
+ withTextPrompt() {
54
54
  return this.withPromptFormat(mapBasicPromptToAutomatic1111Format());
55
55
  }
56
56
  withPromptFormat(promptFormat) {
@@ -1,4 +1,4 @@
1
- import { InstructionPrompt } from "../../model-function/generate-text/prompt-format/InstructionPrompt.js";
1
+ import { MultiModalInstructionPrompt } from "../../model-function/generate-text/prompt-format/InstructionPrompt.js";
2
2
  import { TextGenerationPromptFormat } from "../../model-function/generate-text/TextGenerationPromptFormat.js";
3
3
  import { LlamaCppTextGenerationPrompt } from "./LlamaCppTextGenerationModel.js";
4
4
  /**
@@ -6,4 +6,4 @@ import { LlamaCppTextGenerationPrompt } from "./LlamaCppTextGenerationModel.js";
6
6
  *
7
7
  * @see https://github.com/SkunkworksAI/BakLLaVA
8
8
  */
9
- export declare function instruction(): TextGenerationPromptFormat<InstructionPrompt, LlamaCppTextGenerationPrompt>;
9
+ export declare function instruction(): TextGenerationPromptFormat<MultiModalInstructionPrompt, LlamaCppTextGenerationPrompt>;
@@ -27,7 +27,7 @@ OpenAIChatSettings> {
27
27
  /**
28
28
  * Returns this model with an instruction prompt format.
29
29
  */
30
- withInstructionPrompt(): OpenAIChatFunctionCallStructureGenerationModel<TextGenerationPromptFormat<import("../../../index.js").InstructionPrompt | import("../../../index.js").TextInstructionPrompt, OpenAIChatMessage[]>>;
30
+ withInstructionPrompt(): OpenAIChatFunctionCallStructureGenerationModel<TextGenerationPromptFormat<import("../../../index.js").MultiModalInstructionPrompt | import("../../../index.js").TextInstructionPrompt, OpenAIChatMessage[]>>;
31
31
  /**
32
32
  * Returns this model with a chat prompt format.
33
33
  */
@@ -338,7 +338,7 @@ export declare class OpenAIChatModel extends AbstractModel<OpenAIChatSettings> i
338
338
  /**
339
339
  * Returns this model with an instruction prompt format.
340
340
  */
341
- withInstructionPrompt(): PromptFormatTextStreamingModel<import("../../../index.js").InstructionPrompt | import("../../../index.js").TextInstructionPrompt, OpenAIChatMessage[], OpenAIChatSettings, this>;
341
+ withInstructionPrompt(): PromptFormatTextStreamingModel<import("../../../index.js").MultiModalInstructionPrompt | import("../../../index.js").TextInstructionPrompt, OpenAIChatMessage[], OpenAIChatSettings, this>;
342
342
  /**
343
343
  * Returns this model with a chat prompt format.
344
344
  */
@@ -1,6 +1,6 @@
1
1
  import { TextGenerationPromptFormat } from "../../../model-function/generate-text/TextGenerationPromptFormat.js";
2
2
  import { ChatPrompt } from "../../../model-function/generate-text/prompt-format/ChatPrompt.js";
3
- import { InstructionPrompt, TextInstructionPrompt } from "../../../model-function/generate-text/prompt-format/InstructionPrompt.js";
3
+ import { MultiModalInstructionPrompt, TextInstructionPrompt } from "../../../model-function/generate-text/prompt-format/InstructionPrompt.js";
4
4
  import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
5
5
  /**
6
6
  * OpenAIMessage[] identity chat format.
@@ -13,7 +13,7 @@ export declare function text(): TextGenerationPromptFormat<string, Array<OpenAIC
13
13
  /**
14
14
  * Formats an instruction prompt as an OpenAI chat prompt.
15
15
  */
16
- export declare function instruction(): TextGenerationPromptFormat<InstructionPrompt | TextInstructionPrompt, Array<OpenAIChatMessage>>;
16
+ export declare function instruction(): TextGenerationPromptFormat<MultiModalInstructionPrompt | TextInstructionPrompt, Array<OpenAIChatMessage>>;
17
17
  /**
18
18
  * Formats a chat prompt as an OpenAI chat prompt.
19
19
  */
@@ -78,7 +78,7 @@ class StabilityImageGenerationModel extends AbstractModel_js_1.AbstractModel {
78
78
  base64Image: response.artifacts[0].base64,
79
79
  };
80
80
  }
81
- withBasicPrompt() {
81
+ withTextPrompt() {
82
82
  return this.withPromptFormat((0, StabilityImageGenerationPrompt_js_1.mapBasicPromptToStabilityFormat)());
83
83
  }
84
84
  withPromptFormat(promptFormat) {
@@ -44,7 +44,7 @@ export declare class StabilityImageGenerationModel extends AbstractModel<Stabili
44
44
  };
45
45
  base64Image: string;
46
46
  }>;
47
- withBasicPrompt(): PromptFormatImageGenerationModel<string, StabilityImageGenerationPrompt, StabilityImageGenerationSettings, this>;
47
+ withTextPrompt(): PromptFormatImageGenerationModel<string, StabilityImageGenerationPrompt, StabilityImageGenerationSettings, this>;
48
48
  withPromptFormat<INPUT_PROMPT>(promptFormat: PromptFormat<INPUT_PROMPT, StabilityImageGenerationPrompt>): PromptFormatImageGenerationModel<INPUT_PROMPT, StabilityImageGenerationPrompt, StabilityImageGenerationSettings, this>;
49
49
  withSettings(additionalSettings: StabilityImageGenerationSettings): this;
50
50
  }
@@ -75,7 +75,7 @@ export class StabilityImageGenerationModel extends AbstractModel {
75
75
  base64Image: response.artifacts[0].base64,
76
76
  };
77
77
  }
78
- withBasicPrompt() {
78
+ withTextPrompt() {
79
79
  return this.withPromptFormat(mapBasicPromptToStabilityFormat());
80
80
  }
81
81
  withPromptFormat(promptFormat) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "The TypeScript library for building multi-modal AI applications.",
4
- "version": "0.81.0",
4
+ "version": "0.83.0",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [