mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-25 08:08:14 +00:00
Compare commits
3 Commits
devin/1768
...
devin/1742
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
355826a39d | ||
|
|
5e1f38251a | ||
|
|
abdf7a7967 |
@@ -91,6 +91,7 @@ class CrewAgentExecutorMixin:
|
|||||||
print(f"Missing attributes for long term memory: {e}")
|
print(f"Missing attributes for long term memory: {e}")
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# Only log the error; don't let it affect task output
|
||||||
print(f"Failed to add to long term memory: {e}")
|
print(f"Failed to add to long term memory: {e}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -104,28 +104,40 @@ class EmbeddingConfigurator:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _configure_vertexai(config, model_name):
|
def _configure_vertexai(config, model_name):
|
||||||
from chromadb.utils.embedding_functions.google_embedding_function import (
|
try:
|
||||||
GoogleVertexEmbeddingFunction,
|
from chromadb.utils.embedding_functions.google_embedding_function import (
|
||||||
)
|
GoogleVertexEmbeddingFunction,
|
||||||
|
)
|
||||||
return GoogleVertexEmbeddingFunction(
|
|
||||||
model_name=model_name,
|
return GoogleVertexEmbeddingFunction(
|
||||||
api_key=config.get("api_key"),
|
model_name=model_name,
|
||||||
project_id=config.get("project_id"),
|
api_key=config.get("api_key"),
|
||||||
region=config.get("region"),
|
project_id=config.get("project_id"),
|
||||||
)
|
region=config.get("region"),
|
||||||
|
)
|
||||||
|
except ImportError:
|
||||||
|
raise ImportError(
|
||||||
|
"Google Vertex AI dependencies are not installed. "
|
||||||
|
"Please install them using 'pip install google-cloud-aiplatform'."
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _configure_google(config, model_name):
|
def _configure_google(config, model_name):
|
||||||
from chromadb.utils.embedding_functions.google_embedding_function import (
|
try:
|
||||||
GoogleGenerativeAiEmbeddingFunction,
|
from chromadb.utils.embedding_functions.google_embedding_function import (
|
||||||
)
|
GoogleGenerativeAiEmbeddingFunction,
|
||||||
|
)
|
||||||
return GoogleGenerativeAiEmbeddingFunction(
|
|
||||||
model_name=model_name,
|
return GoogleGenerativeAiEmbeddingFunction(
|
||||||
api_key=config.get("api_key"),
|
model_name=model_name,
|
||||||
task_type=config.get("task_type"),
|
api_key=config.get("api_key"),
|
||||||
)
|
task_type=config.get("task_type"),
|
||||||
|
)
|
||||||
|
except ImportError:
|
||||||
|
raise ImportError(
|
||||||
|
"Google Generative AI dependencies are not installed. "
|
||||||
|
"Please install them using 'pip install google-generativeai'."
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _configure_cohere(config, model_name):
|
def _configure_cohere(config, model_name):
|
||||||
|
|||||||
68
tests/test_output_pydantic.py
Normal file
68
tests/test_output_pydantic.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
from crewai import Agent, Crew, Task
|
||||||
|
from crewai.utilities.converter import Converter
|
||||||
|
|
||||||
|
|
||||||
|
class ResponseFormat(BaseModel):
|
||||||
|
string: str = Field(description='string needs to be maintained')
|
||||||
|
|
||||||
|
def test_pydantic_model_conversion():
|
||||||
|
"""Test that pydantic model conversion works without causing import errors."""
|
||||||
|
|
||||||
|
# Test data
|
||||||
|
test_string = '{"string": "test value"}'
|
||||||
|
|
||||||
|
# Create a pydantic model directly
|
||||||
|
result = ResponseFormat.model_validate_json(test_string)
|
||||||
|
|
||||||
|
# Verify the conversion worked
|
||||||
|
assert result is not None
|
||||||
|
assert hasattr(result, "string")
|
||||||
|
assert isinstance(result.string, str)
|
||||||
|
assert result.string == "test value"
|
||||||
|
|
||||||
|
@patch('crewai.crew.Crew.kickoff')
|
||||||
|
def test_output_pydantic_with_mocked_crew(mock_kickoff):
|
||||||
|
"""Test that output_pydantic works properly without causing import errors."""
|
||||||
|
|
||||||
|
# Mock the crew kickoff to return a valid response
|
||||||
|
mock_result = ResponseFormat(string="mocked result")
|
||||||
|
mock_kickoff.return_value = mock_result
|
||||||
|
|
||||||
|
# Create a simple agent
|
||||||
|
agent = Agent(
|
||||||
|
role="Test Agent",
|
||||||
|
goal="Test pydantic model output",
|
||||||
|
backstory="Testing pydantic output functionality",
|
||||||
|
verbose=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a task with output_pydantic
|
||||||
|
task = Task(
|
||||||
|
description="Return a simple string",
|
||||||
|
expected_output="A simple string",
|
||||||
|
agent=agent,
|
||||||
|
output_pydantic=ResponseFormat
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a crew with the agent and task
|
||||||
|
crew = Crew(
|
||||||
|
agents=[agent],
|
||||||
|
tasks=[task],
|
||||||
|
verbose=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Execute the crew (this will use our mock)
|
||||||
|
result = crew.kickoff()
|
||||||
|
|
||||||
|
# Verify we got a result
|
||||||
|
assert result is not None
|
||||||
|
|
||||||
|
# Verify the result has a string attribute (as defined in ResponseFormat)
|
||||||
|
assert hasattr(result, "string")
|
||||||
|
assert isinstance(result.string, str)
|
||||||
|
assert result.string == "mocked result"
|
||||||
Reference in New Issue
Block a user