langchain 0.0.185 → 0.0.187

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 (60) hide show
  1. package/dist/agents/openai/index.cjs +2 -1
  2. package/dist/agents/openai/index.js +2 -1
  3. package/dist/callbacks/handlers/llmonitor.cjs +31 -17
  4. package/dist/callbacks/handlers/llmonitor.js +31 -17
  5. package/dist/chains/combine_docs_chain.cjs +1 -1
  6. package/dist/chains/combine_docs_chain.js +1 -1
  7. package/dist/chains/llm_chain.cjs +52 -7
  8. package/dist/chains/llm_chain.d.ts +20 -12
  9. package/dist/chains/llm_chain.js +53 -8
  10. package/dist/chat_models/ollama.cjs +8 -0
  11. package/dist/chat_models/ollama.d.ts +3 -0
  12. package/dist/chat_models/ollama.js +8 -0
  13. package/dist/chat_models/openai.cjs +3 -0
  14. package/dist/chat_models/openai.js +3 -0
  15. package/dist/document_loaders/fs/unstructured.d.ts +1 -5
  16. package/dist/embeddings/ollama.d.ts +1 -1
  17. package/dist/experimental/chat_models/ollama_functions.cjs +140 -0
  18. package/dist/experimental/chat_models/ollama_functions.d.ts +76 -0
  19. package/dist/experimental/chat_models/ollama_functions.js +136 -0
  20. package/dist/llms/ollama.cjs +8 -0
  21. package/dist/llms/ollama.d.ts +3 -0
  22. package/dist/llms/ollama.js +8 -0
  23. package/dist/llms/openai.cjs +1 -1
  24. package/dist/llms/openai.js +1 -1
  25. package/dist/load/import_map.cjs +3 -1
  26. package/dist/load/import_map.d.ts +1 -0
  27. package/dist/load/import_map.js +1 -0
  28. package/dist/memory/buffer_token_memory.cjs +92 -0
  29. package/dist/memory/buffer_token_memory.d.ts +41 -0
  30. package/dist/memory/buffer_token_memory.js +88 -0
  31. package/dist/memory/index.cjs +3 -1
  32. package/dist/memory/index.d.ts +1 -0
  33. package/dist/memory/index.js +1 -0
  34. package/dist/output_parsers/index.cjs +3 -1
  35. package/dist/output_parsers/index.d.ts +1 -0
  36. package/dist/output_parsers/index.js +1 -0
  37. package/dist/output_parsers/openai_functions.cjs +3 -3
  38. package/dist/output_parsers/openai_functions.js +3 -3
  39. package/dist/output_parsers/openai_tools.cjs +53 -0
  40. package/dist/output_parsers/openai_tools.d.ts +22 -0
  41. package/dist/output_parsers/openai_tools.js +49 -0
  42. package/dist/prompts/base.cjs +1 -1
  43. package/dist/prompts/base.d.ts +2 -1
  44. package/dist/prompts/base.js +1 -1
  45. package/dist/prompts/chat.cjs +1 -1
  46. package/dist/prompts/chat.js +1 -1
  47. package/dist/schema/index.cjs +2 -2
  48. package/dist/schema/index.d.ts +4 -6
  49. package/dist/schema/index.js +2 -2
  50. package/dist/schema/runnable/base.d.ts +2 -2
  51. package/dist/util/ollama.cjs +10 -12
  52. package/dist/util/ollama.d.ts +3 -0
  53. package/dist/util/ollama.js +10 -12
  54. package/dist/util/types.cjs +5 -0
  55. package/dist/util/types.d.ts +4 -0
  56. package/dist/util/types.js +4 -0
  57. package/experimental/chat_models/ollama_functions.cjs +1 -0
  58. package/experimental/chat_models/ollama_functions.d.ts +1 -0
  59. package/experimental/chat_models/ollama_functions.js +1 -0
  60. package/package.json +13 -4
@@ -0,0 +1,88 @@
1
+ import { getBufferString, } from "./base.js";
2
+ import { BaseChatMemory } from "./chat_memory.js";
3
+ /**
4
+ * Class that represents a conversation chat memory with a token buffer.
5
+ * It extends the `BaseChatMemory` class and implements the
6
+ * `ConversationTokenBufferMemoryInput` interface.
7
+ */
8
+ export class ConversationTokenBufferMemory extends BaseChatMemory {
9
+ constructor(fields) {
10
+ super(fields);
11
+ Object.defineProperty(this, "humanPrefix", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: "Human"
16
+ });
17
+ Object.defineProperty(this, "aiPrefix", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: "AI"
22
+ });
23
+ Object.defineProperty(this, "memoryKey", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: "history"
28
+ });
29
+ Object.defineProperty(this, "maxTokenLimit", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: 2000
34
+ }); // Default max token limit of 2000 which can be overridden
35
+ Object.defineProperty(this, "llm", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ this.llm = fields.llm;
42
+ this.humanPrefix = fields?.humanPrefix ?? this.humanPrefix;
43
+ this.aiPrefix = fields?.aiPrefix ?? this.aiPrefix;
44
+ this.memoryKey = fields?.memoryKey ?? this.memoryKey;
45
+ this.maxTokenLimit = fields?.maxTokenLimit ?? this.maxTokenLimit;
46
+ }
47
+ get memoryKeys() {
48
+ return [this.memoryKey];
49
+ }
50
+ /**
51
+ * Loads the memory variables. It takes an `InputValues` object as a
52
+ * parameter and returns a `Promise` that resolves with a
53
+ * `MemoryVariables` object.
54
+ * @param _values `InputValues` object.
55
+ * @returns A `Promise` that resolves with a `MemoryVariables` object.
56
+ */
57
+ async loadMemoryVariables(_values) {
58
+ const messages = await this.chatHistory.getMessages();
59
+ if (this.returnMessages) {
60
+ const result = {
61
+ [this.memoryKey]: messages,
62
+ };
63
+ return result;
64
+ }
65
+ const result = {
66
+ [this.memoryKey]: getBufferString(messages, this.humanPrefix, this.aiPrefix),
67
+ };
68
+ return result;
69
+ }
70
+ /**
71
+ * Saves the context from this conversation to buffer. If the amount
72
+ * of tokens required to save the buffer exceeds MAX_TOKEN_LIMIT,
73
+ * prune it.
74
+ */
75
+ async saveContext(inputValues, outputValues) {
76
+ await super.saveContext(inputValues, outputValues);
77
+ // Prune buffer if it exceeds the max token limit set for this instance.
78
+ const buffer = await this.chatHistory.getMessages();
79
+ let currBufferLength = await this.llm.getNumTokens(getBufferString(buffer, this.humanPrefix, this.aiPrefix));
80
+ if (currBufferLength > this.maxTokenLimit) {
81
+ const prunedMemory = [];
82
+ while (currBufferLength > this.maxTokenLimit) {
83
+ prunedMemory.push(buffer.shift());
84
+ currBufferLength = await this.llm.getNumTokens(getBufferString(buffer, this.humanPrefix, this.aiPrefix));
85
+ }
86
+ }
87
+ }
88
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConversationSummaryBufferMemory = exports.CombinedMemory = exports.ENTITY_MEMORY_CONVERSATION_TEMPLATE = exports.EntityMemory = exports.VectorStoreRetrieverMemory = exports.MotorheadMemory = exports.ChatMessageHistory = exports.BaseChatMemory = exports.BufferWindowMemory = exports.BaseConversationSummaryMemory = exports.ConversationSummaryMemory = exports.getBufferString = exports.getOutputValue = exports.getInputValue = exports.BaseMemory = exports.BufferMemory = void 0;
3
+ exports.ConversationTokenBufferMemory = exports.ConversationSummaryBufferMemory = exports.CombinedMemory = exports.ENTITY_MEMORY_CONVERSATION_TEMPLATE = exports.EntityMemory = exports.VectorStoreRetrieverMemory = exports.MotorheadMemory = exports.ChatMessageHistory = exports.BaseChatMemory = exports.BufferWindowMemory = exports.BaseConversationSummaryMemory = exports.ConversationSummaryMemory = exports.getBufferString = exports.getOutputValue = exports.getInputValue = exports.BaseMemory = exports.BufferMemory = void 0;
4
4
  var buffer_memory_js_1 = require("./buffer_memory.cjs");
5
5
  Object.defineProperty(exports, "BufferMemory", { enumerable: true, get: function () { return buffer_memory_js_1.BufferMemory; } });
6
6
  var base_js_1 = require("./base.cjs");
@@ -29,3 +29,5 @@ var combined_memory_js_1 = require("./combined_memory.cjs");
29
29
  Object.defineProperty(exports, "CombinedMemory", { enumerable: true, get: function () { return combined_memory_js_1.CombinedMemory; } });
30
30
  var summary_buffer_js_1 = require("./summary_buffer.cjs");
31
31
  Object.defineProperty(exports, "ConversationSummaryBufferMemory", { enumerable: true, get: function () { return summary_buffer_js_1.ConversationSummaryBufferMemory; } });
32
+ var buffer_token_memory_js_1 = require("./buffer_token_memory.cjs");
33
+ Object.defineProperty(exports, "ConversationTokenBufferMemory", { enumerable: true, get: function () { return buffer_token_memory_js_1.ConversationTokenBufferMemory; } });
@@ -10,3 +10,4 @@ export { EntityMemory } from "./entity_memory.js";
10
10
  export { ENTITY_MEMORY_CONVERSATION_TEMPLATE } from "./prompt.js";
11
11
  export { type CombinedMemoryInput, CombinedMemory } from "./combined_memory.js";
12
12
  export { ConversationSummaryBufferMemory, type ConversationSummaryBufferMemoryInput, } from "./summary_buffer.js";
13
+ export { ConversationTokenBufferMemory, type ConversationTokenBufferMemoryInput, } from "./buffer_token_memory.js";
@@ -10,3 +10,4 @@ export { EntityMemory } from "./entity_memory.js";
10
10
  export { ENTITY_MEMORY_CONVERSATION_TEMPLATE } from "./prompt.js";
11
11
  export { CombinedMemory } from "./combined_memory.js";
12
12
  export { ConversationSummaryBufferMemory, } from "./summary_buffer.js";
13
+ export { ConversationTokenBufferMemory, } from "./buffer_token_memory.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.AsymmetricStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
3
+ exports.JsonOutputToolsParser = exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.AsymmetricStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
4
4
  var list_js_1 = require("./list.cjs");
5
5
  Object.defineProperty(exports, "ListOutputParser", { enumerable: true, get: function () { return list_js_1.ListOutputParser; } });
6
6
  Object.defineProperty(exports, "CommaSeparatedListOutputParser", { enumerable: true, get: function () { return list_js_1.CommaSeparatedListOutputParser; } });
@@ -22,3 +22,5 @@ var openai_functions_js_1 = require("../output_parsers/openai_functions.cjs");
22
22
  Object.defineProperty(exports, "OutputFunctionsParser", { enumerable: true, get: function () { return openai_functions_js_1.OutputFunctionsParser; } });
23
23
  Object.defineProperty(exports, "JsonOutputFunctionsParser", { enumerable: true, get: function () { return openai_functions_js_1.JsonOutputFunctionsParser; } });
24
24
  Object.defineProperty(exports, "JsonKeyOutputFunctionsParser", { enumerable: true, get: function () { return openai_functions_js_1.JsonKeyOutputFunctionsParser; } });
25
+ var openai_tools_js_1 = require("../output_parsers/openai_tools.cjs");
26
+ Object.defineProperty(exports, "JsonOutputToolsParser", { enumerable: true, get: function () { return openai_tools_js_1.JsonOutputToolsParser; } });
@@ -6,3 +6,4 @@ export { CombiningOutputParser } from "./combining.js";
6
6
  export { RouterOutputParser, type RouterOutputParserInput } from "./router.js";
7
7
  export { CustomListOutputParser } from "./list.js";
8
8
  export { type FunctionParameters, OutputFunctionsParser, JsonOutputFunctionsParser, JsonKeyOutputFunctionsParser, } from "../output_parsers/openai_functions.js";
9
+ export { type ParsedToolCall, JsonOutputToolsParser, } from "../output_parsers/openai_tools.js";
@@ -6,3 +6,4 @@ export { CombiningOutputParser } from "./combining.js";
6
6
  export { RouterOutputParser } from "./router.js";
7
7
  export { CustomListOutputParser } from "./list.js";
8
8
  export { OutputFunctionsParser, JsonOutputFunctionsParser, JsonKeyOutputFunctionsParser, } from "../output_parsers/openai_functions.js";
9
+ export { JsonOutputToolsParser, } from "../output_parsers/openai_tools.js";
@@ -18,7 +18,7 @@ class OutputFunctionsParser extends output_parser_js_1.BaseLLMOutputParser {
18
18
  enumerable: true,
19
19
  configurable: true,
20
20
  writable: true,
21
- value: ["langchain", "chains", "openai_functions"]
21
+ value: ["langchain", "output_parsers"]
22
22
  });
23
23
  Object.defineProperty(this, "lc_serializable", {
24
24
  enumerable: true,
@@ -75,7 +75,7 @@ class JsonOutputFunctionsParser extends output_parser_js_1.BaseCumulativeTransfo
75
75
  enumerable: true,
76
76
  configurable: true,
77
77
  writable: true,
78
- value: ["langchain", "chains", "openai_functions"]
78
+ value: ["langchain", "output_parsers"]
79
79
  });
80
80
  Object.defineProperty(this, "lc_serializable", {
81
81
  enumerable: true,
@@ -166,7 +166,7 @@ class JsonKeyOutputFunctionsParser extends output_parser_js_1.BaseLLMOutputParse
166
166
  enumerable: true,
167
167
  configurable: true,
168
168
  writable: true,
169
- value: ["langchain", "chains", "openai_functions"]
169
+ value: ["langchain", "output_parsers"]
170
170
  });
171
171
  Object.defineProperty(this, "lc_serializable", {
172
172
  enumerable: true,
@@ -15,7 +15,7 @@ export class OutputFunctionsParser extends BaseLLMOutputParser {
15
15
  enumerable: true,
16
16
  configurable: true,
17
17
  writable: true,
18
- value: ["langchain", "chains", "openai_functions"]
18
+ value: ["langchain", "output_parsers"]
19
19
  });
20
20
  Object.defineProperty(this, "lc_serializable", {
21
21
  enumerable: true,
@@ -71,7 +71,7 @@ export class JsonOutputFunctionsParser extends BaseCumulativeTransformOutputPars
71
71
  enumerable: true,
72
72
  configurable: true,
73
73
  writable: true,
74
- value: ["langchain", "chains", "openai_functions"]
74
+ value: ["langchain", "output_parsers"]
75
75
  });
76
76
  Object.defineProperty(this, "lc_serializable", {
77
77
  enumerable: true,
@@ -161,7 +161,7 @@ export class JsonKeyOutputFunctionsParser extends BaseLLMOutputParser {
161
161
  enumerable: true,
162
162
  configurable: true,
163
163
  writable: true,
164
- value: ["langchain", "chains", "openai_functions"]
164
+ value: ["langchain", "output_parsers"]
165
165
  });
166
166
  Object.defineProperty(this, "lc_serializable", {
167
167
  enumerable: true,
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonOutputToolsParser = void 0;
4
+ const output_parser_js_1 = require("../schema/output_parser.cjs");
5
+ /**
6
+ * Class for parsing the output of an LLM into a JSON object. Uses an
7
+ * instance of `OutputToolsParser` to parse the output.
8
+ */
9
+ class JsonOutputToolsParser extends output_parser_js_1.BaseLLMOutputParser {
10
+ constructor() {
11
+ super(...arguments);
12
+ Object.defineProperty(this, "lc_namespace", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: ["langchain", "output_parsers"]
17
+ });
18
+ Object.defineProperty(this, "lc_serializable", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: true
23
+ });
24
+ }
25
+ static lc_name() {
26
+ return "JsonOutputToolsParser";
27
+ }
28
+ /**
29
+ * Parses the output and returns a JSON object. If `argsOnly` is true,
30
+ * only the arguments of the function call are returned.
31
+ * @param generations The output of the LLM to parse.
32
+ * @returns A JSON object representation of the function call or its arguments.
33
+ */
34
+ async parseResult(generations) {
35
+ const toolCalls = generations[0].message.additional_kwargs.tool_calls;
36
+ if (!toolCalls) {
37
+ throw new Error(`No tools_call in message ${JSON.stringify(generations)}`);
38
+ }
39
+ const clonedToolCalls = JSON.parse(JSON.stringify(toolCalls));
40
+ const parsedToolCalls = [];
41
+ for (const toolCall of clonedToolCalls) {
42
+ if (toolCall.function !== undefined) {
43
+ const functionArgs = toolCall.function.arguments;
44
+ parsedToolCalls.push({
45
+ name: toolCall.function.name,
46
+ arguments: JSON.parse(functionArgs),
47
+ });
48
+ }
49
+ }
50
+ return parsedToolCalls;
51
+ }
52
+ }
53
+ exports.JsonOutputToolsParser = JsonOutputToolsParser;
@@ -0,0 +1,22 @@
1
+ import { BaseLLMOutputParser } from "../schema/output_parser.js";
2
+ import type { ChatGeneration } from "../schema/index.js";
3
+ export type ParsedToolCall = {
4
+ name: string;
5
+ arguments: Record<string, any>;
6
+ };
7
+ /**
8
+ * Class for parsing the output of an LLM into a JSON object. Uses an
9
+ * instance of `OutputToolsParser` to parse the output.
10
+ */
11
+ export declare class JsonOutputToolsParser extends BaseLLMOutputParser<ParsedToolCall[]> {
12
+ static lc_name(): string;
13
+ lc_namespace: string[];
14
+ lc_serializable: boolean;
15
+ /**
16
+ * Parses the output and returns a JSON object. If `argsOnly` is true,
17
+ * only the arguments of the function call are returned.
18
+ * @param generations The output of the LLM to parse.
19
+ * @returns A JSON object representation of the function call or its arguments.
20
+ */
21
+ parseResult(generations: ChatGeneration[]): Promise<ParsedToolCall[]>;
22
+ }
@@ -0,0 +1,49 @@
1
+ import { BaseLLMOutputParser } from "../schema/output_parser.js";
2
+ /**
3
+ * Class for parsing the output of an LLM into a JSON object. Uses an
4
+ * instance of `OutputToolsParser` to parse the output.
5
+ */
6
+ export class JsonOutputToolsParser extends BaseLLMOutputParser {
7
+ constructor() {
8
+ super(...arguments);
9
+ Object.defineProperty(this, "lc_namespace", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: ["langchain", "output_parsers"]
14
+ });
15
+ Object.defineProperty(this, "lc_serializable", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: true
20
+ });
21
+ }
22
+ static lc_name() {
23
+ return "JsonOutputToolsParser";
24
+ }
25
+ /**
26
+ * Parses the output and returns a JSON object. If `argsOnly` is true,
27
+ * only the arguments of the function call are returned.
28
+ * @param generations The output of the LLM to parse.
29
+ * @returns A JSON object representation of the function call or its arguments.
30
+ */
31
+ async parseResult(generations) {
32
+ const toolCalls = generations[0].message.additional_kwargs.tool_calls;
33
+ if (!toolCalls) {
34
+ throw new Error(`No tools_call in message ${JSON.stringify(generations)}`);
35
+ }
36
+ const clonedToolCalls = JSON.parse(JSON.stringify(toolCalls));
37
+ const parsedToolCalls = [];
38
+ for (const toolCall of clonedToolCalls) {
39
+ if (toolCall.function !== undefined) {
40
+ const functionArgs = toolCall.function.arguments;
41
+ parsedToolCalls.push({
42
+ name: toolCall.function.name,
43
+ arguments: JSON.parse(functionArgs),
44
+ });
45
+ }
46
+ }
47
+ return parsedToolCalls;
48
+ }
49
+ }
@@ -12,7 +12,7 @@ const index_js_2 = require("../schema/runnable/index.cjs");
12
12
  */
13
13
  class StringPromptValue extends index_js_1.BasePromptValue {
14
14
  constructor(value) {
15
- super(...arguments);
15
+ super({ value });
16
16
  Object.defineProperty(this, "lc_namespace", {
17
17
  enumerable: true,
18
18
  configurable: true,
@@ -5,7 +5,8 @@ import { SerializedBasePromptTemplate } from "./serde.js";
5
5
  import { SerializedFields } from "../load/map_keys.js";
6
6
  import { Runnable } from "../schema/runnable/index.js";
7
7
  import { BaseCallbackConfig } from "../callbacks/manager.js";
8
- export type TypedPromptInputValues<RunInput> = InputValues<Extract<keyof RunInput, string> | (string & Record<never, never>)>;
8
+ import type { StringWithAutocomplete } from "../util/types.js";
9
+ export type TypedPromptInputValues<RunInput> = InputValues<StringWithAutocomplete<Extract<keyof RunInput, string>>>;
9
10
  /**
10
11
  * Represents a prompt value as a string. It extends the BasePromptValue
11
12
  * class and overrides the toString and toChatMessages methods.
@@ -9,7 +9,7 @@ import { Runnable } from "../schema/runnable/index.js";
9
9
  */
10
10
  export class StringPromptValue extends BasePromptValue {
11
11
  constructor(value) {
12
- super(...arguments);
12
+ super({ value });
13
13
  Object.defineProperty(this, "lc_namespace", {
14
14
  enumerable: true,
15
15
  configurable: true,
@@ -53,7 +53,7 @@ class ChatPromptValue extends index_js_1.BasePromptValue {
53
53
  // eslint-disable-next-line no-param-reassign
54
54
  fields = { messages: fields };
55
55
  }
56
- super(...arguments);
56
+ super(fields);
57
57
  Object.defineProperty(this, "lc_namespace", {
58
58
  enumerable: true,
59
59
  configurable: true,
@@ -49,7 +49,7 @@ export class ChatPromptValue extends BasePromptValue {
49
49
  // eslint-disable-next-line no-param-reassign
50
50
  fields = { messages: fields };
51
51
  }
52
- super(...arguments);
52
+ super(fields);
53
53
  Object.defineProperty(this, "lc_namespace", {
54
54
  enumerable: true,
55
55
  configurable: true,
@@ -396,8 +396,8 @@ class ToolMessage extends BaseMessage {
396
396
  }
397
397
  exports.ToolMessage = ToolMessage;
398
398
  /**
399
- * Represents a chunk of a function message, which can be concatenated
400
- * with other function message chunks.
399
+ * Represents a chunk of a tool message, which can be concatenated
400
+ * with other tool message chunks.
401
401
  */
402
402
  class ToolMessageChunk extends BaseMessageChunk {
403
403
  constructor(fields) {
@@ -1,6 +1,7 @@
1
1
  import type { OpenAI as OpenAIClient } from "openai";
2
2
  import { Document } from "../document.js";
3
3
  import { Serializable } from "../load/serializable.js";
4
+ import type { StringWithAutocomplete } from "../util/types.js";
4
5
  export declare const RUN_KEY = "__run";
5
6
  export type Example = Record<string, string>;
6
7
  export type InputValues<K extends string = string> = Record<K, any>;
@@ -231,8 +232,8 @@ export declare class ToolMessage extends BaseMessage {
231
232
  _getType(): MessageType;
232
233
  }
233
234
  /**
234
- * Represents a chunk of a function message, which can be concatenated
235
- * with other function message chunks.
235
+ * Represents a chunk of a tool message, which can be concatenated
236
+ * with other tool message chunks.
236
237
  */
237
238
  export declare class ToolMessageChunk extends BaseMessageChunk {
238
239
  tool_call_id: string;
@@ -252,10 +253,7 @@ export declare class ChatMessage extends BaseMessage implements ChatMessageField
252
253
  _getType(): MessageType;
253
254
  static isInstance(message: BaseMessage): message is ChatMessage;
254
255
  }
255
- export type BaseMessageLike = BaseMessage | [
256
- MessageType | "user" | "assistant" | (string & Record<never, never>),
257
- string
258
- ] | string;
256
+ export type BaseMessageLike = BaseMessage | [StringWithAutocomplete<MessageType | "user" | "assistant">, string] | string;
259
257
  export declare function isBaseMessage(messageLike?: unknown): messageLike is BaseMessage;
260
258
  export declare function isBaseMessageChunk(messageLike?: unknown): messageLike is BaseMessageChunk;
261
259
  export declare function coerceMessageLikeToMessage(messageLike: BaseMessageLike): BaseMessage;
@@ -381,8 +381,8 @@ export class ToolMessage extends BaseMessage {
381
381
  }
382
382
  }
383
383
  /**
384
- * Represents a chunk of a function message, which can be concatenated
385
- * with other function message chunks.
384
+ * Represents a chunk of a tool message, which can be concatenated
385
+ * with other tool message chunks.
386
386
  */
387
387
  export class ToolMessageChunk extends BaseMessageChunk {
388
388
  constructor(fields) {
@@ -317,8 +317,8 @@ export declare class RunnableWithFallbacks<RunInput, RunOutput> extends Runnable
317
317
  static lc_name(): string;
318
318
  lc_namespace: string[];
319
319
  lc_serializable: boolean;
320
- protected runnable: Runnable<RunInput, RunOutput>;
321
- protected fallbacks: Runnable<RunInput, RunOutput>[];
320
+ runnable: Runnable<RunInput, RunOutput>;
321
+ fallbacks: Runnable<RunInput, RunOutput>[];
322
322
  constructor(fields: {
323
323
  runnable: Runnable<RunInput, RunOutput>;
324
324
  fallbacks: Runnable<RunInput, RunOutput>[];
@@ -29,20 +29,18 @@ async function* createOllamaStream(baseUrl, params, options) {
29
29
  }
30
30
  const stream = stream_js_1.IterableReadableStream.fromReadableStream(response.body);
31
31
  const decoder = new TextDecoder();
32
+ let extra = "";
32
33
  for await (const chunk of stream) {
33
- try {
34
- if (chunk !== undefined) {
35
- const lines = decoder
36
- .decode(chunk)
37
- .split("\n")
38
- .filter((v) => v.length);
39
- for (const line of lines) {
40
- yield JSON.parse(line);
41
- }
34
+ const decoded = extra + decoder.decode(chunk);
35
+ const lines = decoded.split("\n");
36
+ extra = lines.pop() || "";
37
+ for (const line of lines) {
38
+ try {
39
+ yield JSON.parse(line);
40
+ }
41
+ catch (e) {
42
+ console.warn(`Received a non-JSON parseable chunk: ${line}`);
42
43
  }
43
- }
44
- catch (e) {
45
- console.warn(`Received a non-JSON parseable chunk: ${decoder.decode(chunk)}`);
46
44
  }
47
45
  }
48
46
  }
@@ -1,4 +1,5 @@
1
1
  import { BaseLanguageModelCallOptions } from "../base_language/index.js";
2
+ import type { StringWithAutocomplete } from "./types.js";
2
3
  export interface OllamaInput {
3
4
  embeddingOnly?: boolean;
4
5
  f16KV?: boolean;
@@ -32,10 +33,12 @@ export interface OllamaInput {
32
33
  useMLock?: boolean;
33
34
  useMMap?: boolean;
34
35
  vocabOnly?: boolean;
36
+ format?: StringWithAutocomplete<"json">;
35
37
  }
36
38
  export interface OllamaRequestParams {
37
39
  model: string;
38
40
  prompt: string;
41
+ format?: StringWithAutocomplete<"json">;
39
42
  options: {
40
43
  embedding_only?: boolean;
41
44
  f16_kv?: boolean;
@@ -26,20 +26,18 @@ export async function* createOllamaStream(baseUrl, params, options) {
26
26
  }
27
27
  const stream = IterableReadableStream.fromReadableStream(response.body);
28
28
  const decoder = new TextDecoder();
29
+ let extra = "";
29
30
  for await (const chunk of stream) {
30
- try {
31
- if (chunk !== undefined) {
32
- const lines = decoder
33
- .decode(chunk)
34
- .split("\n")
35
- .filter((v) => v.length);
36
- for (const line of lines) {
37
- yield JSON.parse(line);
38
- }
31
+ const decoded = extra + decoder.decode(chunk);
32
+ const lines = decoded.split("\n");
33
+ extra = lines.pop() || "";
34
+ for (const line of lines) {
35
+ try {
36
+ yield JSON.parse(line);
37
+ }
38
+ catch (e) {
39
+ console.warn(`Received a non-JSON parseable chunk: ${line}`);
39
40
  }
40
- }
41
- catch (e) {
42
- console.warn(`Received a non-JSON parseable chunk: ${decoder.decode(chunk)}`);
43
41
  }
44
42
  }
45
43
  }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /**
3
+ * Represents a string value with autocompleted, but not required, suggestions.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Represents a string value with autocompleted, but not required, suggestions.
3
+ */
4
+ export type StringWithAutocomplete<T> = T | (string & Record<never, never>);
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Represents a string value with autocompleted, but not required, suggestions.
3
+ */
4
+ export {};
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/experimental/chat_models/ollama_functions.cjs');
@@ -0,0 +1 @@
1
+ export * from '../../dist/experimental/chat_models/ollama_functions.js'
@@ -0,0 +1 @@
1
+ export * from '../../dist/experimental/chat_models/ollama_functions.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.0.185",
3
+ "version": "0.0.187",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -778,6 +778,9 @@
778
778
  "experimental/chat_models/bittensor.cjs",
779
779
  "experimental/chat_models/bittensor.js",
780
780
  "experimental/chat_models/bittensor.d.ts",
781
+ "experimental/chat_models/ollama_functions.cjs",
782
+ "experimental/chat_models/ollama_functions.js",
783
+ "experimental/chat_models/ollama_functions.d.ts",
781
784
  "experimental/llms/bittensor.cjs",
782
785
  "experimental/llms/bittensor.js",
783
786
  "experimental/llms/bittensor.d.ts",
@@ -806,7 +809,8 @@
806
809
  "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rimraf dist/tests dist/**/tests",
807
810
  "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && node scripts/move-cjs-to-dist.js && rimraf dist-cjs",
808
811
  "build:watch": "node scripts/create-entrypoints.js && tsc --outDir dist/ --watch",
809
- "build:scripts": "node scripts/create-entrypoints.js && node scripts/check-tree-shaking.js && node scripts/generate-docs-llm-compatibility-table",
812
+ "build:scripts": "node scripts/create-entrypoints.js && node scripts/check-tree-shaking.js && yarn conditional:api_refs && node scripts/generate-docs-llm-compatibility-table",
813
+ "conditional:api_refs": "bash scripts/build-api-refs.sh",
810
814
  "lint": "NODE_OPTIONS=--max-old-space-size=4096 eslint src && dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
811
815
  "lint:fix": "yarn lint --fix",
812
816
  "precommit": "lint-staged",
@@ -923,7 +927,7 @@
923
927
  "jest": "^29.5.0",
924
928
  "jest-environment-node": "^29.6.4",
925
929
  "jsdom": "^22.1.0",
926
- "llmonitor": "^0.5.8",
930
+ "llmonitor": "^0.5.9",
927
931
  "lodash": "^4.17.21",
928
932
  "mammoth": "^1.5.1",
929
933
  "ml-matrix": "^6.10.4",
@@ -1029,7 +1033,7 @@
1029
1033
  "ignore": "^5.2.0",
1030
1034
  "ioredis": "^5.3.2",
1031
1035
  "jsdom": "*",
1032
- "llmonitor": "^0.5.8",
1036
+ "llmonitor": "^0.5.9",
1033
1037
  "lodash": "^4.17.21",
1034
1038
  "mammoth": "*",
1035
1039
  "mongodb": "^5.2.0",
@@ -2674,6 +2678,11 @@
2674
2678
  "import": "./experimental/chat_models/bittensor.js",
2675
2679
  "require": "./experimental/chat_models/bittensor.cjs"
2676
2680
  },
2681
+ "./experimental/chat_models/ollama_functions": {
2682
+ "types": "./experimental/chat_models/ollama_functions.d.ts",
2683
+ "import": "./experimental/chat_models/ollama_functions.js",
2684
+ "require": "./experimental/chat_models/ollama_functions.cjs"
2685
+ },
2677
2686
  "./experimental/llms/bittensor": {
2678
2687
  "types": "./experimental/llms/bittensor.d.ts",
2679
2688
  "import": "./experimental/llms/bittensor.js",