Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 20, 2024
1 parent 5328aab commit 575a30b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,31 @@
"""
CONDENSE_PROMPT = PromptTemplate.from_template(PROMPT_TEMPLATE)


class ExceptionNoToolsFile(Exception):
"""Missing tools file"""

pass


class ExceptionModelDoesTakeTools(Exception):
"""Model is not a chat model that takes tools"""

pass


class ExceptionModelNotAuthorized(Exception):
"""Authentication failed for model authorization"""

pass


class ExceptionNotChatModel(Exception):
"""Not a chat model"""

pass


class ToolsChatHandler(BaseChatHandler):
"""Processes messages prefixed with /tools. This actor will
bind a <tool_name>.py collection of tools to the LLM and
Expand Down Expand Up @@ -165,7 +174,6 @@ def conditional_continue(state: MessagesState) -> Literal["tools", "__end__"]:
return "tools"
return "__end__"


def get_tools(file_paths: list) -> list:
"""Get all tool objects from the tool files"""
if len(file_paths) > 0:
Expand Down Expand Up @@ -233,7 +241,6 @@ def get_tools(file_paths: list) -> list:
res = app.invoke({"messages": query})
return res["messages"][-1].content


async def process_message(self, message: HumanChatMessage):
args = self.parse_args(message)
if args is None:
Expand Down Expand Up @@ -264,7 +271,9 @@ async def process_message(self, message: HumanChatMessage):
except ExceptionModelDoesTakeTools:
self.reply(f"Not a chat model that takes tools.")
except ExceptionModelNotAuthorized:
self.reply(f"API failed. Model not authorized or provider package not installed.")
self.reply(
f"API failed. Model not authorized or provider package not installed."
)
except ExceptionNotChatModel:
self.reply(f"Not a chat model, cannot be used with tools.")
except Exception as e:
Expand Down

0 comments on commit 575a30b

Please sign in to comment.