modelfusion 0.12.0 → 0.14.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.
Files changed (55) hide show
  1. package/README.md +5 -5
  2. package/model-function/generate-text/TextGenerationModel.d.ts +3 -3
  3. package/model-provider/cohere/CohereTextGenerationModel.cjs +5 -5
  4. package/model-provider/cohere/CohereTextGenerationModel.d.ts +3 -3
  5. package/model-provider/cohere/CohereTextGenerationModel.js +5 -5
  6. package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +4 -4
  7. package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +3 -3
  8. package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +4 -4
  9. package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +5 -5
  10. package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +3 -3
  11. package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +5 -5
  12. package/model-provider/openai/OpenAITextGenerationModel.cjs +5 -5
  13. package/model-provider/openai/OpenAITextGenerationModel.d.ts +3 -3
  14. package/model-provider/openai/OpenAITextGenerationModel.js +5 -5
  15. package/model-provider/openai/chat/OpenAIChatModel.cjs +5 -5
  16. package/model-provider/openai/chat/OpenAIChatModel.d.ts +3 -3
  17. package/model-provider/openai/chat/OpenAIChatModel.js +5 -5
  18. package/package.json +3 -3
  19. package/prompt/{AlpacaPromptMapping.cjs → AlpacaPromptFormat.cjs} +5 -5
  20. package/prompt/{AlpacaPromptMapping.d.ts → AlpacaPromptFormat.d.ts} +3 -3
  21. package/prompt/{AlpacaPromptMapping.js → AlpacaPromptFormat.js} +3 -3
  22. package/prompt/{Llama2PromptMapping.cjs → Llama2PromptFormat.cjs} +11 -8
  23. package/prompt/Llama2PromptFormat.d.ts +13 -0
  24. package/prompt/{Llama2PromptMapping.js → Llama2PromptFormat.js} +8 -5
  25. package/prompt/{OpenAIChatPromptMapping.cjs → OpenAIChatPromptFormat.cjs} +13 -7
  26. package/prompt/OpenAIChatPromptFormat.d.ts +12 -0
  27. package/prompt/{OpenAIChatPromptMapping.js → OpenAIChatPromptFormat.js} +10 -4
  28. package/prompt/PromptFormat.d.ts +14 -0
  29. package/prompt/{PromptMappingTextGenerationModel.cjs → PromptFormatTextGenerationModel.cjs} +19 -19
  30. package/prompt/{PromptMappingTextGenerationModel.d.ts → PromptFormatTextGenerationModel.d.ts} +6 -6
  31. package/prompt/{PromptMappingTextGenerationModel.js → PromptFormatTextGenerationModel.js} +17 -17
  32. package/prompt/{TextPromptMapping.cjs → TextPromptFormat.cjs} +11 -8
  33. package/prompt/TextPromptFormat.d.ts +17 -0
  34. package/prompt/{TextPromptMapping.js → TextPromptFormat.js} +8 -5
  35. package/prompt/{VicunaPromptMapping.cjs → VicunaPromptFormat.cjs} +5 -5
  36. package/prompt/{VicunaPromptMapping.d.ts → VicunaPromptFormat.d.ts} +3 -3
  37. package/prompt/{VicunaPromptMapping.js → VicunaPromptFormat.js} +3 -3
  38. package/prompt/chat/trimChatPrompt.cjs +1 -1
  39. package/prompt/chat/trimChatPrompt.d.ts +1 -1
  40. package/prompt/chat/trimChatPrompt.js +1 -1
  41. package/prompt/index.cjs +7 -7
  42. package/prompt/index.d.ts +7 -7
  43. package/prompt/index.js +7 -7
  44. package/tool/WebSearchTool.cjs +7 -28
  45. package/tool/WebSearchTool.d.ts +6 -67
  46. package/tool/WebSearchTool.js +7 -28
  47. package/tool/executeTool.cjs +1 -0
  48. package/tool/executeTool.d.ts +5 -4
  49. package/tool/executeTool.js +1 -0
  50. package/prompt/Llama2PromptMapping.d.ts +0 -10
  51. package/prompt/OpenAIChatPromptMapping.d.ts +0 -6
  52. package/prompt/PromptMapping.d.ts +0 -7
  53. package/prompt/TextPromptMapping.d.ts +0 -14
  54. /package/prompt/{PromptMapping.cjs → PromptFormat.cjs} +0 -0
  55. /package/prompt/{PromptMapping.js → PromptFormat.js} +0 -0
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChatToOpenAIChatPromptMapping = exports.InstructionToOpenAIChatPromptMapping = void 0;
3
+ exports.OpenAIChatChatPromptFormat = exports.OpenAIChatInstructionPromptFormat = void 0;
4
4
  const validateChatPrompt_js_1 = require("./chat/validateChatPrompt.cjs");
5
- const InstructionToOpenAIChatPromptMapping = () => ({
6
- map: (instruction) => {
5
+ /**
6
+ * Formats an instruction prompt as an OpenAI chat prompt.
7
+ */
8
+ const OpenAIChatInstructionPromptFormat = () => ({
9
+ format: (instruction) => {
7
10
  const messages = [];
8
11
  if (instruction.system != null) {
9
12
  messages.push({
@@ -25,9 +28,12 @@ const InstructionToOpenAIChatPromptMapping = () => ({
25
28
  },
26
29
  stopTokens: [],
27
30
  });
28
- exports.InstructionToOpenAIChatPromptMapping = InstructionToOpenAIChatPromptMapping;
29
- const ChatToOpenAIChatPromptMapping = () => ({
30
- map: (chatPrompt) => {
31
+ exports.OpenAIChatInstructionPromptFormat = OpenAIChatInstructionPromptFormat;
32
+ /**
33
+ * Formats a chat prompt as an OpenAI chat prompt.
34
+ */
35
+ const OpenAIChatChatPromptFormat = () => ({
36
+ format: (chatPrompt) => {
31
37
  (0, validateChatPrompt_js_1.validateChatPrompt)(chatPrompt);
32
38
  const messages = [];
33
39
  for (let i = 0; i < chatPrompt.length; i++) {
@@ -65,4 +71,4 @@ const ChatToOpenAIChatPromptMapping = () => ({
65
71
  },
66
72
  stopTokens: [],
67
73
  });
68
- exports.ChatToOpenAIChatPromptMapping = ChatToOpenAIChatPromptMapping;
74
+ exports.OpenAIChatChatPromptFormat = OpenAIChatChatPromptFormat;
@@ -0,0 +1,12 @@
1
+ import { OpenAIChatMessage } from "../model-provider/openai/chat/OpenAIChatMessage.js";
2
+ import { ChatPrompt } from "./chat/ChatPrompt.js";
3
+ import { InstructionPrompt } from "./InstructionPrompt.js";
4
+ import { PromptFormat } from "./PromptFormat.js";
5
+ /**
6
+ * Formats an instruction prompt as an OpenAI chat prompt.
7
+ */
8
+ export declare const OpenAIChatInstructionPromptFormat: () => PromptFormat<InstructionPrompt, Array<OpenAIChatMessage>>;
9
+ /**
10
+ * Formats a chat prompt as an OpenAI chat prompt.
11
+ */
12
+ export declare const OpenAIChatChatPromptFormat: () => PromptFormat<ChatPrompt, Array<OpenAIChatMessage>>;
@@ -1,6 +1,9 @@
1
1
  import { validateChatPrompt } from "./chat/validateChatPrompt.js";
2
- export const InstructionToOpenAIChatPromptMapping = () => ({
3
- map: (instruction) => {
2
+ /**
3
+ * Formats an instruction prompt as an OpenAI chat prompt.
4
+ */
5
+ export const OpenAIChatInstructionPromptFormat = () => ({
6
+ format: (instruction) => {
4
7
  const messages = [];
5
8
  if (instruction.system != null) {
6
9
  messages.push({
@@ -22,8 +25,11 @@ export const InstructionToOpenAIChatPromptMapping = () => ({
22
25
  },
23
26
  stopTokens: [],
24
27
  });
25
- export const ChatToOpenAIChatPromptMapping = () => ({
26
- map: (chatPrompt) => {
28
+ /**
29
+ * Formats a chat prompt as an OpenAI chat prompt.
30
+ */
31
+ export const OpenAIChatChatPromptFormat = () => ({
32
+ format: (chatPrompt) => {
27
33
  validateChatPrompt(chatPrompt);
28
34
  const messages = [];
29
35
  for (let i = 0; i < chatPrompt.length; i++) {
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Prompt formats format a source prompt into the structure of a target prompt.
3
+ */
4
+ export interface PromptFormat<SOURCE_PROMPT, TARGET_PROMPT> {
5
+ /**
6
+ * Formats the source prompt into the structure of the target prompt.
7
+ */
8
+ format(sourcePrompt: SOURCE_PROMPT): TARGET_PROMPT;
9
+ /**
10
+ * The tokens that should be used as default stop tokens.
11
+ * This is e.g. important for chat formats.
12
+ */
13
+ stopTokens: string[];
14
+ }
@@ -1,22 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PromptMappingTextGenerationModel = void 0;
4
- class PromptMappingTextGenerationModel {
5
- constructor({ model, promptMapping, }) {
3
+ exports.PromptFormatTextGenerationModel = void 0;
4
+ class PromptFormatTextGenerationModel {
5
+ constructor({ model, promptFormat, }) {
6
6
  Object.defineProperty(this, "model", {
7
7
  enumerable: true,
8
8
  configurable: true,
9
9
  writable: true,
10
10
  value: void 0
11
11
  });
12
- Object.defineProperty(this, "promptMapping", {
12
+ Object.defineProperty(this, "promptFormat", {
13
13
  enumerable: true,
14
14
  configurable: true,
15
15
  writable: true,
16
16
  value: void 0
17
17
  });
18
18
  this.model = model;
19
- this.promptMapping = promptMapping;
19
+ this.promptFormat = promptFormat;
20
20
  }
21
21
  get modelInformation() {
22
22
  return this.model.modelInformation;
@@ -35,10 +35,10 @@ class PromptMappingTextGenerationModel {
35
35
  if (originalCountPromptTokens === undefined) {
36
36
  return undefined;
37
37
  }
38
- return ((prompt) => originalCountPromptTokens(this.promptMapping.map(prompt)));
38
+ return ((prompt) => originalCountPromptTokens(this.promptFormat.format(prompt)));
39
39
  }
40
40
  generateTextResponse(prompt, options) {
41
- const mappedPrompt = this.promptMapping.map(prompt);
41
+ const mappedPrompt = this.promptFormat.format(prompt);
42
42
  return this.model.generateTextResponse(mappedPrompt, options);
43
43
  }
44
44
  extractText(response) {
@@ -50,39 +50,39 @@ class PromptMappingTextGenerationModel {
50
50
  return undefined;
51
51
  }
52
52
  return ((prompt, options) => {
53
- const mappedPrompt = this.promptMapping.map(prompt);
53
+ const mappedPrompt = this.promptFormat.format(prompt);
54
54
  return originalGenerateDeltaStreamResponse(mappedPrompt, options);
55
55
  });
56
56
  }
57
57
  get extractTextDelta() {
58
58
  return this.model.extractTextDelta;
59
59
  }
60
- mapPrompt(promptMapping) {
61
- return new PromptMappingTextGenerationModel({
62
- model: this.withStopTokens(promptMapping.stopTokens),
63
- promptMapping,
60
+ withPromptFormat(promptFormat) {
61
+ return new PromptFormatTextGenerationModel({
62
+ model: this.withStopTokens(promptFormat.stopTokens),
63
+ promptFormat,
64
64
  });
65
65
  }
66
66
  withSettings(additionalSettings) {
67
- return new PromptMappingTextGenerationModel({
67
+ return new PromptFormatTextGenerationModel({
68
68
  model: this.model.withSettings(additionalSettings),
69
- promptMapping: this.promptMapping,
69
+ promptFormat: this.promptFormat,
70
70
  });
71
71
  }
72
72
  get maxCompletionTokens() {
73
73
  return this.model.maxCompletionTokens;
74
74
  }
75
75
  withMaxCompletionTokens(maxCompletionTokens) {
76
- return new PromptMappingTextGenerationModel({
76
+ return new PromptFormatTextGenerationModel({
77
77
  model: this.model.withMaxCompletionTokens(maxCompletionTokens),
78
- promptMapping: this.promptMapping,
78
+ promptFormat: this.promptFormat,
79
79
  });
80
80
  }
81
81
  withStopTokens(stopTokens) {
82
- return new PromptMappingTextGenerationModel({
82
+ return new PromptFormatTextGenerationModel({
83
83
  model: this.model.withStopTokens(stopTokens),
84
- promptMapping: this.promptMapping,
84
+ promptFormat: this.promptFormat,
85
85
  });
86
86
  }
87
87
  }
88
- exports.PromptMappingTextGenerationModel = PromptMappingTextGenerationModel;
88
+ exports.PromptFormatTextGenerationModel = PromptFormatTextGenerationModel;
@@ -1,13 +1,13 @@
1
1
  import { FunctionOptions } from "../model-function/FunctionOptions.js";
2
2
  import { DeltaEvent } from "../model-function/generate-text/DeltaEvent.js";
3
3
  import { TextGenerationModel, TextGenerationModelSettings } from "../model-function/generate-text/TextGenerationModel.js";
4
- import { PromptMapping } from "./PromptMapping.js";
5
- export declare class PromptMappingTextGenerationModel<PROMPT, MODEL_PROMPT, RESPONSE, FULL_DELTA, SETTINGS extends TextGenerationModelSettings, MODEL extends TextGenerationModel<MODEL_PROMPT, RESPONSE, FULL_DELTA, SETTINGS>> implements TextGenerationModel<PROMPT, RESPONSE, FULL_DELTA, SETTINGS> {
4
+ import { PromptFormat } from "./PromptFormat.js";
5
+ export declare class PromptFormatTextGenerationModel<PROMPT, MODEL_PROMPT, RESPONSE, FULL_DELTA, SETTINGS extends TextGenerationModelSettings, MODEL extends TextGenerationModel<MODEL_PROMPT, RESPONSE, FULL_DELTA, SETTINGS>> implements TextGenerationModel<PROMPT, RESPONSE, FULL_DELTA, SETTINGS> {
6
6
  private readonly model;
7
- private readonly promptMapping;
8
- constructor({ model, promptMapping, }: {
7
+ private readonly promptFormat;
8
+ constructor({ model, promptFormat, }: {
9
9
  model: MODEL;
10
- promptMapping: PromptMapping<PROMPT, MODEL_PROMPT>;
10
+ promptFormat: PromptFormat<PROMPT, MODEL_PROMPT>;
11
11
  });
12
12
  get modelInformation(): import("../index.js").ModelInformation;
13
13
  get settings(): SETTINGS;
@@ -18,7 +18,7 @@ export declare class PromptMappingTextGenerationModel<PROMPT, MODEL_PROMPT, RESP
18
18
  extractText(response: RESPONSE): string;
19
19
  get generateDeltaStreamResponse(): MODEL["generateDeltaStreamResponse"] extends undefined ? undefined : (prompt: PROMPT, options: FunctionOptions<SETTINGS>) => PromiseLike<AsyncIterable<DeltaEvent<FULL_DELTA>>>;
20
20
  get extractTextDelta(): MODEL["extractTextDelta"];
21
- mapPrompt<INPUT_PROMPT>(promptMapping: PromptMapping<INPUT_PROMPT, PROMPT>): PromptMappingTextGenerationModel<INPUT_PROMPT, PROMPT, RESPONSE, FULL_DELTA, SETTINGS, this>;
21
+ withPromptFormat<INPUT_PROMPT>(promptFormat: PromptFormat<INPUT_PROMPT, PROMPT>): PromptFormatTextGenerationModel<INPUT_PROMPT, PROMPT, RESPONSE, FULL_DELTA, SETTINGS, this>;
22
22
  withSettings(additionalSettings: Partial<SETTINGS>): this;
23
23
  get maxCompletionTokens(): MODEL["maxCompletionTokens"];
24
24
  withMaxCompletionTokens(maxCompletionTokens: number): this;
@@ -1,19 +1,19 @@
1
- export class PromptMappingTextGenerationModel {
2
- constructor({ model, promptMapping, }) {
1
+ export class PromptFormatTextGenerationModel {
2
+ constructor({ model, promptFormat, }) {
3
3
  Object.defineProperty(this, "model", {
4
4
  enumerable: true,
5
5
  configurable: true,
6
6
  writable: true,
7
7
  value: void 0
8
8
  });
9
- Object.defineProperty(this, "promptMapping", {
9
+ Object.defineProperty(this, "promptFormat", {
10
10
  enumerable: true,
11
11
  configurable: true,
12
12
  writable: true,
13
13
  value: void 0
14
14
  });
15
15
  this.model = model;
16
- this.promptMapping = promptMapping;
16
+ this.promptFormat = promptFormat;
17
17
  }
18
18
  get modelInformation() {
19
19
  return this.model.modelInformation;
@@ -32,10 +32,10 @@ export class PromptMappingTextGenerationModel {
32
32
  if (originalCountPromptTokens === undefined) {
33
33
  return undefined;
34
34
  }
35
- return ((prompt) => originalCountPromptTokens(this.promptMapping.map(prompt)));
35
+ return ((prompt) => originalCountPromptTokens(this.promptFormat.format(prompt)));
36
36
  }
37
37
  generateTextResponse(prompt, options) {
38
- const mappedPrompt = this.promptMapping.map(prompt);
38
+ const mappedPrompt = this.promptFormat.format(prompt);
39
39
  return this.model.generateTextResponse(mappedPrompt, options);
40
40
  }
41
41
  extractText(response) {
@@ -47,38 +47,38 @@ export class PromptMappingTextGenerationModel {
47
47
  return undefined;
48
48
  }
49
49
  return ((prompt, options) => {
50
- const mappedPrompt = this.promptMapping.map(prompt);
50
+ const mappedPrompt = this.promptFormat.format(prompt);
51
51
  return originalGenerateDeltaStreamResponse(mappedPrompt, options);
52
52
  });
53
53
  }
54
54
  get extractTextDelta() {
55
55
  return this.model.extractTextDelta;
56
56
  }
57
- mapPrompt(promptMapping) {
58
- return new PromptMappingTextGenerationModel({
59
- model: this.withStopTokens(promptMapping.stopTokens),
60
- promptMapping,
57
+ withPromptFormat(promptFormat) {
58
+ return new PromptFormatTextGenerationModel({
59
+ model: this.withStopTokens(promptFormat.stopTokens),
60
+ promptFormat,
61
61
  });
62
62
  }
63
63
  withSettings(additionalSettings) {
64
- return new PromptMappingTextGenerationModel({
64
+ return new PromptFormatTextGenerationModel({
65
65
  model: this.model.withSettings(additionalSettings),
66
- promptMapping: this.promptMapping,
66
+ promptFormat: this.promptFormat,
67
67
  });
68
68
  }
69
69
  get maxCompletionTokens() {
70
70
  return this.model.maxCompletionTokens;
71
71
  }
72
72
  withMaxCompletionTokens(maxCompletionTokens) {
73
- return new PromptMappingTextGenerationModel({
73
+ return new PromptFormatTextGenerationModel({
74
74
  model: this.model.withMaxCompletionTokens(maxCompletionTokens),
75
- promptMapping: this.promptMapping,
75
+ promptFormat: this.promptFormat,
76
76
  });
77
77
  }
78
78
  withStopTokens(stopTokens) {
79
- return new PromptMappingTextGenerationModel({
79
+ return new PromptFormatTextGenerationModel({
80
80
  model: this.model.withStopTokens(stopTokens),
81
- promptMapping: this.promptMapping,
81
+ promptFormat: this.promptFormat,
82
82
  });
83
83
  }
84
84
  }
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChatToTextPromptMapping = exports.InstructionToTextPromptMapping = void 0;
3
+ exports.TextChatPromptFormat = exports.TextInstructionPromptFormat = void 0;
4
4
  const validateChatPrompt_js_1 = require("./chat/validateChatPrompt.cjs");
5
- const InstructionToTextPromptMapping = () => ({
5
+ /**
6
+ * Formats an instruction prompt as a basic text prompt.
7
+ */
8
+ const TextInstructionPromptFormat = () => ({
6
9
  stopTokens: [],
7
- map: (instruction) => {
10
+ format: (instruction) => {
8
11
  let text = "";
9
12
  if (instruction.system != null) {
10
13
  text += `${instruction.system}\n\n`;
@@ -16,15 +19,15 @@ const InstructionToTextPromptMapping = () => ({
16
19
  return text;
17
20
  },
18
21
  });
19
- exports.InstructionToTextPromptMapping = InstructionToTextPromptMapping;
22
+ exports.TextInstructionPromptFormat = TextInstructionPromptFormat;
20
23
  /**
21
- * A mapping from a chat prompt to a text prompt.
24
+ * Formats a chat prompt as a basic text prompt.
22
25
  *
23
26
  * @param user The label of the user in the chat.
24
27
  * @param ai The name of the AI in the chat.
25
28
  */
26
- const ChatToTextPromptMapping = ({ user, ai }) => ({
27
- map: (chatPrompt) => {
29
+ const TextChatPromptFormat = ({ user, ai }) => ({
30
+ format: (chatPrompt) => {
28
31
  (0, validateChatPrompt_js_1.validateChatPrompt)(chatPrompt);
29
32
  let text = "";
30
33
  for (let i = 0; i < chatPrompt.length; i++) {
@@ -55,4 +58,4 @@ const ChatToTextPromptMapping = ({ user, ai }) => ({
55
58
  },
56
59
  stopTokens: [`\n${user}:`],
57
60
  });
58
- exports.ChatToTextPromptMapping = ChatToTextPromptMapping;
61
+ exports.TextChatPromptFormat = TextChatPromptFormat;
@@ -0,0 +1,17 @@
1
+ import { PromptFormat } from "./PromptFormat.js";
2
+ import { InstructionPrompt } from "./InstructionPrompt.js";
3
+ import { ChatPrompt } from "./chat/ChatPrompt.js";
4
+ /**
5
+ * Formats an instruction prompt as a basic text prompt.
6
+ */
7
+ export declare const TextInstructionPromptFormat: () => PromptFormat<InstructionPrompt, string>;
8
+ /**
9
+ * Formats a chat prompt as a basic text prompt.
10
+ *
11
+ * @param user The label of the user in the chat.
12
+ * @param ai The name of the AI in the chat.
13
+ */
14
+ export declare const TextChatPromptFormat: ({ user, ai, }: {
15
+ user: string;
16
+ ai: string;
17
+ }) => PromptFormat<ChatPrompt, string>;
@@ -1,7 +1,10 @@
1
1
  import { validateChatPrompt } from "./chat/validateChatPrompt.js";
2
- export const InstructionToTextPromptMapping = () => ({
2
+ /**
3
+ * Formats an instruction prompt as a basic text prompt.
4
+ */
5
+ export const TextInstructionPromptFormat = () => ({
3
6
  stopTokens: [],
4
- map: (instruction) => {
7
+ format: (instruction) => {
5
8
  let text = "";
6
9
  if (instruction.system != null) {
7
10
  text += `${instruction.system}\n\n`;
@@ -14,13 +17,13 @@ export const InstructionToTextPromptMapping = () => ({
14
17
  },
15
18
  });
16
19
  /**
17
- * A mapping from a chat prompt to a text prompt.
20
+ * Formats a chat prompt as a basic text prompt.
18
21
  *
19
22
  * @param user The label of the user in the chat.
20
23
  * @param ai The name of the AI in the chat.
21
24
  */
22
- export const ChatToTextPromptMapping = ({ user, ai }) => ({
23
- map: (chatPrompt) => {
25
+ export const TextChatPromptFormat = ({ user, ai }) => ({
26
+ format: (chatPrompt) => {
24
27
  validateChatPrompt(chatPrompt);
25
28
  let text = "";
26
29
  for (let i = 0; i < chatPrompt.length; i++) {
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChatToVicunaPromptMapping = void 0;
3
+ exports.VicunaChatPromptFormat = void 0;
4
4
  const validateChatPrompt_js_1 = require("./chat/validateChatPrompt.cjs");
5
5
  const DEFAULT_SYSTEM_PROMPT = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.";
6
6
  /**
7
- * A mapping from a chat prompt to a Vicuna prompt.
7
+ * Formats a chat prompt as a Vicuna prompt.
8
8
  *
9
9
  * Overridding the system message in the first chat message can affect model respones.
10
10
  *
@@ -16,8 +16,8 @@ const DEFAULT_SYSTEM_PROMPT = "A chat between a curious user and an artificial i
16
16
  * ASSISTANT:
17
17
  * ```
18
18
  */
19
- const ChatToVicunaPromptMapping = () => ({
20
- map: (chatPrompt) => {
19
+ const VicunaChatPromptFormat = () => ({
20
+ format: (chatPrompt) => {
21
21
  (0, validateChatPrompt_js_1.validateChatPrompt)(chatPrompt);
22
22
  let text = "";
23
23
  for (let i = 0; i < chatPrompt.length; i++) {
@@ -52,4 +52,4 @@ const ChatToVicunaPromptMapping = () => ({
52
52
  },
53
53
  stopTokens: [`\nUSER:`],
54
54
  });
55
- exports.ChatToVicunaPromptMapping = ChatToVicunaPromptMapping;
55
+ exports.VicunaChatPromptFormat = VicunaChatPromptFormat;
@@ -1,7 +1,7 @@
1
- import { PromptMapping } from "./PromptMapping.js";
1
+ import { PromptFormat } from "./PromptFormat.js";
2
2
  import { ChatPrompt } from "./chat/ChatPrompt.js";
3
3
  /**
4
- * A mapping from a chat prompt to a Vicuna prompt.
4
+ * Formats a chat prompt as a Vicuna prompt.
5
5
  *
6
6
  * Overridding the system message in the first chat message can affect model respones.
7
7
  *
@@ -13,4 +13,4 @@ import { ChatPrompt } from "./chat/ChatPrompt.js";
13
13
  * ASSISTANT:
14
14
  * ```
15
15
  */
16
- export declare const ChatToVicunaPromptMapping: () => PromptMapping<ChatPrompt, string>;
16
+ export declare const VicunaChatPromptFormat: () => PromptFormat<ChatPrompt, string>;
@@ -1,7 +1,7 @@
1
1
  import { validateChatPrompt } from "./chat/validateChatPrompt.js";
2
2
  const DEFAULT_SYSTEM_PROMPT = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.";
3
3
  /**
4
- * A mapping from a chat prompt to a Vicuna prompt.
4
+ * Formats a chat prompt as a Vicuna prompt.
5
5
  *
6
6
  * Overridding the system message in the first chat message can affect model respones.
7
7
  *
@@ -13,8 +13,8 @@ const DEFAULT_SYSTEM_PROMPT = "A chat between a curious user and an artificial i
13
13
  * ASSISTANT:
14
14
  * ```
15
15
  */
16
- export const ChatToVicunaPromptMapping = () => ({
17
- map: (chatPrompt) => {
16
+ export const VicunaChatPromptFormat = () => ({
17
+ format: (chatPrompt) => {
18
18
  validateChatPrompt(chatPrompt);
19
19
  let text = "";
20
20
  for (let i = 0; i < chatPrompt.length; i++) {
@@ -10,7 +10,7 @@ const validateChatPrompt_js_1 = require("./validateChatPrompt.cjs");
10
10
  * When the minimal chat prompt (system message + last user message) is already too long, it will only
11
11
  * return this minimal chat prompt.
12
12
  *
13
- * @see https://modelfusion.dev/guide/function/generate-text/prompt-mapping#limiting-the-chat-length
13
+ * @see https://modelfusion.dev/guide/function/generate-text/prompt-format#limiting-the-chat-length
14
14
  */
15
15
  async function trimChatPrompt({ prompt, model, tokenLimit = model.contextWindowSize -
16
16
  (model.maxCompletionTokens ?? model.contextWindowSize / 4), }) {
@@ -8,7 +8,7 @@ import { ChatPrompt } from "./ChatPrompt.js";
8
8
  * When the minimal chat prompt (system message + last user message) is already too long, it will only
9
9
  * return this minimal chat prompt.
10
10
  *
11
- * @see https://modelfusion.dev/guide/function/generate-text/prompt-mapping#limiting-the-chat-length
11
+ * @see https://modelfusion.dev/guide/function/generate-text/prompt-format#limiting-the-chat-length
12
12
  */
13
13
  export declare function trimChatPrompt({ prompt, model, tokenLimit, }: {
14
14
  prompt: ChatPrompt;
@@ -7,7 +7,7 @@ import { validateChatPrompt } from "./validateChatPrompt.js";
7
7
  * When the minimal chat prompt (system message + last user message) is already too long, it will only
8
8
  * return this minimal chat prompt.
9
9
  *
10
- * @see https://modelfusion.dev/guide/function/generate-text/prompt-mapping#limiting-the-chat-length
10
+ * @see https://modelfusion.dev/guide/function/generate-text/prompt-format#limiting-the-chat-length
11
11
  */
12
12
  export async function trimChatPrompt({ prompt, model, tokenLimit = model.contextWindowSize -
13
13
  (model.maxCompletionTokens ?? model.contextWindowSize / 4), }) {
package/prompt/index.cjs CHANGED
@@ -14,14 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./AlpacaPromptMapping.cjs"), exports);
17
+ __exportStar(require("./AlpacaPromptFormat.cjs"), exports);
18
18
  __exportStar(require("./InstructionPrompt.cjs"), exports);
19
- __exportStar(require("./Llama2PromptMapping.cjs"), exports);
20
- __exportStar(require("./OpenAIChatPromptMapping.cjs"), exports);
21
- __exportStar(require("./PromptMapping.cjs"), exports);
22
- __exportStar(require("./PromptMappingTextGenerationModel.cjs"), exports);
23
- __exportStar(require("./TextPromptMapping.cjs"), exports);
24
- __exportStar(require("./VicunaPromptMapping.cjs"), exports);
19
+ __exportStar(require("./Llama2PromptFormat.cjs"), exports);
20
+ __exportStar(require("./OpenAIChatPromptFormat.cjs"), exports);
21
+ __exportStar(require("./PromptFormat.cjs"), exports);
22
+ __exportStar(require("./PromptFormatTextGenerationModel.cjs"), exports);
23
+ __exportStar(require("./TextPromptFormat.cjs"), exports);
24
+ __exportStar(require("./VicunaPromptFormat.cjs"), exports);
25
25
  __exportStar(require("./chat/ChatPrompt.cjs"), exports);
26
26
  __exportStar(require("./chat/trimChatPrompt.cjs"), exports);
27
27
  __exportStar(require("./chat/validateChatPrompt.cjs"), exports);
package/prompt/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export * from "./AlpacaPromptMapping.js";
1
+ export * from "./AlpacaPromptFormat.js";
2
2
  export * from "./InstructionPrompt.js";
3
- export * from "./Llama2PromptMapping.js";
4
- export * from "./OpenAIChatPromptMapping.js";
5
- export * from "./PromptMapping.js";
6
- export * from "./PromptMappingTextGenerationModel.js";
7
- export * from "./TextPromptMapping.js";
8
- export * from "./VicunaPromptMapping.js";
3
+ export * from "./Llama2PromptFormat.js";
4
+ export * from "./OpenAIChatPromptFormat.js";
5
+ export * from "./PromptFormat.js";
6
+ export * from "./PromptFormatTextGenerationModel.js";
7
+ export * from "./TextPromptFormat.js";
8
+ export * from "./VicunaPromptFormat.js";
9
9
  export * from "./chat/ChatPrompt.js";
10
10
  export * from "./chat/trimChatPrompt.js";
11
11
  export * from "./chat/validateChatPrompt.js";
package/prompt/index.js CHANGED
@@ -1,11 +1,11 @@
1
- export * from "./AlpacaPromptMapping.js";
1
+ export * from "./AlpacaPromptFormat.js";
2
2
  export * from "./InstructionPrompt.js";
3
- export * from "./Llama2PromptMapping.js";
4
- export * from "./OpenAIChatPromptMapping.js";
5
- export * from "./PromptMapping.js";
6
- export * from "./PromptMappingTextGenerationModel.js";
7
- export * from "./TextPromptMapping.js";
8
- export * from "./VicunaPromptMapping.js";
3
+ export * from "./Llama2PromptFormat.js";
4
+ export * from "./OpenAIChatPromptFormat.js";
5
+ export * from "./PromptFormat.js";
6
+ export * from "./PromptFormatTextGenerationModel.js";
7
+ export * from "./TextPromptFormat.js";
8
+ export * from "./VicunaPromptFormat.js";
9
9
  export * from "./chat/ChatPrompt.js";
10
10
  export * from "./chat/trimChatPrompt.js";
11
11
  export * from "./chat/validateChatPrompt.js";
@@ -3,9 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebSearchTool = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const Tool_js_1 = require("./Tool.cjs");
6
- const INPUT_SCHEMA = zod_1.z.object({
7
- query: zod_1.z.string(),
8
- });
9
6
  const OUTPUT_SCHEMA = zod_1.z.object({
10
7
  results: zod_1.z.array(zod_1.z.object({
11
8
  title: zod_1.z.string(),
@@ -13,39 +10,21 @@ const OUTPUT_SCHEMA = zod_1.z.object({
13
10
  snippet: zod_1.z.string(),
14
11
  })),
15
12
  });
13
+ // expose the schemas to library consumers:
14
+ const createInputSchema = (description) =>
15
+ // same structure, but with description:
16
+ zod_1.z.object({
17
+ query: zod_1.z.string().describe(description),
18
+ });
16
19
  class WebSearchTool extends Tool_js_1.Tool {
17
20
  constructor({ name, description, queryDescription = "Search query", execute, }) {
18
21
  super({
19
22
  name,
20
23
  description,
21
- inputSchema: WebSearchTool.createInputSchema(queryDescription),
24
+ inputSchema: createInputSchema(queryDescription),
22
25
  outputSchema: OUTPUT_SCHEMA,
23
26
  execute,
24
27
  });
25
- Object.defineProperty(this, "outputSchema", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: void 0
30
- });
31
- this.outputSchema = OUTPUT_SCHEMA;
32
28
  }
33
29
  }
34
30
  exports.WebSearchTool = WebSearchTool;
35
- // expose the schemas to library consumers:
36
- Object.defineProperty(WebSearchTool, "createInputSchema", {
37
- enumerable: true,
38
- configurable: true,
39
- writable: true,
40
- value: (description) =>
41
- // same structure, but with description:
42
- zod_1.z.object({
43
- query: zod_1.z.string().describe(description),
44
- })
45
- });
46
- Object.defineProperty(WebSearchTool, "createOutputSchema", {
47
- enumerable: true,
48
- configurable: true,
49
- writable: true,
50
- value: () => OUTPUT_SCHEMA
51
- });