mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
Fix CI issues: lint, type checker, and test failures
- Remove unused imports from test and example files - Fix f-string formatting in examples - Add proper type handling for Union[str, Dict] in agent_utils.py - Fix XML parser test assertion to match expected output - Use isinstance() for proper type narrowing in LLM calls Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
Example demonstrating the new LLM generations and logprobs functionality.
|
||||
"""
|
||||
|
||||
from crewai import Agent, Task, Crew, LLM
|
||||
from crewai.utilities.xml_parser import extract_xml_content, extract_multiple_xml_tags
|
||||
from crewai import Agent, Task, LLM
|
||||
from crewai.utilities.xml_parser import extract_xml_content
|
||||
|
||||
|
||||
def example_multiple_generations():
|
||||
@@ -133,7 +133,7 @@ def example_logprobs_analysis():
|
||||
print(f"Available logprobs data: {len(logprobs)} choices")
|
||||
|
||||
if usage:
|
||||
print(f"\nToken usage:")
|
||||
print("\nToken usage:")
|
||||
print(f"Prompt tokens: {usage.get('prompt_tokens', 'N/A')}")
|
||||
print(f"Completion tokens: {usage.get('completion_tokens', 'N/A')}")
|
||||
print(f"Total tokens: {usage.get('total_tokens', 'N/A')}")
|
||||
|
||||
@@ -109,7 +109,11 @@ def handle_max_iterations_exceeded(
|
||||
)
|
||||
raise ValueError("Invalid response from LLM call - None or empty.")
|
||||
|
||||
formatted_answer = format_answer(answer)
|
||||
text_answer = answer
|
||||
if isinstance(answer, dict) and "content" in answer:
|
||||
text_answer = answer["content"]
|
||||
|
||||
formatted_answer = format_answer(str(text_answer))
|
||||
# Return the formatted answer, regardless of its type
|
||||
return formatted_answer
|
||||
|
||||
@@ -149,11 +153,18 @@ def get_llm_response(
|
||||
) -> Union[str, Dict[str, Any]]:
|
||||
"""Call the LLM and return the response, handling any invalid responses."""
|
||||
try:
|
||||
answer = llm.call(
|
||||
messages,
|
||||
callbacks=callbacks,
|
||||
return_full_completion=return_full_completion,
|
||||
)
|
||||
from crewai.llm import LLM
|
||||
if isinstance(llm, LLM) and return_full_completion:
|
||||
answer = llm.call(
|
||||
messages,
|
||||
callbacks=callbacks,
|
||||
return_full_completion=return_full_completion,
|
||||
)
|
||||
else:
|
||||
answer = llm.call(
|
||||
messages,
|
||||
callbacks=callbacks,
|
||||
)
|
||||
except Exception as e:
|
||||
printer.print(
|
||||
content=f"Error during LLM call: {e}",
|
||||
@@ -190,12 +201,12 @@ def process_llm_response(
|
||||
if not use_stop_words:
|
||||
try:
|
||||
# Preliminary parsing to check for errors.
|
||||
format_answer(text_answer)
|
||||
format_answer(str(text_answer))
|
||||
except OutputParserException as e:
|
||||
if FINAL_ANSWER_AND_PARSABLE_ACTION_ERROR_MESSAGE in e.error:
|
||||
text_answer = text_answer.split("Observation:")[0].strip()
|
||||
text_answer = str(text_answer).split("Observation:")[0].strip()
|
||||
|
||||
return format_answer(text_answer)
|
||||
return format_answer(str(text_answer))
|
||||
|
||||
|
||||
def handle_agent_action_core(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import pytest
|
||||
from unittest.mock import Mock, patch
|
||||
from crewai import Agent, Task, Crew, LLM
|
||||
from crewai.lite_agent import LiteAgent
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import pytest
|
||||
from unittest.mock import Mock, patch
|
||||
from crewai import Agent, Task, LLM
|
||||
from crewai import Agent, LLM
|
||||
from crewai.tasks.task_output import TaskOutput
|
||||
from crewai.lite_agent import LiteAgent, LiteAgentOutput
|
||||
from crewai.lite_agent import LiteAgentOutput
|
||||
from crewai.utilities.xml_parser import (
|
||||
extract_xml_content,
|
||||
extract_all_xml_content,
|
||||
@@ -202,7 +201,7 @@ class TestXMLParser:
|
||||
"""Test removing XML tags and their content."""
|
||||
text = "Keep this <thinking>Remove this</thinking> and this"
|
||||
result = remove_xml_tags(text, ["thinking"])
|
||||
assert result == "Keep this and this"
|
||||
assert result == "Keep this and this"
|
||||
|
||||
def test_strip_xml_tags_keep_content(self):
|
||||
"""Test stripping XML tags but keeping content."""
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import pytest
|
||||
from crewai.utilities.xml_parser import (
|
||||
extract_xml_content,
|
||||
extract_all_xml_content,
|
||||
|
||||
Reference in New Issue
Block a user