Skip to content

Commit

Permalink
rename error_handling.py to error_handler.py (#1287)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluder-Paradyne authored Sep 27, 2023
1 parent 83d09f7 commit 1c2425d
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions superagi/agent/agent_iteration_step_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from superagi.agent.tool_builder import ToolBuilder
from superagi.apm.event_handler import EventHandler
from superagi.config.config import get_config
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.helper.token_counter import TokenCounter
from superagi.lib.logger import logger
from superagi.models.agent import Agent
Expand Down Expand Up @@ -75,7 +75,7 @@ def execute_step(self):
response = self.llm.chat_completion(messages, TokenCounter(session=self.session, organisation_id=organisation.id).token_limit(self.llm.get_model()) - current_tokens)

Check warning on line 75 in superagi/agent/agent_iteration_step_handler.py

View check run for this annotation

Codecov / codecov/patch

superagi/agent/agent_iteration_step_handler.py#L74-L75

Added lines #L74 - L75 were not covered by tests

if 'error' in response and response['message'] is not None:
ErrorHandling.handle_openai_errors(self.session, self.agent_id, self.agent_execution_id, response['message'])
ErrorHandler.handle_openai_errors(self.session, self.agent_id, self.agent_execution_id, response['message'])

Check warning on line 78 in superagi/agent/agent_iteration_step_handler.py

View check run for this annotation

Codecov / codecov/patch

superagi/agent/agent_iteration_step_handler.py#L78

Added line #L78 was not covered by tests

if 'content' not in response or response['content'] is None:
raise RuntimeError(f"Failed to get response from llm")
Expand Down
4 changes: 2 additions & 2 deletions superagi/agent/agent_message_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy import asc

from superagi.config.config import get_config
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.helper.prompt_reader import PromptReader
from superagi.helper.token_counter import TokenCounter
from superagi.models.agent_execution import AgentExecution
Expand Down Expand Up @@ -124,7 +124,7 @@ def _build_ltm_summary(self, past_messages, output_token_limit) -> str:
ltm_summary = self.llm.chat_completion(msgs)

if 'error' in ltm_summary and ltm_summary['message'] is not None:
ErrorHandling.handle_openai_errors(self.session, self.agent_id, self.agent_execution_id, ltm_summary['message'])
ErrorHandler.handle_openai_errors(self.session, self.agent_id, self.agent_execution_id, ltm_summary['message'])

Check warning on line 127 in superagi/agent/agent_message_builder.py

View check run for this annotation

Codecov / codecov/patch

superagi/agent/agent_message_builder.py#L127

Added line #L127 was not covered by tests

execution = AgentExecution(id=self.agent_execution_id)
agent_execution_configs = {"ltm_summary": ltm_summary["content"]}
Expand Down
6 changes: 3 additions & 3 deletions superagi/agent/agent_tool_step_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from superagi.agent.output_parser import AgentSchemaToolOutputParser
from superagi.agent.queue_step_handler import QueueStepHandler
from superagi.agent.tool_builder import ToolBuilder
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.helper.prompt_reader import PromptReader
from superagi.helper.token_counter import TokenCounter
from superagi.lib.logger import logger
Expand Down Expand Up @@ -108,7 +108,7 @@ def _process_input_instruction(self, agent_config, agent_execution_config, step_
response = self.llm.chat_completion(messages, TokenCounter(session=self.session, organisation_id=self.organisation.id).token_limit(self.llm.get_model()) - current_tokens)

Check warning on line 108 in superagi/agent/agent_tool_step_handler.py

View check run for this annotation

Codecov / codecov/patch

superagi/agent/agent_tool_step_handler.py#L108

Added line #L108 was not covered by tests

if 'error' in response and response['message'] is not None:
ErrorHandling.handle_openai_errors(self.session, self.agent_id, self.agent_execution_id, response['message'])
ErrorHandler.handle_openai_errors(self.session, self.agent_id, self.agent_execution_id, response['message'])

Check warning on line 111 in superagi/agent/agent_tool_step_handler.py

View check run for this annotation

Codecov / codecov/patch

superagi/agent/agent_tool_step_handler.py#L111

Added line #L111 was not covered by tests
# ModelsHelper(session=self.session, organisation_id=organisation.id).create_call_log(execution.name,agent_config['agent_id'],response['response'].usage.total_tokens,json.loads(response['content'])['tool']['name'],agent_config['model'])
if 'content' not in response or response['content'] is None:
raise RuntimeError(f"Failed to get response from llm")
Expand Down Expand Up @@ -143,7 +143,7 @@ def _process_output_instruction(self, final_response: str, step_tool: AgentWorkf
TokenCounter(session=self.session, organisation_id=self.organisation.id).token_limit(self.llm.get_model()) - current_tokens)

if 'error' in response and response['message'] is not None:
ErrorHandling.handle_openai_errors(self.session, self.agent_id, self.agent_execution_id, response['message'])
ErrorHandler.handle_openai_errors(self.session, self.agent_id, self.agent_execution_id, response['message'])

Check warning on line 146 in superagi/agent/agent_tool_step_handler.py

View check run for this annotation

Codecov / codecov/patch

superagi/agent/agent_tool_step_handler.py#L146

Added line #L146 was not covered by tests

if 'content' not in response or response['content'] is None:
raise RuntimeError(f"ToolWorkflowStepHandler: Failed to get output response from llm")
Expand Down
4 changes: 2 additions & 2 deletions superagi/agent/queue_step_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from superagi.agent.agent_message_builder import AgentLlmMessageBuilder
from superagi.agent.task_queue import TaskQueue
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.helper.json_cleaner import JsonCleaner
from superagi.helper.prompt_reader import PromptReader
from superagi.helper.token_counter import TokenCounter
Expand Down Expand Up @@ -93,7 +93,7 @@ def _process_input_instruction(self, step_tool):
response = self.llm.chat_completion(messages, TokenCounter(session=self.session, organisation_id=self.organisation.id).token_limit(self.llm.get_model()) - current_tokens)

Check warning on line 93 in superagi/agent/queue_step_handler.py

View check run for this annotation

Codecov / codecov/patch

superagi/agent/queue_step_handler.py#L93

Added line #L93 was not covered by tests

if 'error' in response and response['message'] is not None:
ErrorHandling.handle_openai_errors(self.session, self.agent_id, self.agent_execution_id, response['message'])
ErrorHandler.handle_openai_errors(self.session, self.agent_id, self.agent_execution_id, response['message'])

Check warning on line 96 in superagi/agent/queue_step_handler.py

View check run for this annotation

Codecov / codecov/patch

superagi/agent/queue_step_handler.py#L96

Added line #L96 was not covered by tests

if 'content' not in response or response['content'] is None:
raise RuntimeError(f"Failed to get response from llm")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from superagi.models.agent_execution import AgentExecution
from superagi.models.agent_execution_feed import AgentExecutionFeed

class ErrorHandling:
class ErrorHandler:

def handle_openai_errors(session, agent_id, agent_execution_id, error_message):
execution = session.query(AgentExecution).filter(AgentExecution.id == agent_execution_id).first()
Expand Down
4 changes: 2 additions & 2 deletions superagi/tools/code/improve_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pydantic import BaseModel, Field

from superagi.agent.agent_prompt_builder import AgentPromptBuilder
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.helper.prompt_reader import PromptReader
from superagi.helper.token_counter import TokenCounter
from superagi.lib.logger import logger
Expand Down Expand Up @@ -77,7 +77,7 @@ def _execute(self) -> str:
result = self.llm.chat_completion([{'role': 'system', 'content': prompt}])

if result is not None and 'error' in result and result['message'] is not None:
ErrorHandling.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
ErrorHandler.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])

Check warning on line 80 in superagi/tools/code/improve_code.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/code/improve_code.py#L80

Added line #L80 was not covered by tests

# Extract the response first
response = result.get('response')
Expand Down
4 changes: 2 additions & 2 deletions superagi/tools/code/write_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pydantic import BaseModel, Field

from superagi.agent.agent_prompt_builder import AgentPromptBuilder
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.helper.prompt_reader import PromptReader
from superagi.helper.token_counter import TokenCounter
from superagi.lib.logger import logger
Expand Down Expand Up @@ -81,7 +81,7 @@ def _execute(self, code_description: str) -> str:
result = self.llm.chat_completion(messages, max_tokens=(token_limit - total_tokens - 100))

if 'error' in result and result['message'] is not None:
ErrorHandling.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
ErrorHandler.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])

Check warning on line 84 in superagi/tools/code/write_code.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/code/write_code.py#L84

Added line #L84 was not covered by tests

# Get all filenames and corresponding code blocks
regex = r"(\S+?)\n```\S*\n(.+?)```"
Expand Down
4 changes: 2 additions & 2 deletions superagi/tools/code/write_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pydantic import BaseModel, Field

from superagi.agent.agent_prompt_builder import AgentPromptBuilder
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.helper.prompt_reader import PromptReader
from superagi.helper.token_counter import TokenCounter
from superagi.lib.logger import logger
Expand Down Expand Up @@ -75,7 +75,7 @@ def _execute(self, task_description: str, spec_file_name: str) -> str:
result = self.llm.chat_completion(messages, max_tokens=(token_limit - total_tokens - 100))

if 'error' in result and result['message'] is not None:
ErrorHandling.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
ErrorHandler.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])

Check warning on line 78 in superagi/tools/code/write_spec.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/code/write_spec.py#L78

Added line #L78 was not covered by tests

# Save the specification to a file
write_result = self.resource_manager.write_file(spec_file_name, result["content"])
Expand Down
4 changes: 2 additions & 2 deletions superagi/tools/code/write_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pydantic import BaseModel, Field

from superagi.agent.agent_prompt_builder import AgentPromptBuilder
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.helper.prompt_reader import PromptReader
from superagi.helper.token_counter import TokenCounter
from superagi.lib.logger import logger
Expand Down Expand Up @@ -92,7 +92,7 @@ def _execute(self, test_description: str, test_file_name: str) -> str:
result = self.llm.chat_completion(messages, max_tokens=(token_limit - total_tokens - 100))

if 'error' in result and result['message'] is not None:
ErrorHandling.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
ErrorHandler.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])

Check warning on line 95 in superagi/tools/code/write_test.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/code/write_test.py#L95

Added line #L95 was not covered by tests

regex = r"(\S+?)\n```\S*\n(.+?)```"
matches = re.finditer(regex, result["content"], re.DOTALL)
Expand Down
4 changes: 2 additions & 2 deletions superagi/tools/duck_duck_go/duck_duck_go_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests
from typing import Type, Optional,Union
import time
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.lib.logger import logger
from pydantic import BaseModel, Field
from duckduckgo_search import DDGS
Expand Down Expand Up @@ -176,5 +176,5 @@ def summarise_result(self, query, snippets):
result = self.llm.chat_completion(messages, max_tokens=self.max_token_limit)

if 'error' in result and result['message'] is not None:
ErrorHandling.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
ErrorHandler.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])

Check warning on line 179 in superagi/tools/duck_duck_go/duck_duck_go_search.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/duck_duck_go/duck_duck_go_search.py#L179

Added line #L179 was not covered by tests
return result["content"]
4 changes: 2 additions & 2 deletions superagi/tools/github/review_pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Type, Optional

from pydantic import BaseModel, Field
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler

from superagi.helper.github_helper import GithubHelper
from superagi.helper.json_cleaner import JsonCleaner
Expand Down Expand Up @@ -92,7 +92,7 @@ def run_code_review(self, github_helper, content, latest_commit_id, organisation
result = self.llm.chat_completion(messages, max_tokens=(token_limit - total_tokens - 100))

Check warning on line 92 in superagi/tools/github/review_pull_request.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/github/review_pull_request.py#L92

Added line #L92 was not covered by tests

if 'error' in result and result['message'] is not None:
ErrorHandling.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
ErrorHandler.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
response = result["content"]

Check warning on line 96 in superagi/tools/github/review_pull_request.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/github/review_pull_request.py#L95-L96

Added lines #L95 - L96 were not covered by tests
if response.startswith("```") and response.endswith("```"):
response = "```".join(response.split("```")[1:-1])
Expand Down
4 changes: 2 additions & 2 deletions superagi/tools/google_search/google_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Type, Optional

from pydantic import BaseModel, Field
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler

from superagi.helper.google_search import GoogleSearchWrap
from superagi.helper.token_counter import TokenCounter
Expand Down Expand Up @@ -94,5 +94,5 @@ def summarise_result(self, query, snippets):
result = self.llm.chat_completion(messages, max_tokens=self.max_token_limit)

if 'error' in result and result['message'] is not None:
ErrorHandling.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
ErrorHandler.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])

Check warning on line 97 in superagi/tools/google_search/google_search.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/google_search/google_search.py#L97

Added line #L97 was not covered by tests
return result["content"]
4 changes: 2 additions & 2 deletions superagi/tools/google_serp_search/google_serp_search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Type, Optional, Any
from pydantic import BaseModel, Field
import aiohttp
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler

Check warning on line 4 in superagi/tools/google_serp_search/google_serp_search.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/google_serp_search/google_serp_search.py#L4

Added line #L4 was not covered by tests
from superagi.helper.google_serp import GoogleSerpApiWrap
from superagi.llms.base_llm import BaseLlm
from superagi.models.agent_execution import AgentExecution
Expand Down Expand Up @@ -73,5 +73,5 @@ def summarise_result(self, query, snippets):
result = self.llm.chat_completion(messages, max_tokens=self.max_token_limit)

if 'error' in result and result['message'] is not None:
ErrorHandling.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
ErrorHandler.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])

Check warning on line 76 in superagi/tools/google_serp_search/google_serp_search.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/google_serp_search/google_serp_search.py#L76

Added line #L76 was not covered by tests
return result["content"]
4 changes: 2 additions & 2 deletions superagi/tools/instagram_tool/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import boto3
import os
from superagi.config.config import get_config
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.helper.resource_helper import ResourceHelper
from typing import Type, Optional
from pydantic import BaseModel, Field
Expand Down Expand Up @@ -117,7 +117,7 @@ def create_caption(self, photo_description: str) -> str:
messages = [{"role": "system", "content": caption_prompt}]
result = self.llm.chat_completion(messages, max_tokens=self.max_token_limit)
if 'error' in result and result['message'] is not None:
ErrorHandling.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
ErrorHandler.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])

Check warning on line 120 in superagi/tools/instagram_tool/instagram.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/instagram_tool/instagram.py#L120

Added line #L120 was not covered by tests
caption=result["content"]

encoded_caption=urllib. parse. quote(caption)
Expand Down
4 changes: 2 additions & 2 deletions superagi/tools/searx/searx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Type, Optional
from pydantic import BaseModel, Field
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.llms.base_llm import BaseLlm
from superagi.models.agent_execution import AgentExecution
from superagi.models.agent_execution_feed import AgentExecutionFeed
Expand Down Expand Up @@ -74,5 +74,5 @@ def summarise_result(self, query, snippets):
result = self.llm.chat_completion(messages, max_tokens=self.max_token_limit)

if 'error' in result and result['message'] is not None:
ErrorHandling.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
ErrorHandler.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])

Check warning on line 77 in superagi/tools/searx/searx.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/searx/searx.py#L77

Added line #L77 was not covered by tests
return result["content"]
4 changes: 2 additions & 2 deletions superagi/tools/thinking/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pydantic import BaseModel, Field

from superagi.agent.agent_prompt_builder import AgentPromptBuilder
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler
from superagi.helper.prompt_reader import PromptReader
from superagi.lib.logger import logger
from superagi.llms.base_llm import BaseLlm
Expand Down Expand Up @@ -68,7 +68,7 @@ def _execute(self, task_description: str):
result = self.llm.chat_completion(messages, max_tokens=self.max_token_limit)

if 'error' in result and result['message'] is not None:
ErrorHandling.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])
ErrorHandler.handle_openai_errors(self.toolkit_config.session, self.agent_id, self.agent_execution_id, result['message'])

Check warning on line 71 in superagi/tools/thinking/tools.py

View check run for this annotation

Codecov / codecov/patch

superagi/tools/thinking/tools.py#L71

Added line #L71 was not covered by tests
return result["content"]
except Exception as e:
logger.error(e)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/helper/test_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest.mock import Mock, patch
from superagi.models.agent_execution import AgentExecution
from superagi.models.agent_execution_feed import AgentExecutionFeed
from superagi.helper.error_handling import ErrorHandling
from superagi.helper.error_handler import ErrorHandler

def test_handle_error():
session = Mock()
Expand All @@ -14,6 +14,6 @@ def test_handle_error():
mock_query.filter().first.return_value = AgentExecution(id=agent_execution_id)
session.query.return_value = mock_query

ErrorHandling.handle_openai_errors(session, agent_id, agent_execution_id, error_message)
ErrorHandler.handle_openai_errors(session, agent_id, agent_execution_id, error_message)

session.query.assert_called_once_with(AgentExecution)

0 comments on commit 1c2425d

Please sign in to comment.