mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-26 16:48:13 +00:00
chore: update typing in types module to Python 3.10+ syntax (#3482)
Some checks failed
Notify Downstream / notify-downstream (push) Has been cancelled
Some checks failed
Notify Downstream / notify-downstream (push) Has been cancelled
Co-authored-by: Lucas Gomide <lucaslg200@gmail.com>
This commit is contained in:
@@ -1,16 +1,22 @@
|
|||||||
from typing import List
|
"""Crew chat input models.
|
||||||
|
|
||||||
|
This module provides models for defining chat inputs and fields
|
||||||
|
for crew interactions.
|
||||||
|
"""
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
class ChatInputField(BaseModel):
|
class ChatInputField(BaseModel):
|
||||||
"""
|
"""Represents a single required input for the crew.
|
||||||
Represents a single required input for the crew, with a name and short description.
|
|
||||||
Example:
|
Example:
|
||||||
{
|
```python
|
||||||
"name": "topic",
|
field = ChatInputField(
|
||||||
"description": "The topic to focus on for the conversation"
|
name="topic",
|
||||||
}
|
description="The topic to focus on for the conversation"
|
||||||
|
)
|
||||||
|
```
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name: str = Field(..., description="The name of the input field")
|
name: str = Field(..., description="The name of the input field")
|
||||||
@@ -18,23 +24,25 @@ class ChatInputField(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class ChatInputs(BaseModel):
|
class ChatInputs(BaseModel):
|
||||||
"""
|
"""Holds crew metadata and input field definitions.
|
||||||
Holds a high-level crew_description plus a list of ChatInputFields.
|
|
||||||
Example:
|
Example:
|
||||||
{
|
```python
|
||||||
"crew_name": "topic-based-qa",
|
inputs = ChatInputs(
|
||||||
"crew_description": "Use this crew for topic-based Q&A",
|
crew_name="topic-based-qa",
|
||||||
"inputs": [
|
crew_description="Use this crew for topic-based Q&A",
|
||||||
{"name": "topic", "description": "The topic to focus on"},
|
inputs=[
|
||||||
{"name": "username", "description": "Name of the user"},
|
ChatInputField(name="topic", description="The topic to focus on"),
|
||||||
|
ChatInputField(name="username", description="Name of the user"),
|
||||||
]
|
]
|
||||||
}
|
)
|
||||||
|
```
|
||||||
"""
|
"""
|
||||||
|
|
||||||
crew_name: str = Field(..., description="The name of the crew")
|
crew_name: str = Field(..., description="The name of the crew")
|
||||||
crew_description: str = Field(
|
crew_description: str = Field(
|
||||||
..., description="A description of the crew's purpose"
|
..., description="A description of the crew's purpose"
|
||||||
)
|
)
|
||||||
inputs: List[ChatInputField] = Field(
|
inputs: list[ChatInputField] = Field(
|
||||||
default_factory=list, description="A list of input fields for the crew"
|
default_factory=list, description="A list of input fields for the crew"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,18 +1,37 @@
|
|||||||
from typing import List, Dict, TypedDict
|
"""Human-in-the-loop (HITL) type definitions.
|
||||||
|
|
||||||
|
This module provides type definitions for human-in-the-loop interactions
|
||||||
|
in crew executions.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import TypedDict
|
||||||
|
|
||||||
|
|
||||||
class HITLResumeInfo(TypedDict, total=False):
|
class HITLResumeInfo(TypedDict, total=False):
|
||||||
"""HITL resume information passed from flow to crew."""
|
"""HITL resume information passed from flow to crew.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
task_id: Unique identifier for the task.
|
||||||
|
crew_execution_id: Unique identifier for the crew execution.
|
||||||
|
task_key: Key identifying the specific task.
|
||||||
|
task_output: Output from the task before human intervention.
|
||||||
|
human_feedback: Feedback provided by the human.
|
||||||
|
previous_messages: History of messages in the conversation.
|
||||||
|
"""
|
||||||
|
|
||||||
task_id: str
|
task_id: str
|
||||||
crew_execution_id: str
|
crew_execution_id: str
|
||||||
task_key: str
|
task_key: str
|
||||||
task_output: str
|
task_output: str
|
||||||
human_feedback: str
|
human_feedback: str
|
||||||
previous_messages: List[Dict[str, str]]
|
previous_messages: list[dict[str, str]]
|
||||||
|
|
||||||
|
|
||||||
class CrewInputsWithHITL(TypedDict, total=False):
|
class CrewInputsWithHITL(TypedDict, total=False):
|
||||||
"""Crew inputs that may contain HITL resume information."""
|
"""Crew inputs that may contain HITL resume information.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
_hitl_resume: Optional HITL resume information for continuing execution.
|
||||||
|
"""
|
||||||
|
|
||||||
_hitl_resume: HITLResumeInfo
|
_hitl_resume: HITLResumeInfo
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
|
"""Usage metrics tracking for CrewAI execution.
|
||||||
|
|
||||||
|
This module provides models for tracking token usage and request metrics
|
||||||
|
during crew and agent execution.
|
||||||
|
"""
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
from typing_extensions import Self
|
||||||
|
|
||||||
|
|
||||||
class UsageMetrics(BaseModel):
|
class UsageMetrics(BaseModel):
|
||||||
"""
|
"""Track usage metrics for crew execution.
|
||||||
Model to track usage metrics for the crew's execution.
|
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
total_tokens: Total number of tokens used.
|
total_tokens: Total number of tokens used.
|
||||||
@@ -27,12 +33,11 @@ class UsageMetrics(BaseModel):
|
|||||||
default=0, description="Number of successful requests made."
|
default=0, description="Number of successful requests made."
|
||||||
)
|
)
|
||||||
|
|
||||||
def add_usage_metrics(self, usage_metrics: "UsageMetrics"):
|
def add_usage_metrics(self, usage_metrics: Self) -> None:
|
||||||
"""
|
"""Add usage metrics from another UsageMetrics object.
|
||||||
Add the usage metrics from another UsageMetrics object.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
usage_metrics (UsageMetrics): The usage metrics to add.
|
usage_metrics: The usage metrics to add.
|
||||||
"""
|
"""
|
||||||
self.total_tokens += usage_metrics.total_tokens
|
self.total_tokens += usage_metrics.total_tokens
|
||||||
self.prompt_tokens += usage_metrics.prompt_tokens
|
self.prompt_tokens += usage_metrics.prompt_tokens
|
||||||
|
|||||||
Reference in New Issue
Block a user