Skip to content

Commit

Permalink
improve tools section
Browse files Browse the repository at this point in the history
  • Loading branch information
javierluraschi committed Aug 21, 2024
1 parent b5fce15 commit 971759b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
10 changes: 8 additions & 2 deletions website/learn/code-interpreter.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ import os
import hal9 as h9
from openai import OpenAI

messages = h9.load("messages", [{ "role": "system", "content": "Always reply with a single page HTML markdown block (which can use JavaScript, CSS, etc) that fulfills the user request" }])
messages = h9.load("messages", [{ "role": "system", "content": """
Always reply with a single page HTML markdown block (which can use JavaScript,
CSS, etc) that fulfills the user request
""" }])

messages.append({"role": "user", "content": input()})

Expand All @@ -102,7 +105,10 @@ Instead of building web applications, you can build data analytics apps that que
import hal9 as h9
from openai import OpenAI

messages = h9.load("messages", [{ "role": "system", "content": "Only reply with plain Python code. Write streamlit code to answer the user requirements." }])
messages = h9.load("messages", [{ "role": "system", "content": """
Only reply with plain Python code.
Write streamlit code to answer the user requirements.
""" }])

messages.append({"role": "user", "content": input()})

Expand Down
18 changes: 14 additions & 4 deletions website/learn/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ sidebar_position: 4

# Tools

This section presents how to add tools to your LLM application.
To build complex chatbots that can support multiple operations from evaluating code expressions, calling external services, browsing the web, etc. We can enable LLMs to choose tools to use in the form of callable functions.

Hal9 simplifies the process of setting up tools with `describe()` which describes functions to be understandable by the LLM.

The following code shows how to define a `calculate` function to help LLMs execute arithmetic operations, notice that the comment in the function is used as part of the description so it's imperative

```python
import hal9 as h9
from openai import OpenAI

def multiply(a: int, b: int) -> int:
"""Multiply two numbers."""
return a * b
def calculate(expression):
"""
Performs aritmetic operations for numerical questions.
'expression' is the aritmetic operations to evaluate,
needs conversion to proper Python syntax.
"""
return eval(expression)

messages = h9.load("messages", [])
prompt = h9.input(messages = messages)
Expand All @@ -28,3 +36,5 @@ completion = OpenAI().chat.completions.create(
h9.complete(completion, messages = messages, functions = [ multiply ])
h9.save("messages", messages, hidden = True)
```

For an advanced example of using multiple tools, consider taking a look at Hal9's main chatbot implementation in [/apps/hal9/app.py](https://github.com/hal9ai/hal9/blob/main/apps/hal9/app.py)

0 comments on commit 971759b

Please sign in to comment.