@langchain/core
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -1,4 +0,4 @@ | ||
import type { AgentAction, AgentFinish } from "../agents.js"; | ||
import { AgentAction, AgentFinish } from "../agents.js"; | ||
import type { ChainValues } from "../utils/types.js"; | ||
import type { LLMResult } from "../outputs.js"; | ||
import { LLMResult } from "../outputs.js"; | ||
import { BaseCallbackHandler, CallbackHandlerMethods, HandleLLMNewTokenCallbackFields, NewTokenIndices } from "./base.js"; | ||
@@ -5,0 +5,0 @@ import { type BaseMessage } from "../messages/index.js"; |
@@ -1,4 +0,4 @@ | ||
import { BaseMessage, BaseMessageChunk, type BaseMessageLike } from "../messages/index.js"; | ||
import { BaseMessage, BaseMessageChunk, BaseMessageLike } from "../messages/index.js"; | ||
import { BasePromptValue } from "../prompt_values.js"; | ||
import { type LLMResult, ChatGenerationChunk, type ChatResult } from "../outputs.js"; | ||
import { LLMResult, ChatGenerationChunk, ChatResult } from "../outputs.js"; | ||
import { BaseLanguageModel, type BaseLanguageModelCallOptions, type BaseLanguageModelInput, type BaseLanguageModelParams } from "./base.js"; | ||
@@ -5,0 +5,0 @@ import { CallbackManagerForLLMRun, Callbacks } from "../callbacks/manager.js"; |
import { BaseMessage } from "../messages/index.js"; | ||
import { BasePromptValue } from "../prompt_values.js"; | ||
import { type LLMResult, GenerationChunk } from "../outputs.js"; | ||
import { type BaseCallbackConfig, CallbackManagerForLLMRun, type Callbacks } from "../callbacks/manager.js"; | ||
import { LLMResult, GenerationChunk } from "../outputs.js"; | ||
import { BaseCallbackConfig, CallbackManagerForLLMRun, Callbacks } from "../callbacks/manager.js"; | ||
import { BaseLanguageModel, type BaseLanguageModelCallOptions, type BaseLanguageModelInput, type BaseLanguageModelParams } from "./base.js"; | ||
import type { RunnableConfig } from "../runnables/config.js"; | ||
import { RunnableConfig } from "../runnables/config.js"; | ||
export type SerializedLLM = { | ||
@@ -8,0 +8,0 @@ _model: string; |
import { AIMessage, getBufferString } from "../messages/index.js"; | ||
import { RUN_KEY, GenerationChunk, } from "../outputs.js"; | ||
import { RUN_KEY, GenerationChunk } from "../outputs.js"; | ||
import { CallbackManager, } from "../callbacks/manager.js"; | ||
@@ -4,0 +4,0 @@ import { BaseLanguageModel, } from "./base.js"; |
@@ -819,33 +819,13 @@ import pRetry from "p-retry"; | ||
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), undefined, undefined, undefined, undefined, options?.runName); | ||
let nextStepInput = input; | ||
const steps = [this.first, ...this.middle, this.last]; | ||
// Find the index of the last runnable in the sequence that doesn't have an overridden .transform() method | ||
// and start streaming from there | ||
const streamingStartStepIndex = Math.min(steps.length - 1, steps.length - | ||
[...steps].reverse().findIndex((step) => { | ||
const isDefaultImplementation = step.transform === Runnable.prototype.transform; | ||
const boundRunnableIsDefaultImplementation = RunnableBinding.isRunnableBinding(step) && | ||
step.bound?.transform === Runnable.prototype.transform; | ||
return (isDefaultImplementation || boundRunnableIsDefaultImplementation); | ||
}) - | ||
1); | ||
try { | ||
const invokeSteps = steps.slice(0, streamingStartStepIndex); | ||
for (let i = 0; i < invokeSteps.length; i += 1) { | ||
const step = invokeSteps[i]; | ||
nextStepInput = await step.invoke(nextStepInput, this._patchConfig(options, runManager?.getChild(`seq:step:${i + 1}`))); | ||
} | ||
} | ||
catch (e) { | ||
await runManager?.handleChainError(e); | ||
throw e; | ||
} | ||
let concatSupported = true; | ||
let finalOutput; | ||
async function* inputGenerator() { | ||
yield input; | ||
} | ||
try { | ||
let finalGenerator = await steps[streamingStartStepIndex]._streamIterator(nextStepInput, this._patchConfig(options, runManager?.getChild(`seq:step:${streamingStartStepIndex + 1}`))); | ||
const finalSteps = steps.slice(streamingStartStepIndex + 1); | ||
for (let i = 0; i < finalSteps.length; i += 1) { | ||
const step = finalSteps[i]; | ||
finalGenerator = await step.transform(finalGenerator, this._patchConfig(options, runManager?.getChild(`seq:step:${streamingStartStepIndex + i + 2}`))); | ||
let finalGenerator = steps[0].transform(inputGenerator(), this._patchConfig(options, runManager?.getChild(`seq:step:1`))); | ||
for (let i = 1; i < steps.length; i += 1) { | ||
const step = steps[i]; | ||
finalGenerator = await step.transform(finalGenerator, this._patchConfig(options, runManager?.getChild(`seq:step:${i + 1}`))); | ||
} | ||
@@ -852,0 +832,0 @@ for await (const chunk of finalGenerator) { |
@@ -8,3 +8,3 @@ import { BaseCallbackConfig } from "../callbacks/manager.js"; | ||
type GetSessionHistoryCallable = (...args: Array<any>) => Promise<BaseChatMessageHistory | BaseListChatMessageHistory>; | ||
export interface RunnableWithMessageHistoryInputs<RunInput, RunOutput> extends Omit<RunnableBindingArgs<RunInput, RunOutput, BaseCallbackConfig>, "bound"> { | ||
export interface RunnableWithMessageHistoryInputs<RunInput, RunOutput> extends Omit<RunnableBindingArgs<RunInput, RunOutput, BaseCallbackConfig>, "bound" | "config"> { | ||
runnable: Runnable<RunInput, RunOutput>; | ||
@@ -15,2 +15,3 @@ getMessageHistory: GetSessionHistoryCallable; | ||
historyMessagesKey?: string; | ||
config?: RunnableConfig; | ||
} | ||
@@ -17,0 +18,0 @@ export declare class RunnableWithMessageHistory<RunInput, RunOutput> extends RunnableBinding<RunInput, RunOutput, BaseCallbackConfig> { |
@@ -20,4 +20,6 @@ import { AIMessage, HumanMessage, isBaseMessage, } from "../messages/index.js"; | ||
.withConfig({ runName: "RunnableWithMessageHistory" }); | ||
const config = fields.config ?? {}; | ||
super({ | ||
...fields, | ||
config, | ||
bound, | ||
@@ -24,0 +26,0 @@ }); |
@@ -38,5 +38,8 @@ /* | ||
this.ensureReader(); | ||
const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet | ||
this.reader.releaseLock(); // release lock first | ||
await cancelPromise; // now await it | ||
// If wrapped in a Node stream, cancel is already called. | ||
if (this.locked) { | ||
const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet | ||
this.reader.releaseLock(); // release lock first | ||
await cancelPromise; // now await it | ||
} | ||
return { done: true, value: undefined }; // This cast fixes TS typing, and convention is to ignore final chunk value anyway | ||
@@ -43,0 +46,0 @@ } |
{ | ||
"name": "@langchain/core", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Core LangChain.js abstractions and schemas", | ||
@@ -16,3 +16,4 @@ "type": "module", | ||
"scripts": { | ||
"build": "yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts", | ||
"build": "yarn turbo run build:scripts", | ||
"build:envs": "yarn build:esm && yarn build:cjs", | ||
"build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rimraf dist/tests dist/**/tests", | ||
@@ -26,3 +27,3 @@ "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", | ||
"lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm", | ||
"clean": "rimraf dist/ && NODE_OPTIONS=--max-old-space-size=4096 node scripts/create-entrypoints.js pre", | ||
"clean": "rimraf .turbo/ dist/ && NODE_OPTIONS=--max-old-space-size=4096 node scripts/create-entrypoints.js pre", | ||
"prepack": "yarn build", | ||
@@ -66,2 +67,3 @@ "release": "release-it --only-version --config .release-it.json", | ||
"rimraf": "^5.0.1", | ||
"turbo": "latest", | ||
"typescript": "^5.0.0" | ||
@@ -68,0 +70,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1138607
18
28326