mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-26 16:48:13 +00:00
high level chat working
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user