upgrade run ui
This commit is contained in:
1 parent
bb204f2c6c
commit
a10224d21e
6 files changed
+91
-18
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import re
|
||||
import json
|
||||
import inspect
|
||||
import time
|
||||
import asyncio
|
||||
|
||||
@@ -18,8 +18,10 @@ frontend_path = '../../frontend/dist'
|
||||
|
||||
def encode_json(value):
|
||||
def encode_unknown(value):
|
||||
if value is ToolSpec:
|
||||
if isinstance(value, ToolSpec):
|
||||
return value.to_openai_dict()
|
||||
elif isinstance(value, Stream):
|
||||
return {'streamId': value.id}
|
||||
else:
|
||||
return repr(value)
|
||||
return json.dumps(value, default=encode_unknown)
|
||||
|
||||
+27
-3
@@ -115,6 +115,30 @@ class ToolSpec:
|
||||
def __repr__(self):
|
||||
return f"ToolSpec(name={self.name!r}, params={[p.name for p in self.parameters]})"
|
||||
|
||||
class Tool:
|
||||
"""Base class for tools that implement their logic in a 'run' method.
|
||||
|
||||
Subclasses should override 'run' to provide the tool's functionality.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def run(self, **kwargs):
|
||||
"""Execute the tool. To be overridden by subclasses."""
|
||||
raise NotImplementedError("Tool subclasses must override the 'run' method.")
|
||||
|
||||
def to_spec(self):
|
||||
"""Generate a ToolSpec from this tool instance."""
|
||||
return ToolSpec(
|
||||
name=None, # TODO: Computed from class name, or from class attribute
|
||||
description=None, # TODO: From class doc comment
|
||||
parameters=None, # TODO: Class attribute
|
||||
func=self.run,
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"Tool(name={self.name!r}, params={[p.name for p in self.parameters]})"
|
||||
|
||||
class ToolCall:
|
||||
"""Represents a single tool invocation request emitted by the model.
|
||||
@@ -123,7 +147,7 @@ class ToolCall:
|
||||
id: Unique call identifier (used by OpenAI / llama-cpp protocol).
|
||||
tool_name: Name of the tool to invoke.
|
||||
arguments: Dict of argument name → value.
|
||||
result: String content returned by the tool.
|
||||
result: String content returned by the tool.
|
||||
is_error: Whether the result represents an error.
|
||||
"""
|
||||
|
||||
@@ -136,10 +160,10 @@ class ToolCall:
|
||||
|
||||
def __repr__(self):
|
||||
return f"ToolCall(tool={self.tool_name!r}, args={self.arguments!r})"
|
||||
|
||||
|
||||
def call_message(self):
|
||||
raise Exception("TODO: Llama message for tool call")
|
||||
|
||||
|
||||
def result_message(self):
|
||||
from inference import LlamaMessage
|
||||
return LlamaMessage("tool", self.result)
|
||||
|
||||
Reference in new issue
Block a user