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

Raise an error if an LLM doesnt return a response #1548

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/crewai/agents/crew_agent_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ def _invoke_loop(self, formatted_answer=None):
callbacks=self.callbacks,
)

if answer is None or answer == "":
self._printer.print(
content="Received None or empty response from LLM call.",
color="red",
)
raise ValueError(
"Invalid response from LLM call - None or empty."
)

if not self.use_stop_words:
try:
self._format_answer(answer)
Expand Down
10 changes: 5 additions & 5 deletions src/crewai/llm.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from contextlib import contextmanager
from typing import Any, Dict, List, Optional, Union
import io
import logging
import sys
import warnings
from contextlib import contextmanager
from typing import Any, Dict, List, Optional, Union

import litellm
from litellm import get_supported_openai_params

from crewai.utilities.exceptions.context_window_exceeding_exception import (
LLMContextLengthExceededException,
)

import sys
import io


class FilteredStream(io.StringIO):
def write(self, s):
Expand Down
Loading