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.
Files changed (45) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +5 -5
  3. package/core/FunctionOptions.d.ts +7 -2
  4. package/core/executeFunction.cjs +1 -7
  5. package/core/executeFunction.d.ts +2 -2
  6. package/core/executeFunction.js +1 -7
  7. package/core/executeFunctionCall.cjs +3 -2
  8. package/core/executeFunctionCall.d.ts +2 -2
  9. package/core/executeFunctionCall.js +3 -2
  10. package/core/getFunctionCallLogger.cjs +22 -7
  11. package/core/getFunctionCallLogger.js +22 -7
  12. package/model-function/executeStandardCall.cjs +2 -2
  13. package/model-function/executeStandardCall.js +2 -2
  14. package/model-function/executeStreamCall.cjs +2 -2
  15. package/model-function/executeStreamCall.js +2 -2
  16. package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.cjs +78 -0
  17. package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.d.ts +35 -0
  18. package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.js +72 -0
  19. package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.test.cjs +60 -0
  20. package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.test.d.ts +1 -0
  21. package/model-function/generate-text/prompt-template/SynthiaPromptTemplate.test.js +58 -0
  22. package/model-function/generate-text/prompt-template/VicunaPromptTemplate.cjs +11 -13
  23. package/model-function/generate-text/prompt-template/VicunaPromptTemplate.d.ts +1 -1
  24. package/model-function/generate-text/prompt-template/VicunaPromptTemplate.js +11 -13
  25. package/model-function/generate-text/prompt-template/index.cjs +2 -1
  26. package/model-function/generate-text/prompt-template/index.d.ts +1 -0
  27. package/model-function/generate-text/prompt-template/index.js +1 -0
  28. package/model-provider/llamacpp/LlamaCppPrompt.cjs +35 -1
  29. package/model-provider/llamacpp/LlamaCppPrompt.d.ts +33 -0
  30. package/model-provider/llamacpp/LlamaCppPrompt.js +34 -0
  31. package/model-provider/ollama/OllamaCompletionModel.cjs +22 -19
  32. package/model-provider/ollama/OllamaCompletionModel.d.ts +13 -4
  33. package/model-provider/ollama/OllamaCompletionModel.js +22 -19
  34. package/model-provider/ollama/OllamaCompletionModel.test.cjs +3 -27
  35. package/model-provider/ollama/OllamaCompletionModel.test.js +3 -4
  36. package/model-provider/ollama/OllamaCompletionPrompt.cjs +91 -0
  37. package/model-provider/ollama/OllamaCompletionPrompt.d.ts +45 -0
  38. package/model-provider/ollama/OllamaCompletionPrompt.js +63 -0
  39. package/model-provider/ollama/OllamaFacade.cjs +25 -1
  40. package/model-provider/ollama/OllamaFacade.d.ts +1 -0
  41. package/model-provider/ollama/OllamaFacade.js +1 -0
  42. package/package.json +1 -1
  43. package/tool/Tool.d.ts +2 -2
  44. package/tool/execute-tool/executeTool.cjs +3 -2
  45. package/tool/execute-tool/executeTool.js +3 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.121.0 - 2024-01-09
4
+
5
+ ### Added
6
+
7
+ - Synthia prompt template
8
+
9
+ ### Changed
10
+
11
+ - **breaking change**: Renamed `parentCallId` function parameter to `callId` to enable options pass-through.
12
+ - Better output filtering for `detailed-object` log format (e.g. via `modelfusion.setLogFormat("detailed-object")`)
13
+
14
+ ## v0.120.0 - 2024-01-09
15
+
16
+ ### Added
17
+
18
+ - `OllamaCompletionModel` supports setting the prompt template in the settings. Prompt formats are available under `ollama.prompt.*`. You can then call `.withTextPrompt()`, `.withInstructionPrompt()` or `.withChatPrompt()` to use a standardized prompt.
19
+
20
+ ```ts
21
+ const model = ollama
22
+ .CompletionTextGenerator({
23
+ model: "mistral",
24
+ promptTemplate: ollama.prompt.Mistral,
25
+ raw: true, // required when using custom prompt template
26
+ maxGenerationTokens: 120,
27
+ })
28
+ .withTextPrompt();
29
+ ```
30
+
31
+ ### Removed
32
+
33
+ - **breaking change**: removed `.withTextPromptTemplate` on `OllamaCompletionModel`.
34
+
3
35
  ## v0.119.1 - 2024-01-08
4
36
 
5
37
  ### Fixed
package/README.md CHANGED
@@ -473,13 +473,13 @@ const textStream = await streamText(
473
473
 
474
474
  | Prompt Template | Text Prompt | Instruction Prompt | Chat Prompt |
475
475
  | ---------------- | ----------- | ------------------ | ----------- |
476
- | OpenAI Chat | ✅ | ✅ | |
477
- | Llama 2 | ✅ | ✅ | ✅ |
476
+ | Alpaca | ✅ | ✅ | |
478
477
  | ChatML | ✅ | ✅ | ✅ |
479
- | NeuralChat | ✅ | ✅ | ✅ |
478
+ | Llama 2 | ✅ | ✅ | ✅ |
480
479
  | Mistral Instruct | ✅ | ✅ | ✅ |
481
- | Alpaca | ✅ | ✅ | |
482
- | Vicuna | | | ✅ |
480
+ | NeuralChat | ✅ | ✅ | |
481
+ | Synthia | | | ✅ |
482
+ | Vicuna | ✅ | ✅ | ✅ |
483
483
  | Generic Text | ✅ | ✅ | ✅ |
484
484
 
485
485
  ### [Image Generation Prompt Templates](https://modelfusion.dev/guide/function/generate-image/prompt-format)
@@ -31,14 +31,19 @@ export type FunctionOptions = {
31
31
  run?: Run;
32
32
  /**
33
33
  * Unique identifier of the call id of the parent function. Used in events and logging.
34
+ *
35
+ * It has the same name as the `callId` in `FunctionCallOptions` to allow for easy
36
+ * propagation of the call id.
37
+ *
38
+ * However, in the `FunctionOptions`, it is the call ID for the parent call, and it is optional.
34
39
  */
35
- parentCallId?: string | undefined;
40
+ callId?: string | undefined;
36
41
  };
37
42
  /**
38
43
  * Extended options that are passed to models when functions are called. They are passed
39
44
  * into e.g. API providers to create custom headers.
40
45
  */
41
- export type FunctionCallOptions = Omit<FunctionOptions, "parentCallId"> & {
46
+ export type FunctionCallOptions = Omit<FunctionOptions, "callId"> & {
42
47
  functionType: string;
43
48
  callId: string;
44
49
  };
@@ -7,13 +7,7 @@ async function executeFunction(fn, input, options) {
7
7
  options,
8
8
  input,
9
9
  functionType: "execute-function",
10
- execute: async (options) => fn(input, {
11
- // omit functionId
12
- logging: options?.logging,
13
- observers: options?.observers,
14
- run: options?.run,
15
- parentCallId: options?.parentCallId,
16
- }),
10
+ execute: async (options) => fn(input, options),
17
11
  });
18
12
  }
19
13
  exports.executeFunction = executeFunction;
@@ -1,2 +1,2 @@
1
- import { FunctionOptions } from "./FunctionOptions.js";
2
- export declare function executeFunction<INPUT, OUTPUT>(fn: (input: INPUT, options?: FunctionOptions) => PromiseLike<OUTPUT>, input: INPUT, options?: FunctionOptions): Promise<OUTPUT>;
1
+ import { FunctionCallOptions, FunctionOptions } from "./FunctionOptions.js";
2
+ export declare function executeFunction<INPUT, OUTPUT>(fn: (input: INPUT, options: FunctionCallOptions) => PromiseLike<OUTPUT>, input: INPUT, options?: FunctionOptions): Promise<OUTPUT>;
@@ -4,12 +4,6 @@ export async function executeFunction(fn, input, options) {
4
4
  options,
5
5
  input,
6
6
  functionType: "execute-function",
7
- execute: async (options) => fn(input, {
8
- // omit functionId
9
- logging: options?.logging,
10
- observers: options?.observers,
11
- run: options?.run,
12
- parentCallId: options?.parentCallId,
13
- }),
7
+ execute: async (options) => fn(input, options),
14
8
  });
15
9
  }
@@ -25,7 +25,7 @@ async function executeFunctionCall({ options, input, functionType, execute, inpu
25
25
  const startMetadata = {
26
26
  functionType,
27
27
  callId: `call-${(0, nanoid_1.nanoid)()}`,
28
- parentCallId: options?.parentCallId,
28
+ parentCallId: options?.callId,
29
29
  runId: run?.runId,
30
30
  sessionId: run?.sessionId,
31
31
  userId: run?.userId,
@@ -39,11 +39,12 @@ async function executeFunctionCall({ options, input, functionType, execute, inpu
39
39
  ...startMetadata,
40
40
  });
41
41
  const result = await (0, runSafe_js_1.runSafe)(() => execute({
42
+ functionType,
42
43
  functionId: options?.functionId,
44
+ callId: startMetadata.callId,
43
45
  logging: options?.logging,
44
46
  observers: options?.observers,
45
47
  run,
46
- parentCallId: startMetadata.callId,
47
48
  }));
48
49
  const finishMetadata = {
49
50
  eventType: "finished",
@@ -1,10 +1,10 @@
1
- import { FunctionOptions } from "./FunctionOptions.js";
1
+ import { FunctionCallOptions, FunctionOptions } from "./FunctionOptions.js";
2
2
  import { FunctionEvent } from "./FunctionEvent.js";
3
3
  export declare function executeFunctionCall<VALUE>({ options, input, functionType, execute, inputPropertyName, outputPropertyName, }: {
4
4
  options?: FunctionOptions;
5
5
  input: unknown;
6
6
  functionType: FunctionEvent["functionType"];
7
- execute: (options?: FunctionOptions) => PromiseLike<VALUE>;
7
+ execute: (options: FunctionCallOptions) => PromiseLike<VALUE>;
8
8
  inputPropertyName?: string;
9
9
  outputPropertyName?: string;
10
10
  }): Promise<VALUE>;
@@ -22,7 +22,7 @@ export async function executeFunctionCall({ options, input, functionType, execut
22
22
  const startMetadata = {
23
23
  functionType,
24
24
  callId: `call-${createId()}`,
25
- parentCallId: options?.parentCallId,
25
+ parentCallId: options?.callId,
26
26
  runId: run?.runId,
27
27
  sessionId: run?.sessionId,
28
28
  userId: run?.userId,
@@ -36,11 +36,12 @@ export async function executeFunctionCall({ options, input, functionType, execut
36
36
  ...startMetadata,
37
37
  });
38
38
  const result = await runSafe(() => execute({
39
+ functionType,
39
40
  functionId: options?.functionId,
41
+ callId: startMetadata.callId,
40
42
  logging: options?.logging,
41
43
  observers: options?.observers,
42
44
  run,
43
- parentCallId: startMetadata.callId,
44
45
  }));
45
46
  const finishMetadata = {
46
47
  eventType: "finished",
@@ -51,15 +51,30 @@ const detailedObjectObserver = {
51
51
  if (obj instanceof Date || typeof obj === "string") {
52
52
  return obj;
53
53
  }
54
+ if (Array.isArray(obj)) {
55
+ return obj.map((item) => cleanObject(item));
56
+ }
54
57
  if (obj !== null && typeof obj === "object") {
55
58
  return Object.fromEntries(Object.entries(obj)
56
- .filter(([_, v] // eslint-disable-line @typescript-eslint/no-unused-vars
57
- ) => v !== undefined && // filter all undefined properties
58
- !(v instanceof Buffer) // remove all buffers
59
- )
60
- .map(([k, v]) => [k, cleanObject(v)])
61
- .filter(([_, v]) => v !== undefined) // eslint-disable-line @typescript-eslint/no-unused-vars
62
- );
59
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
60
+ .map(([k, v]) => {
61
+ if (v === undefined) {
62
+ return [k, undefined];
63
+ }
64
+ else if (v instanceof Buffer) {
65
+ return [k, "omitted<Buffer>"];
66
+ }
67
+ else if (Array.isArray(v) &&
68
+ v.length > 20 &&
69
+ v.every((v) => typeof v === "number")) {
70
+ return [k, "omitted<Array<number>>"];
71
+ }
72
+ else {
73
+ return [k, cleanObject(v)];
74
+ }
75
+ })
76
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
77
+ .filter(([_, v]) => v !== undefined));
63
78
  }
64
79
  return obj;
65
80
  }
@@ -47,15 +47,30 @@ const detailedObjectObserver = {
47
47
  if (obj instanceof Date || typeof obj === "string") {
48
48
  return obj;
49
49
  }
50
+ if (Array.isArray(obj)) {
51
+ return obj.map((item) => cleanObject(item));
52
+ }
50
53
  if (obj !== null && typeof obj === "object") {
51
54
  return Object.fromEntries(Object.entries(obj)
52
- .filter(([_, v] // eslint-disable-line @typescript-eslint/no-unused-vars
53
- ) => v !== undefined && // filter all undefined properties
54
- !(v instanceof Buffer) // remove all buffers
55
- )
56
- .map(([k, v]) => [k, cleanObject(v)])
57
- .filter(([_, v]) => v !== undefined) // eslint-disable-line @typescript-eslint/no-unused-vars
58
- );
55
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
56
+ .map(([k, v]) => {
57
+ if (v === undefined) {
58
+ return [k, undefined];
59
+ }
60
+ else if (v instanceof Buffer) {
61
+ return [k, "omitted<Buffer>"];
62
+ }
63
+ else if (Array.isArray(v) &&
64
+ v.length > 20 &&
65
+ v.every((v) => typeof v === "number")) {
66
+ return [k, "omitted<Array<number>>"];
67
+ }
68
+ else {
69
+ return [k, cleanObject(v)];
70
+ }
71
+ })
72
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
73
+ .filter(([_, v]) => v !== undefined));
59
74
  }
60
75
  return obj;
61
76
  }
@@ -27,7 +27,7 @@ async function executeStandardCall({ model, options, input, functionType, genera
27
27
  const startMetadata = {
28
28
  functionType,
29
29
  callId: `call-${(0, nanoid_1.nanoid)()}`,
30
- parentCallId: options?.parentCallId,
30
+ parentCallId: options?.callId,
31
31
  runId: run?.runId,
32
32
  sessionId: run?.sessionId,
33
33
  userId: run?.userId,
@@ -43,7 +43,7 @@ async function executeStandardCall({ model, options, input, functionType, genera
43
43
  ...startMetadata,
44
44
  });
45
45
  const result = await (0, runSafe_js_1.runSafe)(() => generateResponse({
46
- functionType: startMetadata.functionType,
46
+ functionType,
47
47
  functionId: options?.functionId,
48
48
  callId: startMetadata.callId,
49
49
  logging: options?.logging,
@@ -24,7 +24,7 @@ export async function executeStandardCall({ model, options, input, functionType,
24
24
  const startMetadata = {
25
25
  functionType,
26
26
  callId: `call-${createId()}`,
27
- parentCallId: options?.parentCallId,
27
+ parentCallId: options?.callId,
28
28
  runId: run?.runId,
29
29
  sessionId: run?.sessionId,
30
30
  userId: run?.userId,
@@ -40,7 +40,7 @@ export async function executeStandardCall({ model, options, input, functionType,
40
40
  ...startMetadata,
41
41
  });
42
42
  const result = await runSafe(() => generateResponse({
43
- functionType: startMetadata.functionType,
43
+ functionType,
44
44
  functionId: options?.functionId,
45
45
  callId: startMetadata.callId,
46
46
  logging: options?.logging,
@@ -28,7 +28,7 @@ async function executeStreamCall({ model, options, input, functionType, startStr
28
28
  const startMetadata = {
29
29
  functionType,
30
30
  callId: `call-${(0, nanoid_1.nanoid)()}`,
31
- parentCallId: options?.parentCallId,
31
+ parentCallId: options?.callId,
32
32
  runId: run?.runId,
33
33
  sessionId: run?.sessionId,
34
34
  userId: run?.userId,
@@ -45,7 +45,7 @@ async function executeStreamCall({ model, options, input, functionType, startStr
45
45
  });
46
46
  const result = await (0, runSafe_js_1.runSafe)(async () => {
47
47
  const deltaIterable = await startStream({
48
- functionType: startMetadata.functionType,
48
+ functionType,
49
49
  functionId: options?.functionId,
50
50
  callId: startMetadata.callId,
51
51
  logging: options?.logging,
@@ -25,7 +25,7 @@ export async function executeStreamCall({ model, options, input, functionType, s
25
25
  const startMetadata = {
26
26
  functionType,
27
27
  callId: `call-${createId()}`,
28
- parentCallId: options?.parentCallId,
28
+ parentCallId: options?.callId,
29
29
  runId: run?.runId,
30
30
  sessionId: run?.sessionId,
31
31
  userId: run?.userId,
@@ -42,7 +42,7 @@ export async function executeStreamCall({ model, options, input, functionType, s
42
42
  });
43
43
  const result = await runSafe(async () => {
44
44
  const deltaIterable = await startStream({
45
- functionType: startMetadata.functionType,
45
+ functionType,
46
46
  functionId: options?.functionId,
47
47
  callId: startMetadata.callId,
48
48
  logging: options?.logging,
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chat = exports.instruction = exports.text = void 0;
4
+ const ContentPart_js_1 = require("./ContentPart.cjs");
5
+ const InvalidPromptError_js_1 = require("./InvalidPromptError.cjs");
6
+ /**
7
+ * Formats a text prompt as a Synthia text prompt.
8
+ *
9
+ * Synthia prompt template:
10
+ * ```
11
+ * USER: text
12
+ * ASSISTANT:
13
+ * ```
14
+ */
15
+ const text = () => ({
16
+ stopSequences: [],
17
+ format: (prompt) => `USER: ${prompt}\nASSISTANT: `,
18
+ });
19
+ exports.text = text;
20
+ /**
21
+ * Formats an instruction prompt as a Synthia prompt.
22
+ *
23
+ * Synthia prompt template:
24
+ * ```
25
+ * SYSTEM: system message
26
+ * USER: instruction
27
+ * ASSISTANT: response prefix
28
+ * ```
29
+ */
30
+ const instruction = () => ({
31
+ stopSequences: [`\nUSER:`],
32
+ format(prompt) {
33
+ let text = prompt.system != null ? `SYSTEM: ${prompt.system}\n` : "";
34
+ text += `USER: ${(0, ContentPart_js_1.validateContentIsString)(prompt.instruction, prompt)}\n`;
35
+ text += `ASSISTANT: ${prompt.responsePrefix ?? ""}`;
36
+ return text;
37
+ },
38
+ });
39
+ exports.instruction = instruction;
40
+ /**
41
+ * Formats a chat prompt as a Synthia prompt.
42
+ *
43
+ * Synthia prompt template:
44
+ * ```
45
+ * SYSTEM: system message
46
+ * USER: user message
47
+ * ASSISTANT: assistant message
48
+ * ```
49
+ */
50
+ const chat = () => ({
51
+ format(prompt) {
52
+ let text = prompt.system != null ? `SYSTEM: ${prompt.system}\n` : "";
53
+ for (const { role, content } of prompt.messages) {
54
+ switch (role) {
55
+ case "user": {
56
+ text += `USER: ${(0, ContentPart_js_1.validateContentIsString)(content, prompt)}\n`;
57
+ break;
58
+ }
59
+ case "assistant": {
60
+ text += `ASSISTANT: ${(0, ContentPart_js_1.validateContentIsString)(content, prompt)}\n`;
61
+ break;
62
+ }
63
+ case "tool": {
64
+ throw new InvalidPromptError_js_1.InvalidPromptError("Tool messages are not supported.", prompt);
65
+ }
66
+ default: {
67
+ const _exhaustiveCheck = role;
68
+ throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
69
+ }
70
+ }
71
+ }
72
+ // Assistant message prefix:
73
+ text += `ASSISTANT: `;
74
+ return text;
75
+ },
76
+ stopSequences: [`\nUSER:`],
77
+ });
78
+ exports.chat = chat;
@@ -0,0 +1,35 @@
1
+ import { TextGenerationPromptTemplate } from "../TextGenerationPromptTemplate.js";
2
+ import { ChatPrompt } from "./ChatPrompt.js";
3
+ import { InstructionPrompt } from "./InstructionPrompt.js";
4
+ /**
5
+ * Formats a text prompt as a Synthia text prompt.
6
+ *
7
+ * Synthia prompt template:
8
+ * ```
9
+ * USER: text
10
+ * ASSISTANT:
11
+ * ```
12
+ */
13
+ export declare const text: () => TextGenerationPromptTemplate<string, string>;
14
+ /**
15
+ * Formats an instruction prompt as a Synthia prompt.
16
+ *
17
+ * Synthia prompt template:
18
+ * ```
19
+ * SYSTEM: system message
20
+ * USER: instruction
21
+ * ASSISTANT: response prefix
22
+ * ```
23
+ */
24
+ export declare const instruction: () => TextGenerationPromptTemplate<InstructionPrompt, string>;
25
+ /**
26
+ * Formats a chat prompt as a Synthia prompt.
27
+ *
28
+ * Synthia prompt template:
29
+ * ```
30
+ * SYSTEM: system message
31
+ * USER: user message
32
+ * ASSISTANT: assistant message
33
+ * ```
34
+ */
35
+ export declare const chat: () => TextGenerationPromptTemplate<ChatPrompt, string>;
@@ -0,0 +1,72 @@
1
+ import { validateContentIsString } from "./ContentPart.js";
2
+ import { InvalidPromptError } from "./InvalidPromptError.js";
3
+ /**
4
+ * Formats a text prompt as a Synthia text prompt.
5
+ *
6
+ * Synthia prompt template:
7
+ * ```
8
+ * USER: text
9
+ * ASSISTANT:
10
+ * ```
11
+ */
12
+ export const text = () => ({
13
+ stopSequences: [],
14
+ format: (prompt) => `USER: ${prompt}\nASSISTANT: `,
15
+ });
16
+ /**
17
+ * Formats an instruction prompt as a Synthia prompt.
18
+ *
19
+ * Synthia prompt template:
20
+ * ```
21
+ * SYSTEM: system message
22
+ * USER: instruction
23
+ * ASSISTANT: response prefix
24
+ * ```
25
+ */
26
+ export const instruction = () => ({
27
+ stopSequences: [`\nUSER:`],
28
+ format(prompt) {
29
+ let text = prompt.system != null ? `SYSTEM: ${prompt.system}\n` : "";
30
+ text += `USER: ${validateContentIsString(prompt.instruction, prompt)}\n`;
31
+ text += `ASSISTANT: ${prompt.responsePrefix ?? ""}`;
32
+ return text;
33
+ },
34
+ });
35
+ /**
36
+ * Formats a chat prompt as a Synthia prompt.
37
+ *
38
+ * Synthia prompt template:
39
+ * ```
40
+ * SYSTEM: system message
41
+ * USER: user message
42
+ * ASSISTANT: assistant message
43
+ * ```
44
+ */
45
+ export const chat = () => ({
46
+ format(prompt) {
47
+ let text = prompt.system != null ? `SYSTEM: ${prompt.system}\n` : "";
48
+ for (const { role, content } of prompt.messages) {
49
+ switch (role) {
50
+ case "user": {
51
+ text += `USER: ${validateContentIsString(content, prompt)}\n`;
52
+ break;
53
+ }
54
+ case "assistant": {
55
+ text += `ASSISTANT: ${validateContentIsString(content, prompt)}\n`;
56
+ break;
57
+ }
58
+ case "tool": {
59
+ throw new InvalidPromptError("Tool messages are not supported.", prompt);
60
+ }
61
+ default: {
62
+ const _exhaustiveCheck = role;
63
+ throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
64
+ }
65
+ }
66
+ }
67
+ // Assistant message prefix:
68
+ text += `ASSISTANT: `;
69
+ return text;
70
+ },
71
+ stopSequences: [`\nUSER:`],
72
+ });
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const SynthiaPromptTemplate_js_1 = require("./SynthiaPromptTemplate.cjs");
4
+ describe("text prompt", () => {
5
+ it("should format prompt", () => {
6
+ const prompt = (0, SynthiaPromptTemplate_js_1.text)().format("prompt");
7
+ expect(prompt).toMatchSnapshot();
8
+ });
9
+ });
10
+ describe("instruction prompt", () => {
11
+ it("should format prompt with instruction", () => {
12
+ const prompt = (0, SynthiaPromptTemplate_js_1.instruction)().format({
13
+ instruction: "instruction",
14
+ });
15
+ expect(prompt).toMatchSnapshot();
16
+ });
17
+ it("should format prompt with system and instruction", () => {
18
+ const prompt = (0, SynthiaPromptTemplate_js_1.instruction)().format({
19
+ system: "system",
20
+ instruction: "instruction",
21
+ });
22
+ expect(prompt).toMatchSnapshot();
23
+ });
24
+ it("should format prompt with instruction and response prefix", () => {
25
+ const prompt = (0, SynthiaPromptTemplate_js_1.instruction)().format({
26
+ instruction: "instruction",
27
+ responsePrefix: "response prefix",
28
+ });
29
+ expect(prompt).toMatchSnapshot();
30
+ });
31
+ });
32
+ describe("chat prompt", () => {
33
+ it("should format prompt with user message", () => {
34
+ const prompt = (0, SynthiaPromptTemplate_js_1.chat)().format({
35
+ messages: [{ role: "user", content: "user message" }],
36
+ });
37
+ expect(prompt).toMatchSnapshot();
38
+ });
39
+ it("should format prompt with user-assistant-user messages", () => {
40
+ const prompt = (0, SynthiaPromptTemplate_js_1.chat)().format({
41
+ messages: [
42
+ { role: "user", content: "1st user message" },
43
+ { role: "assistant", content: "assistant message" },
44
+ { role: "user", content: "2nd user message" },
45
+ ],
46
+ });
47
+ expect(prompt).toMatchSnapshot();
48
+ });
49
+ it("should format prompt with system message and user-assistant-user messages", () => {
50
+ const prompt = (0, SynthiaPromptTemplate_js_1.chat)().format({
51
+ system: "you are a chatbot",
52
+ messages: [
53
+ { role: "user", content: "1st user message" },
54
+ { role: "assistant", content: "assistant message" },
55
+ { role: "user", content: "2nd user message" },
56
+ ],
57
+ });
58
+ expect(prompt).toMatchSnapshot();
59
+ });
60
+ });
@@ -0,0 +1,58 @@
1
+ import { chat, instruction, text } from "./SynthiaPromptTemplate.js";
2
+ describe("text prompt", () => {
3
+ it("should format prompt", () => {
4
+ const prompt = text().format("prompt");
5
+ expect(prompt).toMatchSnapshot();
6
+ });
7
+ });
8
+ describe("instruction prompt", () => {
9
+ it("should format prompt with instruction", () => {
10
+ const prompt = instruction().format({
11
+ instruction: "instruction",
12
+ });
13
+ expect(prompt).toMatchSnapshot();
14
+ });
15
+ it("should format prompt with system and instruction", () => {
16
+ const prompt = instruction().format({
17
+ system: "system",
18
+ instruction: "instruction",
19
+ });
20
+ expect(prompt).toMatchSnapshot();
21
+ });
22
+ it("should format prompt with instruction and response prefix", () => {
23
+ const prompt = instruction().format({
24
+ instruction: "instruction",
25
+ responsePrefix: "response prefix",
26
+ });
27
+ expect(prompt).toMatchSnapshot();
28
+ });
29
+ });
30
+ describe("chat prompt", () => {
31
+ it("should format prompt with user message", () => {
32
+ const prompt = chat().format({
33
+ messages: [{ role: "user", content: "user message" }],
34
+ });
35
+ expect(prompt).toMatchSnapshot();
36
+ });
37
+ it("should format prompt with user-assistant-user messages", () => {
38
+ const prompt = chat().format({
39
+ messages: [
40
+ { role: "user", content: "1st user message" },
41
+ { role: "assistant", content: "assistant message" },
42
+ { role: "user", content: "2nd user message" },
43
+ ],
44
+ });
45
+ expect(prompt).toMatchSnapshot();
46
+ });
47
+ it("should format prompt with system message and user-assistant-user messages", () => {
48
+ const prompt = chat().format({
49
+ system: "you are a chatbot",
50
+ messages: [
51
+ { role: "user", content: "1st user message" },
52
+ { role: "assistant", content: "assistant message" },
53
+ { role: "user", content: "2nd user message" },
54
+ ],
55
+ });
56
+ expect(prompt).toMatchSnapshot();
57
+ });
58
+ });