modelfusion 0.79.0 → 0.81.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 +58 -46
- package/core/schema/UncheckedSchema.d.ts +2 -1
- package/core/schema/ZodSchema.d.ts +2 -1
- package/core/schema/index.cjs +0 -3
- package/core/schema/index.d.ts +0 -3
- package/core/schema/index.js +0 -3
- package/guard/fixStructure.cjs +14 -8
- package/guard/fixStructure.d.ts +14 -8
- package/guard/fixStructure.js +14 -8
- package/model-function/generate-structure/StructureFromTextGenerationModel.cjs +2 -3
- package/model-function/generate-structure/StructureFromTextGenerationModel.d.ts +8 -10
- package/model-function/generate-structure/StructureFromTextGenerationModel.js +2 -3
- package/model-function/generate-structure/StructureFromTextPromptFormat.d.ts +6 -0
- package/model-function/generate-structure/StructureFromTextStreamingModel.cjs +69 -0
- package/model-function/generate-structure/StructureFromTextStreamingModel.d.ts +22 -0
- package/model-function/generate-structure/StructureFromTextStreamingModel.js +65 -0
- package/model-function/generate-structure/StructureGenerationModel.d.ts +4 -3
- package/model-function/generate-structure/StructureParseError.cjs +2 -10
- package/model-function/generate-structure/StructureParseError.d.ts +1 -4
- package/model-function/generate-structure/StructureParseError.js +2 -10
- package/model-function/generate-structure/StructureValidationError.cjs +2 -10
- package/model-function/generate-structure/StructureValidationError.d.ts +1 -4
- package/model-function/generate-structure/StructureValidationError.js +2 -10
- package/model-function/generate-structure/generateStructure.cjs +4 -5
- package/model-function/generate-structure/generateStructure.d.ts +14 -20
- package/model-function/generate-structure/generateStructure.js +4 -5
- package/model-function/generate-structure/index.cjs +3 -0
- package/model-function/generate-structure/index.d.ts +3 -0
- package/model-function/generate-structure/index.js +3 -0
- package/model-function/generate-structure/jsonStructurePrompt.cjs +11 -0
- package/model-function/generate-structure/jsonStructurePrompt.d.ts +4 -0
- package/model-function/generate-structure/jsonStructurePrompt.js +7 -0
- package/model-function/generate-structure/streamStructure.cjs +4 -4
- package/model-function/generate-structure/streamStructure.d.ts +18 -26
- package/model-function/generate-structure/streamStructure.js +4 -4
- package/model-function/generate-text/PromptFormatTextGenerationModel.cjs +7 -0
- package/model-function/generate-text/PromptFormatTextGenerationModel.d.ts +3 -0
- package/model-function/generate-text/PromptFormatTextGenerationModel.js +7 -0
- package/model-function/generate-text/PromptFormatTextStreamingModel.cjs +7 -0
- package/model-function/generate-text/PromptFormatTextStreamingModel.d.ts +3 -0
- package/model-function/generate-text/PromptFormatTextStreamingModel.js +7 -0
- package/model-function/generate-text/prompt-format/AlpacaPromptFormat.cjs +10 -10
- package/model-function/generate-text/prompt-format/AlpacaPromptFormat.d.ts +2 -2
- package/model-function/generate-text/prompt-format/AlpacaPromptFormat.js +10 -10
- package/model-function/generate-text/prompt-format/ChatMLPromptFormat.cjs +15 -13
- package/model-function/generate-text/prompt-format/ChatMLPromptFormat.d.ts +3 -3
- package/model-function/generate-text/prompt-format/ChatMLPromptFormat.js +15 -13
- package/model-function/generate-text/prompt-format/ChatPrompt.cjs +24 -0
- package/model-function/generate-text/prompt-format/ChatPrompt.d.ts +10 -4
- package/model-function/generate-text/prompt-format/ChatPrompt.js +22 -1
- package/model-function/generate-text/prompt-format/Content.cjs +2 -0
- package/model-function/generate-text/prompt-format/Content.d.ts +20 -0
- package/model-function/generate-text/prompt-format/Content.js +1 -0
- package/model-function/generate-text/prompt-format/InstructionPrompt.d.ts +22 -17
- package/model-function/generate-text/prompt-format/InvalidPromptError.cjs +28 -0
- package/model-function/generate-text/prompt-format/InvalidPromptError.d.ts +13 -0
- package/model-function/generate-text/prompt-format/InvalidPromptError.js +24 -0
- package/model-function/generate-text/prompt-format/Llama2PromptFormat.cjs +14 -10
- package/model-function/generate-text/prompt-format/Llama2PromptFormat.d.ts +3 -3
- package/model-function/generate-text/prompt-format/Llama2PromptFormat.js +14 -10
- package/model-function/generate-text/prompt-format/TextPromptFormat.cjs +11 -11
- package/model-function/generate-text/prompt-format/TextPromptFormat.d.ts +3 -3
- package/model-function/generate-text/prompt-format/TextPromptFormat.js +11 -11
- package/model-function/generate-text/prompt-format/VicunaPromptFormat.cjs +6 -6
- package/model-function/generate-text/prompt-format/VicunaPromptFormat.d.ts +1 -1
- package/model-function/generate-text/prompt-format/VicunaPromptFormat.js +6 -6
- package/model-function/generate-text/prompt-format/index.cjs +2 -2
- package/model-function/generate-text/prompt-format/index.d.ts +2 -2
- package/model-function/generate-text/prompt-format/index.js +2 -2
- package/model-function/generate-text/prompt-format/trimChatPrompt.cjs +2 -2
- package/model-function/generate-text/prompt-format/trimChatPrompt.d.ts +1 -1
- package/model-function/generate-text/prompt-format/trimChatPrompt.js +1 -1
- package/model-provider/anthropic/AnthropicPromptFormat.cjs +10 -10
- package/model-provider/anthropic/AnthropicPromptFormat.d.ts +3 -3
- package/model-provider/anthropic/AnthropicPromptFormat.js +10 -10
- package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +1 -1
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +1 -1
- package/model-provider/llamacpp/LlamaCppBakLLaVA1Format.cjs +20 -11
- package/model-provider/llamacpp/LlamaCppBakLLaVA1Format.js +20 -11
- package/model-provider/openai/OpenAICompletionModel.d.ts +1 -1
- package/model-provider/openai/chat/OpenAIChatFunctionCallStructureGenerationModel.cjs +147 -0
- package/model-provider/openai/chat/OpenAIChatFunctionCallStructureGenerationModel.d.ts +89 -0
- package/model-provider/openai/chat/OpenAIChatFunctionCallStructureGenerationModel.js +140 -0
- package/model-provider/openai/chat/OpenAIChatMessage.cjs +19 -14
- package/model-provider/openai/chat/OpenAIChatMessage.d.ts +2 -5
- package/model-provider/openai/chat/OpenAIChatMessage.js +19 -14
- package/model-provider/openai/chat/OpenAIChatModel.cjs +16 -56
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +10 -54
- package/model-provider/openai/chat/OpenAIChatModel.js +17 -54
- package/model-provider/openai/chat/OpenAIChatPromptFormat.cjs +19 -14
- package/model-provider/openai/chat/OpenAIChatPromptFormat.d.ts +6 -2
- package/model-provider/openai/chat/OpenAIChatPromptFormat.js +17 -13
- package/package.json +1 -1
- package/tool/generate-tool-calls-or-text/generateToolCallsOrText.d.ts +2 -2
- package/core/schema/StructureDefinition.d.ts +0 -7
- package/core/schema/UncheckedStructureDefinition.cjs +0 -30
- package/core/schema/UncheckedStructureDefinition.d.ts +0 -12
- package/core/schema/UncheckedStructureDefinition.js +0 -26
- package/core/schema/ZodStructureDefinition.cjs +0 -30
- package/core/schema/ZodStructureDefinition.d.ts +0 -13
- package/core/schema/ZodStructureDefinition.js +0 -26
- package/model-function/generate-text/prompt-format/ChatPromptValidationError.cjs +0 -17
- package/model-function/generate-text/prompt-format/ChatPromptValidationError.d.ts +0 -8
- package/model-function/generate-text/prompt-format/ChatPromptValidationError.js +0 -13
- package/model-function/generate-text/prompt-format/validateChatPrompt.cjs +0 -24
- package/model-function/generate-text/prompt-format/validateChatPrompt.d.ts +0 -5
- package/model-function/generate-text/prompt-format/validateChatPrompt.js +0 -20
- /package/{core/schema/StructureDefinition.cjs → model-function/generate-structure/StructureFromTextPromptFormat.cjs} +0 -0
- /package/{core/schema/StructureDefinition.js → model-function/generate-structure/StructureFromTextPromptFormat.js} +0 -0
@@ -1,11 +1,17 @@
|
|
1
|
-
import { validateChatPrompt } from "../../../model-function/generate-text/prompt-format/
|
1
|
+
import { validateChatPrompt } from "../../../model-function/generate-text/prompt-format/ChatPrompt.js";
|
2
2
|
import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
|
3
|
+
/**
|
4
|
+
* OpenAIMessage[] identity chat format.
|
5
|
+
*/
|
6
|
+
export function identity() {
|
7
|
+
return { format: (prompt) => prompt, stopSequences: [] };
|
8
|
+
}
|
3
9
|
/**
|
4
10
|
* Formats a text prompt as an OpenAI chat prompt.
|
5
11
|
*/
|
6
12
|
export function text() {
|
7
13
|
return {
|
8
|
-
format: (
|
14
|
+
format: (prompt) => [OpenAIChatMessage.user(prompt)],
|
9
15
|
stopSequences: [],
|
10
16
|
};
|
11
17
|
}
|
@@ -14,14 +20,12 @@ export function text() {
|
|
14
20
|
*/
|
15
21
|
export function instruction() {
|
16
22
|
return {
|
17
|
-
format
|
23
|
+
format(prompt) {
|
18
24
|
const messages = [];
|
19
|
-
if (
|
20
|
-
messages.push(OpenAIChatMessage.system(
|
25
|
+
if (prompt.system != null) {
|
26
|
+
messages.push(OpenAIChatMessage.system(prompt.system));
|
21
27
|
}
|
22
|
-
messages.push(OpenAIChatMessage.user(
|
23
|
-
image: instruction.image,
|
24
|
-
}));
|
28
|
+
messages.push(OpenAIChatMessage.user(prompt.instruction));
|
25
29
|
return messages;
|
26
30
|
},
|
27
31
|
stopSequences: [],
|
@@ -32,13 +36,13 @@ export function instruction() {
|
|
32
36
|
*/
|
33
37
|
export function chat() {
|
34
38
|
return {
|
35
|
-
format
|
36
|
-
validateChatPrompt(
|
39
|
+
format(prompt) {
|
40
|
+
validateChatPrompt(prompt);
|
37
41
|
const messages = [];
|
38
|
-
if (
|
39
|
-
messages.push(OpenAIChatMessage.system(
|
42
|
+
if (prompt.system != null) {
|
43
|
+
messages.push(OpenAIChatMessage.system(prompt.system));
|
40
44
|
}
|
41
|
-
for (const { role, content } of
|
45
|
+
for (const { role, content } of prompt.messages) {
|
42
46
|
switch (role) {
|
43
47
|
case "user": {
|
44
48
|
messages.push(OpenAIChatMessage.user(content));
|
package/package.json
CHANGED
@@ -14,13 +14,13 @@ type ToToolCallUnion<T> = {
|
|
14
14
|
} : never;
|
15
15
|
}[keyof T];
|
16
16
|
type ToOutputValue<TOOL_CALLS extends ToolCallDefinitionArray<ToolDefinition<any, any>[]>> = ToToolCallUnion<ToToolCallDefinitionMap<TOOL_CALLS>>;
|
17
|
-
export declare function generateToolCallsOrText<TOOLS extends Array<ToolDefinition<any, any>>, PROMPT>(model: ToolCallsOrTextGenerationModel<PROMPT, ToolCallsOrTextGenerationModelSettings>, tools: TOOLS, prompt: PROMPT | ((
|
17
|
+
export declare function generateToolCallsOrText<TOOLS extends Array<ToolDefinition<any, any>>, PROMPT>(model: ToolCallsOrTextGenerationModel<PROMPT, ToolCallsOrTextGenerationModelSettings>, tools: TOOLS, prompt: PROMPT | ((tools: TOOLS) => PROMPT), options?: FunctionOptions & {
|
18
18
|
returnType?: "structure";
|
19
19
|
}): Promise<{
|
20
20
|
text: string | null;
|
21
21
|
toolCalls: Array<ToOutputValue<TOOLS>> | null;
|
22
22
|
}>;
|
23
|
-
export declare function generateToolCallsOrText<TOOLS extends ToolDefinition<any, any>[], PROMPT>(model: ToolCallsOrTextGenerationModel<PROMPT, ToolCallsOrTextGenerationModelSettings>, tools: TOOLS, prompt: PROMPT | ((
|
23
|
+
export declare function generateToolCallsOrText<TOOLS extends ToolDefinition<any, any>[], PROMPT>(model: ToolCallsOrTextGenerationModel<PROMPT, ToolCallsOrTextGenerationModelSettings>, tools: TOOLS, prompt: PROMPT | ((tools: TOOLS) => PROMPT), options: FunctionOptions & {
|
24
24
|
returnType?: "full";
|
25
25
|
}): Promise<{
|
26
26
|
value: {
|
@@ -1,30 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.UncheckedStructureDefinition = void 0;
|
4
|
-
const UncheckedSchema_js_1 = require("./UncheckedSchema.cjs");
|
5
|
-
class UncheckedStructureDefinition {
|
6
|
-
constructor({ name, description, jsonSchema, }) {
|
7
|
-
Object.defineProperty(this, "name", {
|
8
|
-
enumerable: true,
|
9
|
-
configurable: true,
|
10
|
-
writable: true,
|
11
|
-
value: void 0
|
12
|
-
});
|
13
|
-
Object.defineProperty(this, "description", {
|
14
|
-
enumerable: true,
|
15
|
-
configurable: true,
|
16
|
-
writable: true,
|
17
|
-
value: void 0
|
18
|
-
});
|
19
|
-
Object.defineProperty(this, "schema", {
|
20
|
-
enumerable: true,
|
21
|
-
configurable: true,
|
22
|
-
writable: true,
|
23
|
-
value: void 0
|
24
|
-
});
|
25
|
-
this.name = name;
|
26
|
-
this.description = description;
|
27
|
-
this.schema = new UncheckedSchema_js_1.UncheckedSchema(jsonSchema);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
exports.UncheckedStructureDefinition = UncheckedStructureDefinition;
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { StructureDefinition } from "./StructureDefinition.js";
|
2
|
-
import { UncheckedSchema } from "./UncheckedSchema.js";
|
3
|
-
export declare class UncheckedStructureDefinition<NAME extends string, STRUCTURE> implements StructureDefinition<NAME, STRUCTURE> {
|
4
|
-
name: NAME;
|
5
|
-
description?: string;
|
6
|
-
schema: UncheckedSchema<STRUCTURE>;
|
7
|
-
constructor({ name, description, jsonSchema, }: {
|
8
|
-
name: NAME;
|
9
|
-
description?: string;
|
10
|
-
jsonSchema: unknown;
|
11
|
-
});
|
12
|
-
}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import { UncheckedSchema } from "./UncheckedSchema.js";
|
2
|
-
export class UncheckedStructureDefinition {
|
3
|
-
constructor({ name, description, jsonSchema, }) {
|
4
|
-
Object.defineProperty(this, "name", {
|
5
|
-
enumerable: true,
|
6
|
-
configurable: true,
|
7
|
-
writable: true,
|
8
|
-
value: void 0
|
9
|
-
});
|
10
|
-
Object.defineProperty(this, "description", {
|
11
|
-
enumerable: true,
|
12
|
-
configurable: true,
|
13
|
-
writable: true,
|
14
|
-
value: void 0
|
15
|
-
});
|
16
|
-
Object.defineProperty(this, "schema", {
|
17
|
-
enumerable: true,
|
18
|
-
configurable: true,
|
19
|
-
writable: true,
|
20
|
-
value: void 0
|
21
|
-
});
|
22
|
-
this.name = name;
|
23
|
-
this.description = description;
|
24
|
-
this.schema = new UncheckedSchema(jsonSchema);
|
25
|
-
}
|
26
|
-
}
|
@@ -1,30 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ZodStructureDefinition = void 0;
|
4
|
-
const ZodSchema_js_1 = require("./ZodSchema.cjs");
|
5
|
-
class ZodStructureDefinition {
|
6
|
-
constructor({ name, description, schema, }) {
|
7
|
-
Object.defineProperty(this, "name", {
|
8
|
-
enumerable: true,
|
9
|
-
configurable: true,
|
10
|
-
writable: true,
|
11
|
-
value: void 0
|
12
|
-
});
|
13
|
-
Object.defineProperty(this, "description", {
|
14
|
-
enumerable: true,
|
15
|
-
configurable: true,
|
16
|
-
writable: true,
|
17
|
-
value: void 0
|
18
|
-
});
|
19
|
-
Object.defineProperty(this, "schema", {
|
20
|
-
enumerable: true,
|
21
|
-
configurable: true,
|
22
|
-
writable: true,
|
23
|
-
value: void 0
|
24
|
-
});
|
25
|
-
this.name = name;
|
26
|
-
this.description = description;
|
27
|
-
this.schema = schema instanceof ZodSchema_js_1.ZodSchema ? schema : new ZodSchema_js_1.ZodSchema(schema);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
exports.ZodStructureDefinition = ZodStructureDefinition;
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { z } from "zod";
|
2
|
-
import { StructureDefinition } from "./StructureDefinition.js";
|
3
|
-
import { ZodSchema } from "./ZodSchema.js";
|
4
|
-
export declare class ZodStructureDefinition<NAME extends string, STRUCTURE> implements StructureDefinition<NAME, STRUCTURE> {
|
5
|
-
name: NAME;
|
6
|
-
description?: string;
|
7
|
-
schema: ZodSchema<STRUCTURE>;
|
8
|
-
constructor({ name, description, schema, }: {
|
9
|
-
name: NAME;
|
10
|
-
description?: string;
|
11
|
-
schema: z.Schema<STRUCTURE> | ZodSchema<STRUCTURE>;
|
12
|
-
});
|
13
|
-
}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import { ZodSchema } from "./ZodSchema.js";
|
2
|
-
export class ZodStructureDefinition {
|
3
|
-
constructor({ name, description, schema, }) {
|
4
|
-
Object.defineProperty(this, "name", {
|
5
|
-
enumerable: true,
|
6
|
-
configurable: true,
|
7
|
-
writable: true,
|
8
|
-
value: void 0
|
9
|
-
});
|
10
|
-
Object.defineProperty(this, "description", {
|
11
|
-
enumerable: true,
|
12
|
-
configurable: true,
|
13
|
-
writable: true,
|
14
|
-
value: void 0
|
15
|
-
});
|
16
|
-
Object.defineProperty(this, "schema", {
|
17
|
-
enumerable: true,
|
18
|
-
configurable: true,
|
19
|
-
writable: true,
|
20
|
-
value: void 0
|
21
|
-
});
|
22
|
-
this.name = name;
|
23
|
-
this.description = description;
|
24
|
-
this.schema = schema instanceof ZodSchema ? schema : new ZodSchema(schema);
|
25
|
-
}
|
26
|
-
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ChatPromptValidationError = void 0;
|
4
|
-
class ChatPromptValidationError extends Error {
|
5
|
-
constructor(message) {
|
6
|
-
super(message);
|
7
|
-
this.name = "ChatPromptValidationError";
|
8
|
-
}
|
9
|
-
toJSON() {
|
10
|
-
return {
|
11
|
-
name: this.name,
|
12
|
-
message: this.message,
|
13
|
-
stack: this.stack,
|
14
|
-
};
|
15
|
-
}
|
16
|
-
}
|
17
|
-
exports.ChatPromptValidationError = ChatPromptValidationError;
|
@@ -1,24 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.validateChatPrompt = void 0;
|
4
|
-
const ChatPromptValidationError_js_1 = require("./ChatPromptValidationError.cjs");
|
5
|
-
/**
|
6
|
-
* Checks if a chat prompt is valid. Throws a `ChatPromptValidationError` if it's not.
|
7
|
-
*/
|
8
|
-
function validateChatPrompt(chatPrompt) {
|
9
|
-
const messages = chatPrompt.messages;
|
10
|
-
if (messages.length < 1) {
|
11
|
-
throw new ChatPromptValidationError_js_1.ChatPromptValidationError("ChatPrompt should have at least one message.");
|
12
|
-
}
|
13
|
-
for (let i = 0; i < messages.length; i++) {
|
14
|
-
const expectedRole = i % 2 === 0 ? "user" : "assistant";
|
15
|
-
const role = messages[i].role;
|
16
|
-
if (role !== expectedRole) {
|
17
|
-
throw new ChatPromptValidationError_js_1.ChatPromptValidationError(`Message at index ${i} should have role '${expectedRole}', but has role '${role}'.`);
|
18
|
-
}
|
19
|
-
}
|
20
|
-
if (messages.length % 2 === 0) {
|
21
|
-
throw new ChatPromptValidationError_js_1.ChatPromptValidationError("The last message must be a user message.");
|
22
|
-
}
|
23
|
-
}
|
24
|
-
exports.validateChatPrompt = validateChatPrompt;
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { ChatPromptValidationError } from "./ChatPromptValidationError.js";
|
2
|
-
/**
|
3
|
-
* Checks if a chat prompt is valid. Throws a `ChatPromptValidationError` if it's not.
|
4
|
-
*/
|
5
|
-
export function validateChatPrompt(chatPrompt) {
|
6
|
-
const messages = chatPrompt.messages;
|
7
|
-
if (messages.length < 1) {
|
8
|
-
throw new ChatPromptValidationError("ChatPrompt should have at least one message.");
|
9
|
-
}
|
10
|
-
for (let i = 0; i < messages.length; i++) {
|
11
|
-
const expectedRole = i % 2 === 0 ? "user" : "assistant";
|
12
|
-
const role = messages[i].role;
|
13
|
-
if (role !== expectedRole) {
|
14
|
-
throw new ChatPromptValidationError(`Message at index ${i} should have role '${expectedRole}', but has role '${role}'.`);
|
15
|
-
}
|
16
|
-
}
|
17
|
-
if (messages.length % 2 === 0) {
|
18
|
-
throw new ChatPromptValidationError("The last message must be a user message.");
|
19
|
-
}
|
20
|
-
}
|
File without changes
|
File without changes
|