AlloyDBSentimentTool(
*,
name: str = "alloydb_sentiment_tool",
description: str = "Analyze the sentiment of a given text. Useful for determining if text is positive, negative, or neutral.",
args_schema: typing.Type[
pydantic.main.BaseModel
] = langchain_google_alloydb_pg.tools.SentimentInput,
return_direct: bool = False,
verbose: bool = False,
callbacks: (
list[langchain_core.callbacks.base.BaseCallbackHandler]
| langchain_core.callbacks.base.BaseCallbackManager
| None
) = None,
tags: list[str] | None = None,
metadata: dict[str, typing.Any] | None = None,
handle_tool_error: (
bool
| str
| collections.abc.Callable[
[langchain_core.tools.base.ToolException],
str | collections.abc.Sequence[str | dict[str, typing.Any]],
]
| None
) = False,
handle_validation_error: (
bool
| str
| collections.abc.Callable[
[
pydantic_core._pydantic_core.ValidationError
| pydantic.v1.error_wrappers.ValidationError
],
str,
]
| None
) = False,
response_format: typing.Literal["content", "content_and_artifact"] = "content",
extras: dict[str, typing.Any] | None = None,
engine: langchain_google_alloydb_pg.engine.AlloyDBEngine,
model_id: typing.Optional[str] = None
)Analyzes the sentiment of text with google_ml.analyze_sentiment.
Requires AlloyDB running PostgreSQL 17 or higher with
google_ml_integration. Like any LangChain tool, call it with
invoke / ainvoke or give it to an agent:
tool = AlloyDBSentimentTool(engine=engine)
tool.invoke({"content": "I love this product!"}) # "positive"
model_id is set on the tool, not by the agent. If it is None, the
database uses the model named by its
google_ml_integration.default_llm_model flag. If the function returns
NULL, the tool raises AlloyDBToolError.
Methods
AlloyDBSentimentTool
AlloyDBSentimentTool(
*,
name: str = "alloydb_sentiment_tool",
description: str = "Analyze the sentiment of a given text. Useful for determining if text is positive, negative, or neutral.",
args_schema: typing.Type[
pydantic.main.BaseModel
] = langchain_google_alloydb_pg.tools.SentimentInput,
return_direct: bool = False,
verbose: bool = False,
callbacks: (
list[langchain_core.callbacks.base.BaseCallbackHandler]
| langchain_core.callbacks.base.BaseCallbackManager
| None
) = None,
tags: list[str] | None = None,
metadata: dict[str, typing.Any] | None = None,
handle_tool_error: (
bool
| str
| collections.abc.Callable[
[langchain_core.tools.base.ToolException],
str | collections.abc.Sequence[str | dict[str, typing.Any]],
]
| None
) = False,
handle_validation_error: (
bool
| str
| collections.abc.Callable[
[
pydantic_core._pydantic_core.ValidationError
| pydantic.v1.error_wrappers.ValidationError
],
str,
]
| None
) = False,
response_format: typing.Literal["content", "content_and_artifact"] = "content",
extras: dict[str, typing.Any] | None = None,
engine: langchain_google_alloydb_pg.engine.AlloyDBEngine,
model_id: typing.Optional[str] = None
)Initialize the tool.
| Exceptions | |
|---|---|
| Type | Description |
TypeError |
If args_schema is not a subclass of pydantic BaseModel or dict. |
_arun
_arun(
content: str,
run_manager: typing.Optional[
langchain_core.callbacks.manager.AsyncCallbackManagerForToolRun
] = None,
) -> strAnalyze sentiment asynchronously. Called by ainvoke and arun.
_run
_run(
content: str,
run_manager: typing.Optional[
langchain_core.callbacks.manager.CallbackManagerForToolRun
] = None,
) -> strAnalyze sentiment synchronously. Called by invoke and run.
model_post_init
model_post_init(context: Any, /) -> NoneThis function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that's what pydantic-core passes when calling it.