Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core[minor]: Convert runnable to tool #6013

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 6 additions & 48 deletions langchain-core/src/language_models/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import { type LLMResult } from "../outputs.js";
import { CallbackManager, Callbacks } from "../callbacks/manager.js";
import { AsyncCaller, AsyncCallerParams } from "../utils/async_caller.js";
import { encodingForModel } from "../utils/tiktoken.js";
import { Runnable, type RunnableInterface } from "../runnables/base.js";
import {
BaseLangChain,
BaseLangChainParams,
Runnable,
type RunnableInterface,
} from "../runnables/base.js";
import { RunnableConfig } from "../runnables/config.js";

// https://www.npmjs.com/package/js-tiktoken
Expand Down Expand Up @@ -132,59 +137,12 @@ export const calculateMaxTokens = async ({
return maxTokens - numTokens;
};

const getVerbosity = () => false;

export type SerializedLLM = {
_model: string;
_type: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} & Record<string, any>;

export interface BaseLangChainParams {
verbose?: boolean;
callbacks?: Callbacks;
tags?: string[];
metadata?: Record<string, unknown>;
}

/**
* Base class for language models, chains, tools.
*/
export abstract class BaseLangChain<
RunInput,
RunOutput,
CallOptions extends RunnableConfig = RunnableConfig
>
extends Runnable<RunInput, RunOutput, CallOptions>
implements BaseLangChainParams
{
/**
* Whether to print out response text.
*/
verbose: boolean;

callbacks?: Callbacks;

tags?: string[];

metadata?: Record<string, unknown>;

get lc_attributes(): { [key: string]: undefined } | undefined {
return {
callbacks: undefined,
verbose: undefined,
};
}

constructor(params: BaseLangChainParams) {
super(params);
this.verbose = params.verbose ?? getVerbosity();
this.callbacks = params.callbacks;
this.tags = params.tags ?? [];
this.metadata = params.metadata ?? {};
}
}

/**
* Base interface for language model parameters.
* A subclass of {@link BaseLanguageModel} should have a constructor that
Expand Down
2 changes: 1 addition & 1 deletion langchain-core/src/language_models/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import {
} from "../callbacks/manager.js";
import type { RunnableConfig } from "../runnables/config.js";
import type { BaseCache } from "../caches.js";
import { StructuredToolInterface } from "../tools.js";
import {
Runnable,
RunnableLambda,
RunnableSequence,
type StructuredToolInterface,
} from "../runnables/base.js";
import { isStreamEventsHandler } from "../tracers/event_stream.js";
import { isLogStreamHandler } from "../tracers/log_stream.js";
Expand Down
Loading
Loading