Skip to content

Commit

Permalink
persist llama tools in complete()
Browse files Browse the repository at this point in the history
  • Loading branch information
javierluraschi committed Aug 12, 2024
1 parent 3f9a1e7 commit fbf92c0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 2.6.6

- Improve error message when saving empty files in `save()`
- Persist in `complete()` tools with Llama

## 2.6.5

- Minor fix

## 2.6.4

- `deploy` supports `--access` to share private, public or unlisted
Expand Down
23 changes: 22 additions & 1 deletion python/hal9/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,33 @@ def complete_llama(completion, messages = [], tools = [], show = True):
if tool_calls:
tools = {func.__name__: func for func in tools}
for tool_call in tool_calls:
function_name = tool_call.function.name
print("tool_call.function.arguments: " + tool_call.function.arguments)
messages.append({
"role": "assistant",
"tool_calls": [{
"id": tool_call.id,
"function": {
"name": tool_call.function.name,
"arguments": tool_call.function.arguments
},
"type": "function"
}]
})

function_name = tool_call.function.name
function_to_call = tools[function_name]
function_args = json.loads(tool_call.function.arguments)
response = str(function_to_call(**function_args))

messages.append(
{
"tool_call_id": tool_call.id,
"role": "tool",
"name": function_name,
"content": response
}
)

if show:
print(response)
else:
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hal9"
version = "2.6.5"
version = "2.6.6"
description = ""
authors = ["Javier Luraschi <javier@hal9.ai>"]
readme = "README.md"
Expand Down

0 comments on commit fbf92c0

Please sign in to comment.