Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version check to crew_chat.py #1966

Merged
merged 6 commits into from
Jan 24, 2025
39 changes: 39 additions & 0 deletions src/crewai/cli/crew_chat.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,63 @@
# Standard library
import json
import re
import sys
from pathlib import Path
from typing import Any, Dict, List, Optional, Set, Tuple

# Third-party
import click
import tomli
from packaging import version

# Local
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop unnecessary comments like this and the ones above.

from crewai.cli.utils import read_toml
from crewai.cli.version import get_crewai_version
from crewai.crew import Crew
from crewai.llm import LLM
from crewai.types.crew_chat import ChatInputField, ChatInputs
from crewai.utilities.llm_utils import create_llm

MIN_REQUIRED_VERSION = "0.98.0"


def check_conversational_crews_version(crewai_version: str, pyproject_data: dict) -> bool:
"""
Check if the installed crewAI version supports conversational crews.

Args:
crewai_version: The current version of crewAI
pyproject_data: Dictionary containing pyproject.toml data

Returns:
bool: True if version check passes, False otherwise
"""
try:
if version.parse(crewai_version) < version.parse(MIN_REQUIRED_VERSION):
if pyproject_data.get("tool", {}).get("poetry"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this check right? We can get rid of this.

click.secho(
"You are using an older version of crewAI that doesn't support conversational crews. "
"Run 'uv upgrade crewai' to get the latest version.",
fg="red"
)
return False
except version.InvalidVersion:
click.secho("Invalid crewAI version format detected", fg="red")
return False
return True


def run_chat():
"""
Runs an interactive chat loop using the Crew's chat LLM with function calling.
Incorporates crew_name, crew_description, and input fields to build a tool schema.
Exits if crew_name or crew_description are missing.
"""
crewai_version = get_crewai_version()
pyproject_data = read_toml()

if not check_conversational_crews_version(crewai_version, pyproject_data):
return
crew, crew_name = load_crew_and_name()
chat_llm = initialize_chat_llm(crew)
if not chat_llm:
Expand Down
Loading