forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
community[patch]: Change recommended entrypoint, bump versions (langc…
…hain-ai#4069) * Change recommended entrypoint * Update docs * Fix lint * Bump versions * Update lock
- Loading branch information
1 parent
0e3c944
commit c311576
Showing
18 changed files
with
26 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,7 @@ | ||
import { z } from "zod"; | ||
import { | ||
CallbackManagerForToolRun, | ||
Callbacks, | ||
parseCallbackConfigArg, | ||
} from "@langchain/core/callbacks/manager"; | ||
import { StructuredTool, Tool, type ToolParams } from "@langchain/core/tools"; | ||
import { RunnableConfig } from "@langchain/core/runnables"; | ||
|
||
export interface BaseDynamicToolInput extends ToolParams { | ||
name: string; | ||
description: string; | ||
returnDirect?: boolean; | ||
} | ||
|
||
/** | ||
* Interface for the input parameters of the DynamicTool class. | ||
*/ | ||
export interface DynamicToolInput extends BaseDynamicToolInput { | ||
func: ( | ||
input: string, | ||
runManager?: CallbackManagerForToolRun | ||
) => Promise<string>; | ||
} | ||
|
||
/** | ||
* Interface for the input parameters of the DynamicStructuredTool class. | ||
*/ | ||
export interface DynamicStructuredToolInput< | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
T extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any> | ||
> extends BaseDynamicToolInput { | ||
func: ( | ||
input: z.infer<T>, | ||
runManager?: CallbackManagerForToolRun | ||
) => Promise<string>; | ||
schema: T; | ||
} | ||
|
||
/** | ||
* A tool that can be created dynamically from a function, name, and description. | ||
*/ | ||
export class DynamicTool extends Tool { | ||
static lc_name() { | ||
return "DynamicTool"; | ||
} | ||
|
||
name: string; | ||
|
||
description: string; | ||
|
||
func: DynamicToolInput["func"]; | ||
|
||
constructor(fields: DynamicToolInput) { | ||
super(fields); | ||
this.name = fields.name; | ||
this.description = fields.description; | ||
this.func = fields.func; | ||
this.returnDirect = fields.returnDirect ?? this.returnDirect; | ||
} | ||
|
||
async call( | ||
arg: string | undefined | z.input<this["schema"]>, | ||
configArg?: RunnableConfig | Callbacks | ||
): Promise<string> { | ||
const config = parseCallbackConfigArg(configArg); | ||
if (config.runName === undefined) { | ||
config.runName = this.name; | ||
} | ||
return super.call(arg, config); | ||
} | ||
|
||
/** @ignore */ | ||
async _call( | ||
input: string, | ||
runManager?: CallbackManagerForToolRun | ||
): Promise<string> { | ||
return this.func(input, runManager); | ||
} | ||
} | ||
|
||
/** | ||
* A tool that can be created dynamically from a function, name, and | ||
* description, designed to work with structured data. It extends the | ||
* StructuredTool class and overrides the _call method to execute the | ||
* provided function when the tool is called. | ||
*/ | ||
export class DynamicStructuredTool< | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
T extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any> | ||
> extends StructuredTool { | ||
static lc_name() { | ||
return "DynamicStructuredTool"; | ||
} | ||
|
||
name: string; | ||
|
||
description: string; | ||
|
||
func: DynamicStructuredToolInput["func"]; | ||
|
||
schema: T; | ||
|
||
constructor(fields: DynamicStructuredToolInput<T>) { | ||
super(fields); | ||
this.name = fields.name; | ||
this.description = fields.description; | ||
this.func = fields.func; | ||
this.returnDirect = fields.returnDirect ?? this.returnDirect; | ||
this.schema = fields.schema; | ||
} | ||
|
||
async call( | ||
arg: z.output<T>, | ||
configArg?: RunnableConfig | Callbacks, | ||
/** @deprecated */ | ||
tags?: string[] | ||
): Promise<string> { | ||
const config = parseCallbackConfigArg(configArg); | ||
if (config.runName === undefined) { | ||
config.runName = this.name; | ||
} | ||
return super.call(arg, config, tags); | ||
} | ||
|
||
protected _call( | ||
arg: z.output<T>, | ||
runManager?: CallbackManagerForToolRun | ||
): Promise<string> { | ||
return this.func(arg, runManager); | ||
} | ||
} | ||
export { | ||
type BaseDynamicToolInput, | ||
type DynamicToolInput, | ||
type DynamicStructuredToolInput, | ||
DynamicTool, | ||
DynamicStructuredTool, | ||
} from "@langchain/core/tools"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters