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

Fix/giga tools inected variables fix #220

Merged
merged 6 commits into from
Sep 11, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class __ModuleName__Tool(BaseTool):
.. code-block:: python

# TODO: output of invocation
""" # noqa: E501
""" # noqa: E501

# TODO: Set tool name and description
name: str = "TODO: Tool name"
Expand Down
6 changes: 3 additions & 3 deletions libs/cli/langchain_cli/namespaces/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ def new(
if has_packages:
add(package, project_dir=destination_dir, pip=pip_bool)

typer.echo(f'\n\nSuccess! Created a new LangChain app under "./{app_name}"!\n\n')
typer.echo(f'\n\nSuccess! Created a new GigaChain app under "./{app_name}"!\n\n')
typer.echo("Next, enter your new app directory by running:\n")
typer.echo(f" cd ./{app_name}\n")
typer.echo("Then add templates with commands like:\n")
typer.echo(" langchain app add extraction-openai-functions")
typer.echo(" gigachain app add extraction-openai-functions")
typer.echo(
" langchain app add git+ssh://[email protected]/efriis/simple-pirate.git\n\n"
" gigachain app add git+ssh://[email protected]/efriis/simple-pirate.git\n\n"
)


Expand Down
12 changes: 8 additions & 4 deletions libs/cli/langchain_cli/utils/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_package_root(cwd: Optional[Path] = None) -> Path:

class LangServeExport(TypedDict):
"""
Fields from pyproject.toml that are relevant to LangServe
Fields from pyproject.toml that are relevant to GigaServe

Attributes:
module: The module to import from, tool.langserve.export_module
Expand All @@ -37,9 +37,13 @@ def get_langserve_export(filepath: Path) -> LangServeExport:
with open(filepath) as f:
data: Dict[str, Any] = load(f)
try:
module = data["tool"]["langserve"]["export_module"]
attr = data["tool"]["langserve"]["export_attr"]
if "gigaserve" in data["tool"]:
module = data["tool"]["gigaserve"]["export_module"]
attr = data["tool"]["gigaserve"]["export_attr"]
else:
module = data["tool"]["langserve"]["export_module"]
attr = data["tool"]["langserve"]["export_attr"]
package_name = data["tool"]["poetry"]["name"]
except KeyError as e:
raise KeyError("Invalid LangServe PyProject.toml") from e
raise KeyError("Invalid GigaServe pyproject.toml") from e
return LangServeExport(module=module, attr=attr, package_name=package_name)
4 changes: 2 additions & 2 deletions libs/community/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/community/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ignore-words-list = "momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogy

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
gigachain-core = "^0.2.35post3"
gigachain-core = "^0.2.35post4"
gigachain = ">=0.2.12"
SQLAlchemy = ">=1.4,<3"
requests = "^2"
Expand Down
17 changes: 17 additions & 0 deletions libs/community/tests/unit_tests/chat_models/test_gigachat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# flake8: noqa: I001
from typing import Any, AsyncGenerator, Iterable, List
from typing_extensions import Annotated

import pytest
from gigachat.models import (
Expand All @@ -20,12 +21,15 @@
HumanMessage,
SystemMessage,
)
from langchain.tools import tool
from langchain_community.chat_models.gigachat import (
GigaChat,
_convert_dict_to_message,
_convert_message_to_dict,
)
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_core.runnables import RunnableConfig
from langchain_core.tools.base import InjectedToolArg
from pytest_mock import MockerFixture
from tests.unit_tests.stubs import AnyStr

Expand Down Expand Up @@ -317,3 +321,16 @@ class Person(BaseModel):
llm = GigaChat()
llm.bind_functions(functions=[Person], function_call="Person")
llm.bind_tools(tools=[Person], tool_choice="Person")


@tool
def _test_tool(
arg: str, config: RunnableConfig, injected: Annotated[str, InjectedToolArg]
) -> None:
"""Some description"""
return


async def test_gigachat_bind_with_injected_vars() -> None:
llm = GigaChat().bind_tools(tools=[_test_tool])
assert llm.kwargs["functions"][0]["parameters"]["required"] == ["arg"] # type: ignore[attr-defined]
7 changes: 5 additions & 2 deletions libs/core/langchain_core/utils/function_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,12 @@ def format_tool_to_gigachat_function(tool: BaseTool) -> GigaFunctionDescription:
raise Exception(
"Incorrect function or tool description. Description is required."
)
if tool.args_schema:
tool_schema = tool.args_schema
if tool.tool_call_schema:
tool_schema = tool.tool_call_schema
if tool_schema:
return convert_pydantic_to_gigachat_function(
tool.args_schema,
tool_schema,
name=tool.name,
description=tool.description,
return_model=tool.return_schema,
Expand Down
2 changes: 1 addition & 1 deletion libs/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "gigachain-core"
version = "0.2.35post3"
version = "0.2.35post4"
description = "Building applications with LLMs through composability"
authors = []
license = "MIT"
Expand Down
6 changes: 3 additions & 3 deletions templates/summarize-anthropic/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[tool.poetry]
name = "summarize-anthropic"
version = "0.1.0"
version = "0.1.0post1"
description = "This template uses Anthropic's `Claude2` to summarize long documents."
authors = ["Lance Martin <[email protected]>"]
readme = "README.md"
Expand All @@ -10,14 +10,14 @@ readme = "README.md"
python = ">=3.8.1,<4.0"
gigachain = "^0.1"
langchainhub = ">=0.1.13"
gigachain-anthropic = "^0.1.4"
gigachain-anthropic = "^0.1.23"

[tool.poetry.group.dev.dependencies]
gigachain-cli = ">=0.0.21"

[tool.templates-hub]
use-case = "summarization"
author = "LangChain"
author = "LangChain, GigaChain"
integrations = ["Anthropic"]
tags = ["summarization"]

Expand Down
Loading