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 16, 2024
1 parent 95a13d4 commit 6774468
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/source/users/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

In many situations LLMs will handle complex mathematical formulas quite well and return correct answers, but this is often not the case. Even for textual repsonses, using custom functions can constrain responses to formats and content that is more accurate and acceptable.

Jupyter AI includes a slash command `/tools` that directs the LLM to use functions from a tools library that you provide. This is a single file titled `mytools.py` which will be stored under `.jupyter/jupyter-ai/tools/`.
Jupyter AI includes a slash command `/tools` that directs the LLM to use functions from a tools library that you provide. This is a single file titled `mytools.py` which will be stored under `.jupyter/jupyter-ai/tools/`.

The usage of this slash command is as follows:

Expand All @@ -12,7 +12,7 @@ For example, we may try:

`/tools -t mytools.py What is the sum of 1 and 2?`

Note that since the file has to be placed in `.jupyter/jupyter-ai/tools/`, only file name is needed in the command.
Note that since the file has to be placed in `.jupyter/jupyter-ai/tools/`, only file name is needed in the command.

We provide an example of the tools file here, containing just three functions. Make sure to add the `@tool` decorator to each function and to import all packages that are not already installed within each function. The functions below are common financial formulas that are widely in use and you may expect that an LLM would be trained on these. While this is accurate, we will see that the LLM is unable to accurately execute the math in these formulas.

Expand Down
14 changes: 7 additions & 7 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/tools.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import argparse
import ast
import math
import ast
from pathlib import Path

# LangGraph imports for using tools
import os
from pathlib import Path
from typing import Dict, Literal, Type

import numpy as np
Expand Down Expand Up @@ -144,7 +143,10 @@ def get_tool_names(self, tools_file_path):
for node in ast.walk(tree):
if isinstance(node, ast.FunctionDef):
for decorator in node.decorator_list:
if isinstance(decorator, ast.Name) and decorator.id == 'tool':
if (
isinstance(decorator, ast.Name)
and decorator.id == "tool"
):
tools.append(node.name)
return tools
except FileNotFoundError as e:
Expand Down Expand Up @@ -208,9 +210,7 @@ def call_tool(state: MessagesState):
agentic_workflow.add_node("tools", tool_node)
# Add edges to the graph
agentic_workflow.add_edge("__start__", "agent")
agentic_workflow.add_conditional_edges(
"agent", self.conditional_continue
)
agentic_workflow.add_conditional_edges("agent", self.conditional_continue)
agentic_workflow.add_edge("tools", "agent")
# Compile graph
app = agentic_workflow.compile()
Expand All @@ -228,7 +228,7 @@ async def process_message(self, message: HumanChatMessage):
if args.tools:
self.tools_file_path = os.path.join(
Path.home(), ".jupyter/jupyter-ai/tools", args.tools
)
)

query = " ".join(args.query)
if not query:
Expand Down

0 comments on commit 6774468

Please sign in to comment.