Mem0 1.0.0 (#3545)
This commit is contained in:
+18
-12
@@ -12,6 +12,7 @@ except ImportError:
|
||||
from mem0.configs.llms.base import BaseLlmConfig
|
||||
from mem0.configs.llms.aws_bedrock import AWSBedrockConfig
|
||||
from mem0.llms.base import LLMBase
|
||||
from mem0.memory.utils import extract_json
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -371,7 +372,7 @@ class AWSBedrockLLM(LLMBase):
|
||||
processed_response["tool_calls"].append(
|
||||
{
|
||||
"name": item["toolUse"]["name"],
|
||||
"arguments": item["toolUse"]["input"],
|
||||
"arguments": json.loads(extract_json(json.dumps(item["toolUse"]["input"]))),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -575,21 +576,26 @@ class AWSBedrockLLM(LLMBase):
|
||||
|
||||
return self._parse_response(response)
|
||||
else:
|
||||
prompt = self._format_messages(messages)
|
||||
# For other providers and legacy Amazon models (like Titan)
|
||||
if self.provider == "amazon":
|
||||
# Legacy Amazon models need string formatting, not array formatting
|
||||
prompt = self._format_messages_generic(messages)
|
||||
else:
|
||||
prompt = self._format_messages(messages)
|
||||
input_body = self._prepare_input(prompt)
|
||||
|
||||
# Convert to JSON
|
||||
body = json.dumps(input_body)
|
||||
# Convert to JSON
|
||||
body = json.dumps(input_body)
|
||||
|
||||
# Make API call
|
||||
response = self.client.invoke_model(
|
||||
body=body,
|
||||
modelId=self.config.model,
|
||||
accept="application/json",
|
||||
contentType="application/json",
|
||||
)
|
||||
# Make API call
|
||||
response = self.client.invoke_model(
|
||||
body=body,
|
||||
modelId=self.config.model,
|
||||
accept="application/json",
|
||||
contentType="application/json",
|
||||
)
|
||||
|
||||
return self._parse_response(response)
|
||||
return self._parse_response(response)
|
||||
|
||||
def list_available_models(self) -> List[Dict[str, Any]]:
|
||||
"""List all available models in the current region."""
|
||||
|
||||
+9
-6
@@ -49,20 +49,22 @@ class OllamaLLM(LLMBase):
|
||||
Returns:
|
||||
str or dict: The processed response.
|
||||
"""
|
||||
# Get the content from response
|
||||
if isinstance(response, dict):
|
||||
content = response["message"]["content"]
|
||||
else:
|
||||
content = response.message.content
|
||||
|
||||
if tools:
|
||||
processed_response = {
|
||||
"content": response["message"]["content"] if isinstance(response, dict) else response.message.content,
|
||||
"content": content,
|
||||
"tool_calls": [],
|
||||
}
|
||||
|
||||
# Ollama doesn't support tool calls in the same way, so we return the content
|
||||
return processed_response
|
||||
else:
|
||||
# Handle both dict and object responses
|
||||
if isinstance(response, dict):
|
||||
return response["message"]["content"]
|
||||
else:
|
||||
return response.message.content
|
||||
return content
|
||||
|
||||
def generate_response(
|
||||
self,
|
||||
@@ -94,6 +96,7 @@ class OllamaLLM(LLMBase):
|
||||
# Handle JSON response format by using Ollama's native format parameter
|
||||
if response_format and response_format.get("type") == "json_object":
|
||||
params["format"] = "json"
|
||||
# Also add JSON format instruction to the last message as a fallback
|
||||
if messages and messages[-1]["role"] == "user":
|
||||
messages[-1]["content"] += "\n\nPlease respond with valid JSON only."
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user