Skip to content

Commit

Permalink
migrate tools name
Browse files Browse the repository at this point in the history
  • Loading branch information
rgbkrk committed Mar 4, 2024
1 parent 5df8612 commit 98f4cf1
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 70 deletions.
2 changes: 1 addition & 1 deletion chatlab/builtins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Builtins for ChatLab."""
"""Simple tools for any LLM to use."""

from deprecation import deprecated

Expand Down
4 changes: 2 additions & 2 deletions chatlab/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def __init__(

if function_registry is None:
if allow_hallucinated_python and python_hallucination_function is None:
from .builtins import run_cell
from .tools import run_python

python_hallucination_function = run_cell
python_hallucination_function = run_python

self.function_registry = FunctionRegistry(python_hallucination_function=python_hallucination_function)
else:
Expand Down
358 changes: 311 additions & 47 deletions notebooks/color-picker.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/cooking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "chatlab-0EWIBOuo-py3.11",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down
7 changes: 3 additions & 4 deletions notebooks/function-registry.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "chatlab-3kMKfU-i-py3.11",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1136,9 +1136,8 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.1"
},
"orig_nbformat": 4
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
12 changes: 6 additions & 6 deletions tests/test_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

from chatlab import FunctionRegistry
from chatlab.builtins import os_functions
from chatlab.builtins.files import (
from chatlab.tools.files import (
get_file_size,
is_directory,
is_file,
list_files,
read_file,
write_file,
)
from chatlab.builtins.shell import run_shell_command
from chatlab.tools.shell import run_shell_command


def test_chat_function_adherence():
Expand Down Expand Up @@ -39,29 +39,29 @@ async def test_run_shell_command():

@pytest.mark.asyncio
async def test_list_files():
directory = "chatlab/builtins"
directory = "chatlab/tools"
files = await list_files(directory)
assert isinstance(files, list)
assert len(files) > 0


@pytest.mark.asyncio
async def test_get_file_size():
file_path = "chatlab/builtins/files.py"
file_path = "chatlab/tools/files.py"
size = await get_file_size(file_path)
assert isinstance(size, int)
assert size > 0


@pytest.mark.asyncio
async def test_is_file():
file_path = "chatlab/builtins/files.py"
file_path = "chatlab/tools/files.py"
assert await is_file(file_path)


@pytest.mark.asyncio
async def test_is_directory():
directory = "chatlab/builtins"
directory = "chatlab/tools"
assert await is_directory(directory)


Expand Down
2 changes: 1 addition & 1 deletion website/docs/examples/color-picker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The IPython-provided `display()` uses your object's `_repr_html_()` to show HTML

```python cell count=1
from chatlab import Chat, models, system
from chatlab.builtins.colors import show_colors
from chatlab.tools.colors import show_colors

chat = Chat(
system("Format responses in markdown,. You are a skilled designer."),
Expand Down
16 changes: 8 additions & 8 deletions website/docs/interpreter.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ There is a builtin code interpreter that lets the assistant run code. It's not e

```python cell count=1
from chatlab import Chat
from chatlab.builtins import run_cell
from chatlab.tools import run_python

chat = Chat()
chat.register(run_cell)
chat.register(run_python)
await chat("Please calculate sin(793.1)")
```

<OutputBlock count={1}>
<ChatFunctionCall
open
name="run_cell"
name="run_python"
input={'{\n "code": "import math\\nmath.sin(793.1)"\n}'}
output="0.9884482539459452"
/>
Expand All @@ -37,7 +37,7 @@ You can let ChatGPT take on a data persona with a `system` message and then have

```python
from chatlab import Chat, system
from chatlab.builtins import run_cell
from chatlab.tools import run_python
import pandas as pd

# The Chicago Public Library location dataset
Expand All @@ -49,22 +49,22 @@ chat = Chat(
"collaborating with a data engineer."
),
)
chat.register(run_cell)
chat.register(run_python)
await chat("Please tell me about what's in `df`")
```

## The hidden `python` hallucination

Sometimes GPT models will hallucinate a `python` tool that accepts a single string rather than the proper JSON object that `run_cell` requests. You can include it in your `Chat` to handle these cases.
Sometimes GPT models will hallucinate a `python` tool that accepts a single string rather than the proper JSON object that `run_python` requests. You can include it in your `Chat` to handle these cases.

```python cell count=1
from chatlab import Chat
from chatlab.builtins import run_cell
from chatlab.tools import run_python

chat = Chat(
allow_hallucinated_python=True
)
chat.register(run_cell)
chat.register(run_python)
await chat("Please calculate sin(793.1)")
```

Expand Down

0 comments on commit 98f4cf1

Please sign in to comment.