Reverting the tools commit (#2404)

This commit is contained in:
Parshva Daftari
2025-03-20 00:09:00 +05:30
committed by GitHub
parent 1aed611539
commit ee66e0c954
21 changed files with 990 additions and 475 deletions

View File

@@ -4,26 +4,14 @@ from typing import Dict, List, Optional
try:
import anthropic
except ImportError:
raise ImportError(
"The 'anthropic' library is required. Please install it using 'pip install anthropic'."
)
raise ImportError("The 'anthropic' library is required. Please install it using 'pip install anthropic'.")
from mem0.configs.llms.base import BaseLlmConfig
from mem0.llms.base import LLMBase
class AnthropicLLM(LLMBase):
"""
A class for interacting with Anthropic's Claude models using the specified configuration.
"""
def __init__(self, config: Optional[BaseLlmConfig] = None):
"""
Initializes the AnthropicLLM instance with the given configuration.
Args:
config (Optional[BaseLlmConfig]): Configuration settings for the language model.
"""
super().__init__(config)
if not self.config.model:
@@ -35,17 +23,23 @@ class AnthropicLLM(LLMBase):
def generate_response(
self,
messages: List[Dict[str, str]],
) -> str:
response_format=None,
tools: Optional[List[Dict]] = None,
tool_choice: str = "auto",
):
"""
Generates a response using Anthropic's Claude model based on the provided messages.
Generate a response based on the given messages using Anthropic.
Args:
messages (List[Dict[str, str]]): A list of dictionaries, each containing a 'role' and 'content' key.
messages (list): List of message dicts containing 'role' and 'content'.
response_format (str or object, optional): Format of the response. Defaults to "text".
tools (list, optional): List of tools that the model can call. Defaults to None.
tool_choice (str, optional): Tool choice method. Defaults to "auto".
Returns:
str: The generated response from the model.
str: The generated response.
"""
# Extract system message separately
# Separate system message from other messages
system_message = ""
filtered_messages = []
for message in messages:
@@ -62,6 +56,9 @@ class AnthropicLLM(LLMBase):
"max_tokens": self.config.max_tokens,
"top_p": self.config.top_p,
}
if tools: # TODO: Remove tools if no issues found with new memory addition logic
params["tools"] = tools
params["tool_choice"] = tool_choice
response = self.client.messages.create(**params)
return response.content[0].text