mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-27 00:58:13 +00:00
feat: enhance pydantic output to include field descriptions
- Update generate_model_description to include field descriptions - Add tests for field description handling - Maintain backward compatibility for fields without descriptions Fixes #2188 Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -4,7 +4,7 @@ from typing import Dict, List, Optional
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from crewai.llm import LLM
|
||||
from crewai.utilities.converter import (
|
||||
@@ -328,6 +328,26 @@ def test_generate_model_description_dict_field():
|
||||
assert description == expected_description
|
||||
|
||||
|
||||
def test_generate_model_description_with_field_descriptions():
|
||||
class ModelWithDescriptions(BaseModel):
|
||||
name: str = Field(..., description="The user's full name")
|
||||
age: int = Field(..., description="The user's age in years")
|
||||
|
||||
description = generate_model_description(ModelWithDescriptions)
|
||||
expected = '{\n "name": {"type": "str", "description": "The user\'s full name"},\n "age": {"type": "int", "description": "The user\'s age in years"}\n}'
|
||||
assert description == expected
|
||||
|
||||
|
||||
def test_generate_model_description_mixed_fields():
|
||||
class MixedModel(BaseModel):
|
||||
name: str = Field(..., description="The user's name")
|
||||
age: int # No description
|
||||
|
||||
description = generate_model_description(MixedModel)
|
||||
expected = '{\n "name": {"type": "str", "description": "The user\'s name"},\n "age": int\n}'
|
||||
assert description == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||
def test_convert_with_instructions():
|
||||
llm = LLM(model="gpt-4o-mini")
|
||||
|
||||
Reference in New Issue
Block a user