langchain/libs/community/langchain_community/chat_models
Igor Drozdov bb597b1286
feat(community): add bind_tools function for ChatLiteLLM (#23823)
It's a follow-up to https://github.com/langchain-ai/langchain/pull/23765

Now the tools can be bound by calling `bind_tools`

```python
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_core.utils.function_calling import convert_to_openai_tool
from langchain_community.chat_models import ChatLiteLLM

class GetWeather(BaseModel):
    '''Get the current weather in a given location'''

    location: str = Field(..., description="The city and state, e.g. San Francisco, CA")

class GetPopulation(BaseModel):
    '''Get the current population in a given location'''

    location: str = Field(..., description="The city and state, e.g. San Francisco, CA")

prompt = "Which city is hotter today and which is bigger: LA or NY?"
# tools = [convert_to_openai_tool(GetWeather), convert_to_openai_tool(GetPopulation)]
tools = [GetWeather, GetPopulation]

llm = ChatLiteLLM(model="claude-3-sonnet-20240229").bind_tools(tools)
ai_msg = llm.invoke(prompt)
print(ai_msg.tool_calls)
```

If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.

Co-authored-by: Igor Drozdov <idrozdov@gitlab.com>
2024-07-05 09:19:41 -04:00
..
__init__.py Add OCI Generative AI new model support (#22880) 2024-06-24 14:48:23 -04:00
anthropic.py
anyscale.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
azure_openai.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
azureml_endpoint.py infra: rm unused # noqa violations (#22049) 2024-05-22 15:21:08 -07:00
baichuan.py feat: Implement ChatBaichuan asynchronous interface (#23589) 2024-07-03 12:10:04 -04:00
baidu_qianfan_endpoint.py community[patch]: set tool name for tongyi&qianfan llm (#22889) 2024-06-28 09:17:05 -04:00
bedrock.py
cohere.py
coze.py community[patch]: Update root_validators to use pre=True or pre=False (#23731) 2024-07-01 20:10:15 +00:00
dappier.py community[patch]: Update root_validators to use pre=True or pre=False (#23731) 2024-07-01 20:10:15 +00:00
databricks.py
deepinfra.py community[deepinfra]: fix tool call parsing. (#23162) 2024-07-03 12:11:37 -04:00
edenai.py community[minor]: Add tools calls to ChatEdenAI (#22320) 2024-06-04 10:29:28 -07:00
ernie.py community[patch]: Update root_validators to use pre=True or pre=False (#23731) 2024-07-01 20:10:15 +00:00
everlyai.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
fake.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
fireworks.py community[patch]: Update root_validators to use pre=True or pre=False (#23731) 2024-07-01 20:10:15 +00:00
friendli.py
gigachat.py
google_palm.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
gpt_router.py
huggingface.py community[patch]: Update root_validators to use pre=True or pre=False (#23731) 2024-07-01 20:10:15 +00:00
human.py
hunyuan.py community[patch]: fix hunyuan message include chinese signature error (#22795) (#22796) 2024-06-12 12:30:22 -04:00
javelin_ai_gateway.py community[patch]: standardize init args, update for javelin sdk release. (#21980) 2024-05-22 21:47:28 +00:00
jinachat.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
kinetica.py
konko.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
litellm_router.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
litellm.py feat(community): add bind_tools function for ChatLiteLLM (#23823) 2024-07-05 09:19:41 -04:00
llama_edge.py
llamacpp.py openai, anthropic, ...: with_structured_output to pass in explicit tool choice (#23645) 2024-06-28 16:39:53 -07:00
maritalk.py community: fix lint (#23611) 2024-06-27 22:12:16 +00:00
meta.py
minimax.py community[patch]: Fix MiniMaxChat validate_environment error (#23770) 2024-07-02 13:23:32 -04:00
mlflow_ai_gateway.py
mlflow.py community[patch]: Fix ChatDatabricsk in case that streaming response doesn't have role field in delta chunk (#21897) 2024-05-22 08:12:53 -07:00
mlx.py
moonshot.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
oci_generative_ai.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
octoai.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
ollama.py Ollama vision support (#22734) 2024-06-11 16:10:19 +00:00
openai.py
pai_eas_endpoint.py community[patch]: Update root_validators embeddings: llamacpp, jina, dashscope, mosaicml, huggingface_hub, Toolkits: Connery, ChatModels: PAI_EAS, (#22828) 2024-06-12 13:59:05 -04:00
perplexity.py docs: updated PPLX model (#23723) 2024-07-02 08:48:49 -04:00
premai.py community[minor]: Prem Templates (#22783) 2024-06-13 19:59:28 -07:00
promptlayer_openai.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
snowflake.py community[minor]: add ChatSnowflakeCortex chat model (#21490) 2024-06-17 09:47:05 -07:00
solar.py
sparkllm.py community[patch]: Update root_validators ChatModels: ChatBaichuan, QianfanChatEndpoint, MiniMaxChat, ChatSparkLLM, ChatZhipuAI (#22853) 2024-06-20 16:36:41 +00:00
tongyi.py community[patch]: set tool name for tongyi&qianfan llm (#22889) 2024-06-28 09:17:05 -04:00
vertexai.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
volcengine_maas.py
yandex.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
yuan2.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
zhipuai.py community[patch]: Invoke callback prior to yielding token (#23638) 2024-07-01 18:12:24 +00:00