langchain 0.0.132 → 0.0.133

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 (44) hide show
  1. package/dist/agents/chat/outputParser.cjs +2 -1
  2. package/dist/agents/chat/outputParser.js +2 -1
  3. package/dist/agents/executor.cjs +106 -7
  4. package/dist/agents/executor.d.ts +23 -0
  5. package/dist/agents/executor.js +104 -6
  6. package/dist/agents/mrkl/outputParser.cjs +2 -1
  7. package/dist/agents/mrkl/outputParser.js +2 -1
  8. package/dist/chat_models/googlevertexai.cjs +1 -1
  9. package/dist/chat_models/googlevertexai.d.ts +2 -2
  10. package/dist/chat_models/googlevertexai.js +2 -2
  11. package/dist/chat_models/ollama.cjs +8 -8
  12. package/dist/chat_models/ollama.js +8 -8
  13. package/dist/document_loaders/web/notionapi.cjs +153 -74
  14. package/dist/document_loaders/web/notionapi.d.ts +19 -10
  15. package/dist/document_loaders/web/notionapi.js +154 -75
  16. package/dist/embeddings/googlevertexai.cjs +1 -1
  17. package/dist/embeddings/googlevertexai.d.ts +2 -2
  18. package/dist/embeddings/googlevertexai.js +2 -2
  19. package/dist/experimental/multimodal_embeddings/googlevertexai.cjs +1 -1
  20. package/dist/experimental/multimodal_embeddings/googlevertexai.d.ts +2 -2
  21. package/dist/experimental/multimodal_embeddings/googlevertexai.js +2 -2
  22. package/dist/llms/googlevertexai.cjs +1 -1
  23. package/dist/llms/googlevertexai.js +2 -2
  24. package/dist/load/import_constants.cjs +1 -0
  25. package/dist/load/import_constants.js +1 -0
  26. package/dist/schema/output_parser.cjs +2 -2
  27. package/dist/schema/output_parser.js +2 -2
  28. package/dist/tools/base.cjs +26 -2
  29. package/dist/tools/base.d.ts +9 -0
  30. package/dist/tools/base.js +24 -1
  31. package/dist/types/googlevertexai-types.d.ts +8 -3
  32. package/dist/util/googlevertexai-connection.cjs +49 -15
  33. package/dist/util/googlevertexai-connection.d.ts +12 -4
  34. package/dist/util/googlevertexai-connection.js +46 -13
  35. package/dist/vectorstores/googlevertexai.cjs +550 -0
  36. package/dist/vectorstores/googlevertexai.d.ts +180 -0
  37. package/dist/vectorstores/googlevertexai.js +519 -0
  38. package/dist/vectorstores/vectara.cjs +11 -2
  39. package/dist/vectorstores/vectara.d.ts +10 -1
  40. package/dist/vectorstores/vectara.js +11 -2
  41. package/package.json +10 -2
  42. package/vectorstores/googlevertexai.cjs +1 -0
  43. package/vectorstores/googlevertexai.d.ts +1 -0
  44. package/vectorstores/googlevertexai.js +1 -0
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChatAgentOutputParser = exports.FINAL_ANSWER_ACTION = void 0;
4
4
  const types_js_1 = require("../types.cjs");
5
5
  const prompt_js_1 = require("./prompt.cjs");
6
+ const output_parser_js_1 = require("../../schema/output_parser.cjs");
6
7
  exports.FINAL_ANSWER_ACTION = "Final Answer:";
7
8
  /**
8
9
  * A class that extends the AgentActionOutputParser to parse the output of
@@ -46,7 +47,7 @@ class ChatAgentOutputParser extends types_js_1.AgentActionOutputParser {
46
47
  };
47
48
  }
48
49
  catch {
49
- throw new Error(`Unable to parse JSON response from chat agent.\n\n${text}`);
50
+ throw new output_parser_js_1.OutputParserException(`Unable to parse JSON response from chat agent.\n\n${text}`);
50
51
  }
51
52
  }
52
53
  /**
@@ -1,5 +1,6 @@
1
1
  import { AgentActionOutputParser } from "../types.js";
2
2
  import { FORMAT_INSTRUCTIONS } from "./prompt.js";
3
+ import { OutputParserException } from "../../schema/output_parser.js";
3
4
  export const FINAL_ANSWER_ACTION = "Final Answer:";
4
5
  /**
5
6
  * A class that extends the AgentActionOutputParser to parse the output of
@@ -43,7 +44,7 @@ export class ChatAgentOutputParser extends AgentActionOutputParser {
43
44
  };
44
45
  }
45
46
  catch {
46
- throw new Error(`Unable to parse JSON response from chat agent.\n\n${text}`);
47
+ throw new OutputParserException(`Unable to parse JSON response from chat agent.\n\n${text}`);
47
48
  }
48
49
  }
49
50
  /**
@@ -1,7 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AgentExecutor = void 0;
3
+ exports.AgentExecutor = exports.ExceptionTool = void 0;
4
4
  const base_js_1 = require("../chains/base.cjs");
5
+ const output_parser_js_1 = require("../schema/output_parser.cjs");
6
+ const base_js_2 = require("../tools/base.cjs");
7
+ /**
8
+ * Tool that just returns the query.
9
+ * Used for exception tracking.
10
+ */
11
+ class ExceptionTool extends base_js_2.Tool {
12
+ constructor() {
13
+ super(...arguments);
14
+ Object.defineProperty(this, "name", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: "_Exception"
19
+ });
20
+ Object.defineProperty(this, "description", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: "Exception tool"
25
+ });
26
+ }
27
+ async _call(query) {
28
+ return query;
29
+ }
30
+ }
31
+ exports.ExceptionTool = ExceptionTool;
5
32
  /**
6
33
  * A chain managing an agent using tools.
7
34
  * @augments BaseChain
@@ -51,8 +78,26 @@ class AgentExecutor extends base_js_1.BaseChain {
51
78
  writable: true,
52
79
  value: "force"
53
80
  });
81
+ /**
82
+ * How to handle errors raised by the agent's output parser.
83
+ Defaults to `False`, which raises the error.
84
+
85
+ If `true`, the error will be sent back to the LLM as an observation.
86
+ If a string, the string itself will be sent to the LLM as an observation.
87
+ If a callable function, the function will be called with the exception
88
+ as an argument, and the result of that function will be passed to the agent
89
+ as an observation.
90
+ */
91
+ Object.defineProperty(this, "handleParsingErrors", {
92
+ enumerable: true,
93
+ configurable: true,
94
+ writable: true,
95
+ value: false
96
+ });
54
97
  this.agent = input.agent;
55
98
  this.tools = input.tools;
99
+ this.handleParsingErrors =
100
+ input.handleParsingErrors ?? this.handleParsingErrors;
56
101
  if (this.agent._agentActionType() === "multi") {
57
102
  for (const tool of this.tools) {
58
103
  if (tool.returnDirect) {
@@ -94,7 +139,36 @@ class AgentExecutor extends base_js_1.BaseChain {
94
139
  return { ...returnValues, ...additional };
95
140
  };
96
141
  while (this.shouldContinue(iterations)) {
97
- const output = await this.agent.plan(steps, inputs, runManager?.getChild());
142
+ let output;
143
+ try {
144
+ output = await this.agent.plan(steps, inputs, runManager?.getChild());
145
+ }
146
+ catch (e) {
147
+ // eslint-disable-next-line no-instanceof/no-instanceof
148
+ if (e instanceof output_parser_js_1.OutputParserException) {
149
+ let observation;
150
+ if (this.handleParsingErrors === true) {
151
+ observation = "Invalid or incomplete response";
152
+ }
153
+ else if (typeof this.handleParsingErrors === "string") {
154
+ observation = this.handleParsingErrors;
155
+ }
156
+ else if (typeof this.handleParsingErrors === "function") {
157
+ observation = this.handleParsingErrors(e);
158
+ }
159
+ else {
160
+ throw e;
161
+ }
162
+ output = {
163
+ tool: "_Exception",
164
+ toolInput: observation,
165
+ log: e.message,
166
+ };
167
+ }
168
+ else {
169
+ throw e;
170
+ }
171
+ }
98
172
  // Check if the agent has finished
99
173
  if ("returnValues" in output) {
100
174
  return getOutput(output);
@@ -108,11 +182,36 @@ class AgentExecutor extends base_js_1.BaseChain {
108
182
  }
109
183
  const newSteps = await Promise.all(actions.map(async (action) => {
110
184
  await runManager?.handleAgentAction(action);
111
- const tool = toolsByName[action.tool?.toLowerCase()];
112
- const observation = tool
113
- ? await tool.call(action.toolInput, runManager?.getChild())
114
- : `${action.tool} is not a valid tool, try another one.`;
115
- return { action, observation };
185
+ const tool = action.tool === "_Exception"
186
+ ? new ExceptionTool()
187
+ : toolsByName[action.tool?.toLowerCase()];
188
+ let observation;
189
+ try {
190
+ observation = tool
191
+ ? await tool.call(action.toolInput, runManager?.getChild())
192
+ : `${action.tool} is not a valid tool, try another one.`;
193
+ }
194
+ catch (e) {
195
+ // eslint-disable-next-line no-instanceof/no-instanceof
196
+ if (e instanceof base_js_2.ToolInputParsingException) {
197
+ if (this.handleParsingErrors === true) {
198
+ observation =
199
+ "Invalid or incomplete tool input. Please try again.";
200
+ }
201
+ else if (typeof this.handleParsingErrors === "string") {
202
+ observation = this.handleParsingErrors;
203
+ }
204
+ else if (typeof this.handleParsingErrors === "function") {
205
+ observation = this.handleParsingErrors(e);
206
+ }
207
+ else {
208
+ throw e;
209
+ }
210
+ observation = await new ExceptionTool().call(observation, runManager?.getChild());
211
+ return { action, observation: observation ?? "" };
212
+ }
213
+ }
214
+ return { action, observation: observation ?? "" };
116
215
  }));
117
216
  steps.push(...newSteps);
118
217
  const lastStep = steps[steps.length - 1];
@@ -4,6 +4,8 @@ import { StoppingMethod } from "./types.js";
4
4
  import { SerializedLLMChain } from "../chains/serde.js";
5
5
  import { ChainValues } from "../schema/index.js";
6
6
  import { CallbackManagerForChainRun } from "../callbacks/manager.js";
7
+ import { OutputParserException } from "../schema/output_parser.js";
8
+ import { Tool, ToolInputParsingException } from "../tools/base.js";
7
9
  /**
8
10
  * Interface defining the structure of input data for creating an
9
11
  * AgentExecutor. It extends ChainInputs and includes additional
@@ -15,6 +17,16 @@ export interface AgentExecutorInput extends ChainInputs {
15
17
  returnIntermediateSteps?: boolean;
16
18
  maxIterations?: number;
17
19
  earlyStoppingMethod?: StoppingMethod;
20
+ handleParsingErrors?: boolean | string | ((e: OutputParserException | ToolInputParsingException) => string);
21
+ }
22
+ /**
23
+ * Tool that just returns the query.
24
+ * Used for exception tracking.
25
+ */
26
+ export declare class ExceptionTool extends Tool {
27
+ name: string;
28
+ description: string;
29
+ _call(query: string): Promise<string>;
18
30
  }
19
31
  /**
20
32
  * A chain managing an agent using tools.
@@ -28,6 +40,17 @@ export declare class AgentExecutor extends BaseChain {
28
40
  returnIntermediateSteps: boolean;
29
41
  maxIterations?: number;
30
42
  earlyStoppingMethod: StoppingMethod;
43
+ /**
44
+ * How to handle errors raised by the agent's output parser.
45
+ Defaults to `False`, which raises the error.
46
+
47
+ If `true`, the error will be sent back to the LLM as an observation.
48
+ If a string, the string itself will be sent to the LLM as an observation.
49
+ If a callable function, the function will be called with the exception
50
+ as an argument, and the result of that function will be passed to the agent
51
+ as an observation.
52
+ */
53
+ handleParsingErrors: boolean | string | ((e: OutputParserException | ToolInputParsingException) => string);
31
54
  get inputKeys(): string[];
32
55
  get outputKeys(): string[];
33
56
  constructor(input: AgentExecutorInput);
@@ -1,4 +1,30 @@
1
1
  import { BaseChain } from "../chains/base.js";
2
+ import { OutputParserException } from "../schema/output_parser.js";
3
+ import { Tool, ToolInputParsingException } from "../tools/base.js";
4
+ /**
5
+ * Tool that just returns the query.
6
+ * Used for exception tracking.
7
+ */
8
+ export class ExceptionTool extends Tool {
9
+ constructor() {
10
+ super(...arguments);
11
+ Object.defineProperty(this, "name", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: "_Exception"
16
+ });
17
+ Object.defineProperty(this, "description", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: "Exception tool"
22
+ });
23
+ }
24
+ async _call(query) {
25
+ return query;
26
+ }
27
+ }
2
28
  /**
3
29
  * A chain managing an agent using tools.
4
30
  * @augments BaseChain
@@ -48,8 +74,26 @@ export class AgentExecutor extends BaseChain {
48
74
  writable: true,
49
75
  value: "force"
50
76
  });
77
+ /**
78
+ * How to handle errors raised by the agent's output parser.
79
+ Defaults to `False`, which raises the error.
80
+
81
+ If `true`, the error will be sent back to the LLM as an observation.
82
+ If a string, the string itself will be sent to the LLM as an observation.
83
+ If a callable function, the function will be called with the exception
84
+ as an argument, and the result of that function will be passed to the agent
85
+ as an observation.
86
+ */
87
+ Object.defineProperty(this, "handleParsingErrors", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: false
92
+ });
51
93
  this.agent = input.agent;
52
94
  this.tools = input.tools;
95
+ this.handleParsingErrors =
96
+ input.handleParsingErrors ?? this.handleParsingErrors;
53
97
  if (this.agent._agentActionType() === "multi") {
54
98
  for (const tool of this.tools) {
55
99
  if (tool.returnDirect) {
@@ -91,7 +135,36 @@ export class AgentExecutor extends BaseChain {
91
135
  return { ...returnValues, ...additional };
92
136
  };
93
137
  while (this.shouldContinue(iterations)) {
94
- const output = await this.agent.plan(steps, inputs, runManager?.getChild());
138
+ let output;
139
+ try {
140
+ output = await this.agent.plan(steps, inputs, runManager?.getChild());
141
+ }
142
+ catch (e) {
143
+ // eslint-disable-next-line no-instanceof/no-instanceof
144
+ if (e instanceof OutputParserException) {
145
+ let observation;
146
+ if (this.handleParsingErrors === true) {
147
+ observation = "Invalid or incomplete response";
148
+ }
149
+ else if (typeof this.handleParsingErrors === "string") {
150
+ observation = this.handleParsingErrors;
151
+ }
152
+ else if (typeof this.handleParsingErrors === "function") {
153
+ observation = this.handleParsingErrors(e);
154
+ }
155
+ else {
156
+ throw e;
157
+ }
158
+ output = {
159
+ tool: "_Exception",
160
+ toolInput: observation,
161
+ log: e.message,
162
+ };
163
+ }
164
+ else {
165
+ throw e;
166
+ }
167
+ }
95
168
  // Check if the agent has finished
96
169
  if ("returnValues" in output) {
97
170
  return getOutput(output);
@@ -105,11 +178,36 @@ export class AgentExecutor extends BaseChain {
105
178
  }
106
179
  const newSteps = await Promise.all(actions.map(async (action) => {
107
180
  await runManager?.handleAgentAction(action);
108
- const tool = toolsByName[action.tool?.toLowerCase()];
109
- const observation = tool
110
- ? await tool.call(action.toolInput, runManager?.getChild())
111
- : `${action.tool} is not a valid tool, try another one.`;
112
- return { action, observation };
181
+ const tool = action.tool === "_Exception"
182
+ ? new ExceptionTool()
183
+ : toolsByName[action.tool?.toLowerCase()];
184
+ let observation;
185
+ try {
186
+ observation = tool
187
+ ? await tool.call(action.toolInput, runManager?.getChild())
188
+ : `${action.tool} is not a valid tool, try another one.`;
189
+ }
190
+ catch (e) {
191
+ // eslint-disable-next-line no-instanceof/no-instanceof
192
+ if (e instanceof ToolInputParsingException) {
193
+ if (this.handleParsingErrors === true) {
194
+ observation =
195
+ "Invalid or incomplete tool input. Please try again.";
196
+ }
197
+ else if (typeof this.handleParsingErrors === "string") {
198
+ observation = this.handleParsingErrors;
199
+ }
200
+ else if (typeof this.handleParsingErrors === "function") {
201
+ observation = this.handleParsingErrors(e);
202
+ }
203
+ else {
204
+ throw e;
205
+ }
206
+ observation = await new ExceptionTool().call(observation, runManager?.getChild());
207
+ return { action, observation: observation ?? "" };
208
+ }
209
+ }
210
+ return { action, observation: observation ?? "" };
113
211
  }));
114
212
  steps.push(...newSteps);
115
213
  const lastStep = steps[steps.length - 1];
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZeroShotAgentOutputParser = exports.FINAL_ANSWER_ACTION = void 0;
4
+ const output_parser_js_1 = require("../../schema/output_parser.cjs");
4
5
  const types_js_1 = require("../types.cjs");
5
6
  const prompt_js_1 = require("./prompt.cjs");
6
7
  exports.FINAL_ANSWER_ACTION = "Final Answer:";
@@ -42,7 +43,7 @@ class ZeroShotAgentOutputParser extends types_js_1.AgentActionOutputParser {
42
43
  }
43
44
  const match = /Action: ([\s\S]*?)(?:\nAction Input: ([\s\S]*?))?$/.exec(text);
44
45
  if (!match) {
45
- throw new Error(`Could not parse LLM output: ${text}`);
46
+ throw new output_parser_js_1.OutputParserException(`Could not parse LLM output: ${text}`);
46
47
  }
47
48
  return {
48
49
  tool: match[1].trim(),
@@ -1,3 +1,4 @@
1
+ import { OutputParserException } from "../../schema/output_parser.js";
1
2
  import { AgentActionOutputParser } from "../types.js";
2
3
  import { FORMAT_INSTRUCTIONS } from "./prompt.js";
3
4
  export const FINAL_ANSWER_ACTION = "Final Answer:";
@@ -39,7 +40,7 @@ export class ZeroShotAgentOutputParser extends AgentActionOutputParser {
39
40
  }
40
41
  const match = /Action: ([\s\S]*?)(?:\nAction Input: ([\s\S]*?))?$/.exec(text);
41
42
  if (!match) {
42
- throw new Error(`Could not parse LLM output: ${text}`);
43
+ throw new OutputParserException(`Could not parse LLM output: ${text}`);
43
44
  }
44
45
  return {
45
46
  tool: match[1].trim(),
@@ -158,7 +158,7 @@ class ChatGoogleVertexAI extends base_js_1.BaseChatModel {
158
158
  this.topP = fields?.topP ?? this.topP;
159
159
  this.topK = fields?.topK ?? this.topK;
160
160
  this.examples = fields?.examples ?? this.examples;
161
- this.connection = new googlevertexai_connection_js_1.GoogleVertexAIConnection({
161
+ this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({
162
162
  ...fields,
163
163
  ...this,
164
164
  }, this.caller);
@@ -1,6 +1,6 @@
1
1
  import { BaseChatModel } from "./base.js";
2
2
  import { BaseMessage, ChatGeneration, ChatMessage, ChatResult, LLMResult } from "../schema/index.js";
3
- import { GoogleVertexAIConnection } from "../util/googlevertexai-connection.js";
3
+ import { GoogleVertexAILLMConnection } from "../util/googlevertexai-connection.js";
4
4
  import { GoogleVertexAIBaseLLMInput, GoogleVertexAIBasePrediction } from "../types/googlevertexai-types.js";
5
5
  import { BaseLanguageModelCallOptions } from "../base_language/index.js";
6
6
  /**
@@ -105,7 +105,7 @@ export declare class ChatGoogleVertexAI extends BaseChatModel implements GoogleV
105
105
  topP: number;
106
106
  topK: number;
107
107
  examples: ChatExample[];
108
- connection: GoogleVertexAIConnection<BaseLanguageModelCallOptions, GoogleVertexAIChatInstance, GoogleVertexAIChatPrediction>;
108
+ connection: GoogleVertexAILLMConnection<BaseLanguageModelCallOptions, GoogleVertexAIChatInstance, GoogleVertexAIChatPrediction>;
109
109
  constructor(fields?: GoogleVertexAIChatInput);
110
110
  _combineLLMOutput(): LLMResult["llmOutput"];
111
111
  _generate(messages: BaseMessage[], options: this["ParsedCallOptions"]): Promise<ChatResult>;
@@ -1,6 +1,6 @@
1
1
  import { BaseChatModel } from "./base.js";
2
2
  import { AIMessage, ChatMessage, } from "../schema/index.js";
3
- import { GoogleVertexAIConnection } from "../util/googlevertexai-connection.js";
3
+ import { GoogleVertexAILLMConnection } from "../util/googlevertexai-connection.js";
4
4
  /**
5
5
  * Represents a chat message in the Google Vertex AI chat model.
6
6
  */
@@ -154,7 +154,7 @@ export class ChatGoogleVertexAI extends BaseChatModel {
154
154
  this.topP = fields?.topP ?? this.topP;
155
155
  this.topK = fields?.topK ?? this.topK;
156
156
  this.examples = fields?.examples ?? this.examples;
157
- this.connection = new GoogleVertexAIConnection({
157
+ this.connection = new GoogleVertexAILLMConnection({
158
158
  ...fields,
159
159
  ...this,
160
160
  }, this.caller);
@@ -177,27 +177,27 @@ class ChatOllama extends base_js_1.SimpleChatModel {
177
177
  _formatMessagesAsPrompt(messages) {
178
178
  const formattedMessages = messages
179
179
  .map((message) => {
180
- let rolePrefix;
180
+ let messageText;
181
181
  if (message._getType() === "human") {
182
- rolePrefix = "Human: ";
182
+ messageText = `[INST] ${message.content} [/INST]`;
183
183
  }
184
184
  else if (message._getType() === "ai") {
185
- rolePrefix = "Assistant: ";
185
+ messageText = message.content;
186
186
  }
187
187
  else if (message._getType() === "system") {
188
- rolePrefix = "";
188
+ messageText = `<<SYS>> ${message.content} <</SYS>>`;
189
189
  }
190
190
  else if (index_js_1.ChatMessage.isInstance(message)) {
191
- rolePrefix = `${message.role}: `;
191
+ messageText = `\n\n${message.role[0].toUpperCase()}${message.role.slice(1)}: ${message.content}`;
192
192
  }
193
193
  else {
194
194
  console.warn(`Unsupported message type passed to Ollama: "${message._getType()}"`);
195
- rolePrefix = "";
195
+ messageText = "";
196
196
  }
197
- return `${rolePrefix}${message.content}`;
197
+ return messageText;
198
198
  })
199
199
  .join("\n");
200
- return `${formattedMessages}\nAssistant: `;
200
+ return formattedMessages;
201
201
  }
202
202
  /** @ignore */
203
203
  async _call(messages, options) {
@@ -174,27 +174,27 @@ export class ChatOllama extends SimpleChatModel {
174
174
  _formatMessagesAsPrompt(messages) {
175
175
  const formattedMessages = messages
176
176
  .map((message) => {
177
- let rolePrefix;
177
+ let messageText;
178
178
  if (message._getType() === "human") {
179
- rolePrefix = "Human: ";
179
+ messageText = `[INST] ${message.content} [/INST]`;
180
180
  }
181
181
  else if (message._getType() === "ai") {
182
- rolePrefix = "Assistant: ";
182
+ messageText = message.content;
183
183
  }
184
184
  else if (message._getType() === "system") {
185
- rolePrefix = "";
185
+ messageText = `<<SYS>> ${message.content} <</SYS>>`;
186
186
  }
187
187
  else if (ChatMessage.isInstance(message)) {
188
- rolePrefix = `${message.role}: `;
188
+ messageText = `\n\n${message.role[0].toUpperCase()}${message.role.slice(1)}: ${message.content}`;
189
189
  }
190
190
  else {
191
191
  console.warn(`Unsupported message type passed to Ollama: "${message._getType()}"`);
192
- rolePrefix = "";
192
+ messageText = "";
193
193
  }
194
- return `${rolePrefix}${message.content}`;
194
+ return messageText;
195
195
  })
196
196
  .join("\n");
197
- return `${formattedMessages}\nAssistant: `;
197
+ return formattedMessages;
198
198
  }
199
199
  /** @ignore */
200
200
  async _call(messages, options) {