From 8427e627521439be0146c4f18a932bebdd73a215 Mon Sep 17 00:00:00 2001 From: Tyler White Date: Mon, 2 Dec 2024 08:46:35 -0500 Subject: [PATCH] style(ruff): resolve all outstanding default violations (#68) --- .pre-commit-config.yaml | 5 +++-- Quickstart.ipynb | 5 +++-- agent_gateway/agents/agent.py | 6 +++--- agent_gateway/chains/llm_chain.py | 4 ++-- agent_gateway/executors/agent_executor.py | 1 - agent_gateway/gateway/gateway.py | 2 +- agent_gateway/gateway/output_parser.py | 2 +- agent_gateway/gateway/planner.py | 2 +- agent_gateway/tools/snowflake_tools.py | 4 ++-- agent_gateway/tools/utils.py | 2 +- demo_app/demo_app.py | 3 +-- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7a1bf51..e2708c1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,11 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + rev: v5.0.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.1 + rev: v0.8.0 hooks: + - id: ruff - id: ruff-format diff --git a/Quickstart.ipynb b/Quickstart.ipynb index 28ecf84..a34def8 100644 --- a/Quickstart.ipynb +++ b/Quickstart.ipynb @@ -62,7 +62,7 @@ "from agent_gateway import Agent\n", "from agent_gateway.tools import CortexSearchTool, CortexAnalystTool, PythonTool\n", "from snowflake.snowpark import Session\n", - "import os, time\n", + "import os\n", "\n", "connection_parameters = {\n", " \"account\": os.getenv(\"SNOWFLAKE_ACCOUNT\"),\n", @@ -136,7 +136,8 @@ "metadata": {}, "outputs": [], "source": [ - "import requests, json\n", + "import requests\n", + "import json\n", "\n", "\n", "class NewsTool:\n", diff --git a/agent_gateway/agents/agent.py b/agent_gateway/agents/agent.py index 4b89fb1..12aba72 100644 --- a/agent_gateway/agents/agent.py +++ b/agent_gateway/agents/agent.py @@ -21,7 +21,7 @@ import yaml from chains.llm_chain import LLMChain -from langchain.agents.agent import AgentOutputParser, BaseSingleActionAgent +from langchain.agents.agent import BaseSingleActionAgent from langchain.agents.agent_types import AgentType from langchain.callbacks.base import BaseCallbackManager from langchain.callbacks.manager import Callbacks @@ -130,7 +130,7 @@ def plan( full_inputs = self.get_full_inputs(intermediate_steps, **kwargs) full_output = self.llm_chain.predict(callbacks=callbacks, **full_inputs) return self.output_parser.parse(full_output) - except Exception as e: + except Exception: full_inputs["agent_scratchpad"] = ( full_inputs["agent_scratchpad"] + full_output + "\nAction: " ) @@ -161,7 +161,7 @@ async def aplan( callbacks=callbacks, **full_inputs ) agent_output = await self.output_parser.aparse(full_output) - except Exception as e: + except Exception: full_inputs["agent_scratchpad"] = ( full_inputs["agent_scratchpad"] + full_output + "\nAction: " ) diff --git a/agent_gateway/chains/llm_chain.py b/agent_gateway/chains/llm_chain.py index b657568..741e975 100644 --- a/agent_gateway/chains/llm_chain.py +++ b/agent_gateway/chains/llm_chain.py @@ -133,7 +133,7 @@ def generate( callbacks=run_manager.get_child() if run_manager else None, **self.llm_kwargs, ) - except: + except Exception: text = prompts[0].text # Try removing in-context examples first_index = text.find("Question:") @@ -167,7 +167,7 @@ async def agenerate( callbacks=run_manager.get_child() if run_manager else None, **self.llm_kwargs, ) - except: + except Exception: text = prompts[0].text # Try removing in-context examples first_index = text.find("Question:") diff --git a/agent_gateway/executors/agent_executor.py b/agent_gateway/executors/agent_executor.py index 53d42e0..d211b2d 100644 --- a/agent_gateway/executors/agent_executor.py +++ b/agent_gateway/executors/agent_executor.py @@ -30,7 +30,6 @@ ) from langchain.pydantic_v1 import root_validator from langchain.schema import AgentAction, AgentFinish, OutputParserException -from langchain.tools import BaseTool from langchain.utilities.asyncio import asyncio_timeout from langchain.utils.input import get_color_mapping diff --git a/agent_gateway/gateway/gateway.py b/agent_gateway/gateway/gateway.py index 5e40664..d5eb58f 100644 --- a/agent_gateway/gateway/gateway.py +++ b/agent_gateway/gateway/gateway.py @@ -69,7 +69,7 @@ async def arun(self, prompt: str) -> str: try: snowflake_response = self._parse_snowflake_response(response_text) return snowflake_response - except: + except Exception: raise AgentGatewayError( message=f"Failed Cortex LLM Request. Unable to parse response. See details:{response_text}" ) diff --git a/agent_gateway/gateway/output_parser.py b/agent_gateway/gateway/output_parser.py index 30f27b9..01b4ed5 100644 --- a/agent_gateway/gateway/output_parser.py +++ b/agent_gateway/gateway/output_parser.py @@ -188,7 +188,7 @@ def instantiate_task( args = _parse_llm_compiler_action_args(args) if tool_name == "fuse": # fuse does not have a tool - tool_func = lambda x: None + tool_func = lambda x: None # noqa: E731 stringify_rule = None else: tool = _find_tool(tool_name, tools) diff --git a/agent_gateway/gateway/planner.py b/agent_gateway/gateway/planner.py index 2fd0c51..aef5ab2 100644 --- a/agent_gateway/gateway/planner.py +++ b/agent_gateway/gateway/planner.py @@ -259,7 +259,7 @@ async def run_llm( try: snowflake_response = self._parse_snowflake_response(response_text) return snowflake_response - except: + except Exception: raise AgentGatewayError( message=f"Failed Cortex LLM Request. Unable to parse response. See details:{response_text}" ) diff --git a/agent_gateway/tools/snowflake_tools.py b/agent_gateway/tools/snowflake_tools.py index a637c36..0c84bd1 100644 --- a/agent_gateway/tools/snowflake_tools.py +++ b/agent_gateway/tools/snowflake_tools.py @@ -101,7 +101,7 @@ async def asearch(self, query): gateway_logger.log(logging.DEBUG, f"Cortex Search Response:{response_json}") try: return response_json["results"] - except: + except Exception: raise SnowflakeError(message=response_json["message"]) def _prepare_request(self, query): @@ -363,7 +363,7 @@ async def asearch(self, query): else: break - except: + except Exception: raise SnowflakeError(message=json_response["message"]) gateway_logger.log(logging.DEBUG, f"Cortex Analyst Response:{query_response}") diff --git a/agent_gateway/tools/utils.py b/agent_gateway/tools/utils.py index f7a7370..56abb63 100644 --- a/agent_gateway/tools/utils.py +++ b/agent_gateway/tools/utils.py @@ -40,7 +40,7 @@ class Headers(TypedDict): def _determine_runtime(): try: - from _stored_proc_restful import StoredProcRestful + from _stored_proc_restful import StoredProcRestful # noqa: F401 return True except ImportError: diff --git a/demo_app/demo_app.py b/demo_app/demo_app.py index fa35d3b..2366792 100644 --- a/demo_app/demo_app.py +++ b/demo_app/demo_app.py @@ -13,6 +13,7 @@ import asyncio import io import json +import logging import os import queue import re @@ -114,8 +115,6 @@ def create_prompt(prompt_key: str): source_list = [] -import logging - class StreamlitLogHandler(logging.Handler): def __init__(self):