You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/python-api.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,50 @@ If you have set a `OPENAI_API_KEY` environment variable you can omit the `model.
45
45
46
46
Calling `llm.get_model()` with an invalid model ID will raise a `llm.UnknownModelError` exception.
47
47
48
+
(python-api-tools)=
49
+
50
+
### Tools
51
+
52
+
{ref}`Tools <tools>` are functions that can be executed by the model as part of a chain of responses.
53
+
54
+
You can define tools in Python code - with a docstring to describe what they do - and then pass them to the `model.prompt()` method using the `tools=` keyword argument. If the model decides to request a tool call the `response.tool_calls()` method show what the model wants to execute:
55
+
56
+
```python
57
+
import llm
58
+
59
+
defupper(text: str) -> str:
60
+
"""Convert text to uppercase."""
61
+
return text.upper()
62
+
63
+
model = llm.get_model("gpt-4.1-mini")
64
+
response = model.prompt("Convert panda to upper", tools=[upper])
Copy file name to clipboardExpand all lines: docs/tools.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,4 +20,6 @@ In LLM every tool is a defined as a Python function. The function can take any n
20
20
21
21
Tool functions should include a docstring that describes what the function does. This docstring will become the description that is passed to the model.
22
22
23
-
The Python API can accept functions directly. The command-line interface has two ways for tools to be defined: via plugins that implement the {ref}`register_tools() plugin hook <plugin-hooks-register-tools>`, or directly on the command-line using the `--functions` argument to specify a block of Python code defining one or more functions - or a path to a Python file containing the same.
23
+
The Python API can accept functions directly. The command-line interface has two ways for tools to be defined: via plugins that implement the {ref}`register_tools() plugin hook <plugin-hooks-register-tools>`, or directly on the command-line using the `--functions` argument to specify a block of Python code defining one or more functions - or a path to a Python file containing the same.
24
+
25
+
You can use tools {ref}`with the LLM command-line tool <usage-tools>` or {ref}`with the Python API <python-api-tools>`.
0 commit comments