modelfusion 0.119.1 → 0.121.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/CHANGELOG.md +32 -0
- package/README.md +5 -5
- package/core/FunctionOptions.d.ts +7 -2
- package/core/executeFunction.cjs +1 -7
- package/core/executeFunction.d.ts +2 -2
- package/core/executeFunction.js +1 -7
- package/core/executeFunctionCall.cjs +3 -2
- package/core/executeFunctionCall.d.ts +2 -2
- package/core/executeFunctionCall.js +3 -2
- package/core/getFunctionCallLogger.cjs +22 -7
- package/core/getFunctionCallLogger.js +22 -7
- package/model-function/executeStandardCall.cjs +2 -2
- package/model-function/executeStandardCall.js +2 -2
- package/model-function/executeStreamCall.cjs +2 -2
- package/model-function/executeStreamCall.js +2 -2
- package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.cjs +78 -0
- package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.d.ts +35 -0
- package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.js +72 -0
- package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.test.cjs +60 -0
- package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.test.d.ts +1 -0
- package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.test.js +58 -0
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.cjs +11 -13
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.d.ts +1 -1
- package/model-function/generate-text/prompt-template/VicunaPromptTemplate.js +11 -13
- package/model-function/generate-text/prompt-template/index.cjs +2 -1
- package/model-function/generate-text/prompt-template/index.d.ts +1 -0
- package/model-function/generate-text/prompt-template/index.js +1 -0
- package/model-provider/llamacpp/LlamaCppPrompt.cjs +35 -1
- package/model-provider/llamacpp/LlamaCppPrompt.d.ts +33 -0
- package/model-provider/llamacpp/LlamaCppPrompt.js +34 -0
- package/model-provider/ollama/OllamaCompletionModel.cjs +22 -19
- package/model-provider/ollama/OllamaCompletionModel.d.ts +13 -4
- package/model-provider/ollama/OllamaCompletionModel.js +22 -19
- package/model-provider/ollama/OllamaCompletionModel.test.cjs +3 -27
- package/model-provider/ollama/OllamaCompletionModel.test.js +3 -4
- package/model-provider/ollama/OllamaCompletionPrompt.cjs +91 -0
- package/model-provider/ollama/OllamaCompletionPrompt.d.ts +45 -0
- package/model-provider/ollama/OllamaCompletionPrompt.js +63 -0
- package/model-provider/ollama/OllamaFacade.cjs +25 -1
- package/model-provider/ollama/OllamaFacade.d.ts +1 -0
- package/model-provider/ollama/OllamaFacade.js +1 -0
- package/package.json +1 -1
- package/tool/Tool.d.ts +2 -2
- package/tool/execute-tool/executeTool.cjs +3 -2
- package/tool/execute-tool/executeTool.js +3 -2
@@ -0,0 +1,45 @@
|
|
1
|
+
import { TextGenerationPromptTemplate } from "../../model-function/generate-text/TextGenerationPromptTemplate.js";
|
2
|
+
import { TextGenerationPromptTemplateProvider } from "../../model-function/generate-text/prompt-template/PromptTemplateProvider.js";
|
3
|
+
import { OllamaCompletionPrompt } from "./OllamaCompletionModel.js";
|
4
|
+
export declare function asOllamaCompletionPromptTemplate<SOURCE_PROMPT>(promptTemplate: TextGenerationPromptTemplate<SOURCE_PROMPT, string>): TextGenerationPromptTemplate<SOURCE_PROMPT, OllamaCompletionPrompt>;
|
5
|
+
export declare function asOllamaCompletionTextPromptTemplateProvider(promptTemplateProvider: TextGenerationPromptTemplateProvider<string>): TextGenerationPromptTemplateProvider<OllamaCompletionPrompt>;
|
6
|
+
export declare const Text: TextGenerationPromptTemplateProvider<OllamaCompletionPrompt>;
|
7
|
+
/**
|
8
|
+
* Formats text, instruction or chat prompts as a Mistral instruct prompt.
|
9
|
+
*
|
10
|
+
* Note that Mistral does not support system prompts. We emulate them.
|
11
|
+
*
|
12
|
+
* Text prompt:
|
13
|
+
* ```
|
14
|
+
* <s>[INST] { instruction } [/INST]
|
15
|
+
* ```
|
16
|
+
*
|
17
|
+
* Instruction prompt when system prompt is set:
|
18
|
+
* ```
|
19
|
+
* <s>[INST] ${ system prompt } [/INST] </s>[INST] ${instruction} [/INST] ${ response prefix }
|
20
|
+
* ```
|
21
|
+
*
|
22
|
+
* Instruction prompt template when there is no system prompt:
|
23
|
+
* ```
|
24
|
+
* <s>[INST] ${ instruction } [/INST] ${ response prefix }
|
25
|
+
* ```
|
26
|
+
*
|
27
|
+
* Chat prompt when system prompt is set:
|
28
|
+
* ```
|
29
|
+
* <s>[INST] ${ system prompt } [/INST] </s> [INST] ${ user msg 1 } [/INST] ${ model response 1 } [INST] ${ user msg 2 } [/INST] ${ model response 2 } [INST] ${ user msg 3 } [/INST]
|
30
|
+
* ```
|
31
|
+
*
|
32
|
+
* Chat prompt when there is no system prompt:
|
33
|
+
* ```
|
34
|
+
* <s>[INST] ${ user msg 1 } [/INST] ${ model response 1 } </s>[INST] ${ user msg 2 } [/INST] ${ model response 2 } [INST] ${ user msg 3 } [/INST]
|
35
|
+
* ```
|
36
|
+
*
|
37
|
+
* @see https://docs.mistral.ai/models/#chat-template
|
38
|
+
*/
|
39
|
+
export declare const Mistral: TextGenerationPromptTemplateProvider<OllamaCompletionPrompt>;
|
40
|
+
export declare const ChatML: TextGenerationPromptTemplateProvider<OllamaCompletionPrompt>;
|
41
|
+
export declare const Llama2: TextGenerationPromptTemplateProvider<OllamaCompletionPrompt>;
|
42
|
+
export declare const NeuralChat: TextGenerationPromptTemplateProvider<OllamaCompletionPrompt>;
|
43
|
+
export declare const Alpaca: TextGenerationPromptTemplateProvider<OllamaCompletionPrompt>;
|
44
|
+
export declare const Synthia: TextGenerationPromptTemplateProvider<OllamaCompletionPrompt>;
|
45
|
+
export declare const Vicuna: TextGenerationPromptTemplateProvider<OllamaCompletionPrompt>;
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import * as alpacaPrompt from "../../model-function/generate-text/prompt-template/AlpacaPromptTemplate.js";
|
2
|
+
import * as chatMlPrompt from "../../model-function/generate-text/prompt-template/ChatMLPromptTemplate.js";
|
3
|
+
import * as llama2Prompt from "../../model-function/generate-text/prompt-template/Llama2PromptTemplate.js";
|
4
|
+
import * as mistralPrompt from "../../model-function/generate-text/prompt-template/MistralInstructPromptTemplate.js";
|
5
|
+
import * as neuralChatPrompt from "../../model-function/generate-text/prompt-template/NeuralChatPromptTemplate.js";
|
6
|
+
import * as synthiaPrompt from "../../model-function/generate-text/prompt-template/SynthiaPromptTemplate.js";
|
7
|
+
import * as textPrompt from "../../model-function/generate-text/prompt-template/TextPromptTemplate.js";
|
8
|
+
import * as vicunaPrompt from "../../model-function/generate-text/prompt-template/VicunaPromptTemplate.js";
|
9
|
+
export function asOllamaCompletionPromptTemplate(promptTemplate) {
|
10
|
+
return {
|
11
|
+
format: (prompt) => ({
|
12
|
+
prompt: promptTemplate.format(prompt),
|
13
|
+
}),
|
14
|
+
stopSequences: promptTemplate.stopSequences,
|
15
|
+
};
|
16
|
+
}
|
17
|
+
export function asOllamaCompletionTextPromptTemplateProvider(promptTemplateProvider) {
|
18
|
+
return {
|
19
|
+
text: () => asOllamaCompletionPromptTemplate(promptTemplateProvider.text()),
|
20
|
+
instruction: () => asOllamaCompletionPromptTemplate(promptTemplateProvider.instruction()),
|
21
|
+
chat: () => asOllamaCompletionPromptTemplate(promptTemplateProvider.chat()),
|
22
|
+
};
|
23
|
+
}
|
24
|
+
export const Text = asOllamaCompletionTextPromptTemplateProvider(textPrompt);
|
25
|
+
/**
|
26
|
+
* Formats text, instruction or chat prompts as a Mistral instruct prompt.
|
27
|
+
*
|
28
|
+
* Note that Mistral does not support system prompts. We emulate them.
|
29
|
+
*
|
30
|
+
* Text prompt:
|
31
|
+
* ```
|
32
|
+
* <s>[INST] { instruction } [/INST]
|
33
|
+
* ```
|
34
|
+
*
|
35
|
+
* Instruction prompt when system prompt is set:
|
36
|
+
* ```
|
37
|
+
* <s>[INST] ${ system prompt } [/INST] </s>[INST] ${instruction} [/INST] ${ response prefix }
|
38
|
+
* ```
|
39
|
+
*
|
40
|
+
* Instruction prompt template when there is no system prompt:
|
41
|
+
* ```
|
42
|
+
* <s>[INST] ${ instruction } [/INST] ${ response prefix }
|
43
|
+
* ```
|
44
|
+
*
|
45
|
+
* Chat prompt when system prompt is set:
|
46
|
+
* ```
|
47
|
+
* <s>[INST] ${ system prompt } [/INST] </s> [INST] ${ user msg 1 } [/INST] ${ model response 1 } [INST] ${ user msg 2 } [/INST] ${ model response 2 } [INST] ${ user msg 3 } [/INST]
|
48
|
+
* ```
|
49
|
+
*
|
50
|
+
* Chat prompt when there is no system prompt:
|
51
|
+
* ```
|
52
|
+
* <s>[INST] ${ user msg 1 } [/INST] ${ model response 1 } </s>[INST] ${ user msg 2 } [/INST] ${ model response 2 } [INST] ${ user msg 3 } [/INST]
|
53
|
+
* ```
|
54
|
+
*
|
55
|
+
* @see https://docs.mistral.ai/models/#chat-template
|
56
|
+
*/
|
57
|
+
export const Mistral = asOllamaCompletionTextPromptTemplateProvider(mistralPrompt);
|
58
|
+
export const ChatML = asOllamaCompletionTextPromptTemplateProvider(chatMlPrompt);
|
59
|
+
export const Llama2 = asOllamaCompletionTextPromptTemplateProvider(llama2Prompt);
|
60
|
+
export const NeuralChat = asOllamaCompletionTextPromptTemplateProvider(neuralChatPrompt);
|
61
|
+
export const Alpaca = asOllamaCompletionTextPromptTemplateProvider(alpacaPrompt);
|
62
|
+
export const Synthia = asOllamaCompletionTextPromptTemplateProvider(synthiaPrompt);
|
63
|
+
export const Vicuna = asOllamaCompletionTextPromptTemplateProvider(vicunaPrompt);
|
@@ -1,6 +1,29 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.TextEmbedder = exports.ChatTextGenerator = exports.CompletionTextGenerator = exports.Api = void 0;
|
26
|
+
exports.prompt = exports.TextEmbedder = exports.ChatTextGenerator = exports.CompletionTextGenerator = exports.Api = void 0;
|
4
27
|
const OllamaApiConfiguration_js_1 = require("./OllamaApiConfiguration.cjs");
|
5
28
|
const OllamaChatModel_js_1 = require("./OllamaChatModel.cjs");
|
6
29
|
const OllamaCompletionModel_js_1 = require("./OllamaCompletionModel.cjs");
|
@@ -25,3 +48,4 @@ function TextEmbedder(settings) {
|
|
25
48
|
return new OllamaTextEmbeddingModel_js_1.OllamaTextEmbeddingModel(settings);
|
26
49
|
}
|
27
50
|
exports.TextEmbedder = TextEmbedder;
|
51
|
+
exports.prompt = __importStar(require("./OllamaCompletionPrompt.cjs"));
|
@@ -12,3 +12,4 @@ export declare function CompletionTextGenerator<CONTEXT_WINDOW_SIZE extends numb
|
|
12
12
|
export declare function ChatTextGenerator(settings: OllamaChatModelSettings): OllamaChatModel;
|
13
13
|
export declare function TextEmbedder(settings: OllamaTextEmbeddingModelSettings): OllamaTextEmbeddingModel;
|
14
14
|
export { OllamaChatMessage as ChatMessage, OllamaChatPrompt as ChatPrompt, } from "./OllamaChatModel.js";
|
15
|
+
export * as prompt from "./OllamaCompletionPrompt.js";
|
package/package.json
CHANGED
package/tool/Tool.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { FunctionOptions } from "../core/FunctionOptions.js";
|
1
|
+
import { FunctionCallOptions, FunctionOptions } from "../core/FunctionOptions.js";
|
2
2
|
import { JsonSchemaProducer } from "../core/schema/JsonSchemaProducer.js";
|
3
3
|
import { Schema } from "../core/schema/Schema.js";
|
4
4
|
import { ToolDefinition } from "./ToolDefinition.js";
|
@@ -28,7 +28,7 @@ export declare class Tool<NAME extends string, PARAMETERS, RESULT> implements To
|
|
28
28
|
/**
|
29
29
|
* The actual execution function of the tool.
|
30
30
|
*/
|
31
|
-
readonly execute: (args: PARAMETERS, options
|
31
|
+
readonly execute: (args: PARAMETERS, options: FunctionCallOptions) => PromiseLike<RESULT>;
|
32
32
|
constructor({ name, description, parameters, returnType, execute, }: {
|
33
33
|
name: NAME;
|
34
34
|
description: string;
|
@@ -32,7 +32,7 @@ async function doExecuteTool(tool, args, options) {
|
|
32
32
|
const metadata = {
|
33
33
|
functionType: "execute-tool",
|
34
34
|
callId: `call-${(0, nanoid_1.nanoid)()}`,
|
35
|
-
parentCallId: options?.
|
35
|
+
parentCallId: options?.callId,
|
36
36
|
runId: run?.runId,
|
37
37
|
sessionId: run?.sessionId,
|
38
38
|
userId: run?.userId,
|
@@ -47,11 +47,12 @@ async function doExecuteTool(tool, args, options) {
|
|
47
47
|
startTimestamp: durationMeasurement.startDate,
|
48
48
|
});
|
49
49
|
const result = await (0, runSafe_js_1.runSafe)(() => tool.execute(args, {
|
50
|
+
functionType: metadata.functionType,
|
51
|
+
callId: metadata.callId,
|
50
52
|
functionId: options?.functionId,
|
51
53
|
logging: options?.logging,
|
52
54
|
observers: options?.observers,
|
53
55
|
run,
|
54
|
-
parentCallId: metadata.callId,
|
55
56
|
}));
|
56
57
|
const finishMetadata = {
|
57
58
|
...metadata,
|
@@ -28,7 +28,7 @@ async function doExecuteTool(tool, args, options) {
|
|
28
28
|
const metadata = {
|
29
29
|
functionType: "execute-tool",
|
30
30
|
callId: `call-${createId()}`,
|
31
|
-
parentCallId: options?.
|
31
|
+
parentCallId: options?.callId,
|
32
32
|
runId: run?.runId,
|
33
33
|
sessionId: run?.sessionId,
|
34
34
|
userId: run?.userId,
|
@@ -43,11 +43,12 @@ async function doExecuteTool(tool, args, options) {
|
|
43
43
|
startTimestamp: durationMeasurement.startDate,
|
44
44
|
});
|
45
45
|
const result = await runSafe(() => tool.execute(args, {
|
46
|
+
functionType: metadata.functionType,
|
47
|
+
callId: metadata.callId,
|
46
48
|
functionId: options?.functionId,
|
47
49
|
logging: options?.logging,
|
48
50
|
observers: options?.observers,
|
49
51
|
run,
|
50
|
-
parentCallId: metadata.callId,
|
51
52
|
}));
|
52
53
|
const finishMetadata = {
|
53
54
|
...metadata,
|