high level chat working

This commit is contained in:
Brandon Hancock
2024-12-27 11:21:40 -05:00
parent 2bf5b15f1e
commit 2f882d68ad
9 changed files with 86 additions and 61 deletions

View File

@@ -1,5 +1,6 @@
import json
import subprocess
from typing import Optional
import click
from packaging import version
@@ -9,7 +10,7 @@ from crewai.cli.version import get_crewai_version
from crewai.types.crew_chat import ChatInputs
def fetch_crew_inputs() -> ChatInputs:
def fetch_crew_inputs() -> Optional[ChatInputs]:
"""
Fetch the crew's ChatInputs (a structure containing crew_description and input fields)
by running "uv run fetch_chat_inputs", which prints JSON representing a ChatInputs object.
@@ -37,22 +38,37 @@ def fetch_crew_inputs() -> ChatInputs:
try:
result = subprocess.run(command, capture_output=True, text=True, check=True)
stdout_str = result.stdout.strip()
stdout_lines = result.stdout.strip().splitlines()
if not stdout_str:
return ChatInputs(crew_name=crew_name)
# Find the line that contains the JSON data
json_line = next(
(
line
for line in stdout_lines
if line.startswith("{") and line.endswith("}")
),
None,
)
if not json_line:
click.echo(
"No valid JSON output received from `fetch_chat_inputs` command.",
err=True,
)
return None
try:
raw_data = json.loads(stdout_str)
raw_data = json.loads(json_line)
chat_inputs = ChatInputs(**raw_data)
if crew_name:
chat_inputs.crew_name = crew_name
return chat_inputs
except json.JSONDecodeError as e:
click.echo(
f"Unable to parse JSON from `fetch_chat_inputs` output: {e}", err=True
f"Unable to parse JSON from `fetch_chat_inputs` output: {e}\nOutput: {repr(json_line)}",
err=True,
)
return ChatInputs(crew_name=crew_name)
return None
except subprocess.CalledProcessError as e:
click.echo(f"An error occurred while fetching chat inputs: {e}", err=True)
@@ -67,4 +83,4 @@ def fetch_crew_inputs() -> ChatInputs:
except Exception as e:
click.echo(f"An unexpected error occurred: {e}", err=True)
return ChatInputs(crew_name=crew_name)
return None