mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Limit retry to transient openai API errors. Return non-empty tool output
This commit is contained in:
@@ -78,10 +78,8 @@ def _extract_text_for_instructions(content: Union[str, List, Dict, None]) -> str
|
|||||||
@retry(
|
@retry(
|
||||||
retry=(
|
retry=(
|
||||||
retry_if_exception_type(openai._exceptions.APITimeoutError)
|
retry_if_exception_type(openai._exceptions.APITimeoutError)
|
||||||
| retry_if_exception_type(openai._exceptions.APIError)
|
|
||||||
| retry_if_exception_type(openai._exceptions.APIConnectionError)
|
|
||||||
| retry_if_exception_type(openai._exceptions.RateLimitError)
|
| retry_if_exception_type(openai._exceptions.RateLimitError)
|
||||||
| retry_if_exception_type(openai._exceptions.APIStatusError)
|
| retry_if_exception_type(openai._exceptions.InternalServerError)
|
||||||
| retry_if_exception_type(ValueError)
|
| retry_if_exception_type(ValueError)
|
||||||
),
|
),
|
||||||
wait=wait_random_exponential(min=1, max=10),
|
wait=wait_random_exponential(min=1, max=10),
|
||||||
@@ -249,10 +247,8 @@ def completion_with_backoff(
|
|||||||
@retry(
|
@retry(
|
||||||
retry=(
|
retry=(
|
||||||
retry_if_exception_type(openai._exceptions.APITimeoutError)
|
retry_if_exception_type(openai._exceptions.APITimeoutError)
|
||||||
| retry_if_exception_type(openai._exceptions.APIError)
|
|
||||||
| retry_if_exception_type(openai._exceptions.APIConnectionError)
|
|
||||||
| retry_if_exception_type(openai._exceptions.RateLimitError)
|
| retry_if_exception_type(openai._exceptions.RateLimitError)
|
||||||
| retry_if_exception_type(openai._exceptions.APIStatusError)
|
| retry_if_exception_type(openai._exceptions.InternalServerError)
|
||||||
| retry_if_exception_type(ValueError)
|
| retry_if_exception_type(ValueError)
|
||||||
),
|
),
|
||||||
wait=wait_exponential(multiplier=1, min=4, max=10),
|
wait=wait_exponential(multiplier=1, min=4, max=10),
|
||||||
@@ -415,10 +411,8 @@ async def chat_completion_with_backoff(
|
|||||||
@retry(
|
@retry(
|
||||||
retry=(
|
retry=(
|
||||||
retry_if_exception_type(openai._exceptions.APITimeoutError)
|
retry_if_exception_type(openai._exceptions.APITimeoutError)
|
||||||
| retry_if_exception_type(openai._exceptions.APIError)
|
|
||||||
| retry_if_exception_type(openai._exceptions.APIConnectionError)
|
|
||||||
| retry_if_exception_type(openai._exceptions.RateLimitError)
|
| retry_if_exception_type(openai._exceptions.RateLimitError)
|
||||||
| retry_if_exception_type(openai._exceptions.APIStatusError)
|
| retry_if_exception_type(openai._exceptions.InternalServerError)
|
||||||
| retry_if_exception_type(ValueError)
|
| retry_if_exception_type(ValueError)
|
||||||
),
|
),
|
||||||
wait=wait_random_exponential(min=1, max=10),
|
wait=wait_random_exponential(min=1, max=10),
|
||||||
@@ -529,10 +523,8 @@ def responses_completion_with_backoff(
|
|||||||
@retry(
|
@retry(
|
||||||
retry=(
|
retry=(
|
||||||
retry_if_exception_type(openai._exceptions.APITimeoutError)
|
retry_if_exception_type(openai._exceptions.APITimeoutError)
|
||||||
| retry_if_exception_type(openai._exceptions.APIError)
|
|
||||||
| retry_if_exception_type(openai._exceptions.APIConnectionError)
|
|
||||||
| retry_if_exception_type(openai._exceptions.RateLimitError)
|
| retry_if_exception_type(openai._exceptions.RateLimitError)
|
||||||
| retry_if_exception_type(openai._exceptions.APIStatusError)
|
| retry_if_exception_type(openai._exceptions.InternalServerError)
|
||||||
| retry_if_exception_type(ValueError)
|
| retry_if_exception_type(ValueError)
|
||||||
),
|
),
|
||||||
wait=wait_exponential(multiplier=1, min=4, max=10),
|
wait=wait_exponential(multiplier=1, min=4, max=10),
|
||||||
@@ -764,7 +756,7 @@ def format_message_for_api(raw_messages: List[ChatMessage], api_base_url: str) -
|
|||||||
{
|
{
|
||||||
"type": "function_call_output",
|
"type": "function_call_output",
|
||||||
"call_id": tool_call_id,
|
"call_id": tool_call_id,
|
||||||
"output": part.get("content"),
|
"output": part.get("content") or "No output",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -773,7 +765,7 @@ def format_message_for_api(raw_messages: List[ChatMessage], api_base_url: str) -
|
|||||||
"role": "tool",
|
"role": "tool",
|
||||||
"tool_call_id": tool_call_id,
|
"tool_call_id": tool_call_id,
|
||||||
"name": part.get("name"),
|
"name": part.get("name"),
|
||||||
"content": part.get("content"),
|
"content": part.get("content") or "No output",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user