From 4129d190076776e9277c03612a49c4ba6a65a51d Mon Sep 17 00:00:00 2001 From: "luca.gobbi" Date: Fri, 1 Nov 2024 00:54:06 +0100 Subject: [PATCH] added anthropic as supported llm provider --- core/cat/factory/llm.py | 19 +++++++++++++++++++ core/pyproject.toml | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/cat/factory/llm.py b/core/cat/factory/llm.py index d2d85f08..b91ff0de 100644 --- a/core/cat/factory/llm.py +++ b/core/cat/factory/llm.py @@ -7,6 +7,7 @@ from langchain_openai import ChatOpenAI, OpenAI from langchain_cohere import ChatCohere from langchain_google_genai import ChatGoogleGenerativeAI +from langchain_anthropic import ChatAnthropic from typing import Type import json @@ -282,6 +283,23 @@ class LLMGeminiChatConfig(LLMSettings): ) +class LLMAnthropicChatConfig(LLMSettings): + api_key: str + model: str = "claude-3-5-sonnet-20241022" + temperature: float = 0.7 + max_tokens: int = 8192 + max_retries: int = 2 + + _pyclass: Type = ChatAnthropic + + model_config = ConfigDict( + json_schema_extra={ + "humanReadableName": "Anthropic", + "description": "Configuration for Anthropic", + "link": "https://www.anthropic.com/", + } + ) + def get_allowed_language_models(): list_llms_default = [ LLMOpenAIChatConfig, @@ -296,6 +314,7 @@ def get_allowed_language_models(): LLMHuggingFaceTextGenInferenceConfig, LLMCustomConfig, LLMDefaultConfig, + LLMAnthropicChatConfig ] mad_hatter_instance = MadHatter() diff --git a/core/pyproject.toml b/core/pyproject.toml index c1a8ed76..0c07d754 100644 --- a/core/pyproject.toml +++ b/core/pyproject.toml @@ -25,6 +25,7 @@ dependencies = [ "langchain==0.2.1", "langchain-community==0.2.1", "langchain-openai==0.1.7", + "langchain-anthropic==0.1.23", "langchain-google-genai==1.0.8", "langchain-cohere==0.1.5", "huggingface-hub==0.20.3", @@ -34,7 +35,6 @@ dependencies = [ "tiktoken==0.7.0", "tomli", "loguru==0.7.2", - "anthropic==0.2.9", "text_generation==0.6.1", "tinydb==4.8.0", "python-slugify==8.0.1",