-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support toolcall from agent directly
- Loading branch information
1 parent
b50be2f
commit fc8cb53
Showing
35 changed files
with
555 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
import logging | ||
|
||
import spear.client as client | ||
import spear.hostcalls.transform as tf | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def chat_completion( | ||
agent: client.HostAgent, | ||
prompt: str, | ||
toolset_id: int = -1, | ||
role: str = "user", | ||
model: str = "gpt-4o", | ||
) -> list[tf.ChatChoice]: | ||
""" | ||
get user input | ||
""" | ||
resp = agent.exec_request( | ||
"transform", | ||
tf.TransformRequest( | ||
input_types=[tf.TransformType.TEXT], | ||
output_types=[tf.TransformType.TEXT], | ||
operations=[tf.TransformOperation.LLM, tf.TransformOperation.TOOLS], | ||
params={ | ||
"model": model, | ||
"messages": [ | ||
tf.ChatMessageV2( | ||
metadata=tf.ChatMessageV2Metadata(role=role), | ||
content=prompt, | ||
) | ||
], | ||
"toolset_id": toolset_id, | ||
}, | ||
), | ||
) | ||
|
||
if isinstance(resp, client.JsonRpcOkResp): | ||
resp = tf.TransformResponse.schema().load(resp.result) | ||
resp = tf.ChatResponseV2.schema().load(resp.results[0].data) | ||
return resp.messages | ||
else: | ||
raise ValueError(f"Error: {resp.message}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
import logging | ||
|
||
import spear.client as client | ||
import spear.hostcalls.tools as tools | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def new_toolset( | ||
agent: client.HostAgent, name: str, description: str, workload_name: str = None | ||
) -> str: | ||
""" | ||
create a new toolset | ||
""" | ||
req = { | ||
"name": name, | ||
"description": description, | ||
} | ||
if workload_name: | ||
req["workload_name"] = workload_name | ||
resp = agent.exec_request( | ||
"toolset.new", | ||
req, | ||
) | ||
|
||
if isinstance(resp, client.JsonRpcOkResp): | ||
logger.debug("Toolset created with id: %s", resp.result) | ||
resp = tools.NewToolsetResponse.schema().load(resp.result) | ||
return resp.toolset_id | ||
else: | ||
raise ValueError(f"Error creating toolset: {resp.message}") |
Oops, something went wrong.