SimpleSallap:SimpleMCP:Update toolcall to suite calls needed
This commit is contained in:
parent
452e610095
commit
47bd2bbc90
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
from typing import Any, TypeAlias
|
from typing import Any, TypeAlias
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
import http
|
||||||
|
import http.client
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
@ -32,6 +35,8 @@ fetchurlraw_meta = {
|
||||||
# Dataclasses to help with Tool Calls
|
# Dataclasses to help with Tool Calls
|
||||||
#
|
#
|
||||||
|
|
||||||
|
TCInArgs: TypeAlias = dict[str, Any]
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TCInProperty():
|
class TCInProperty():
|
||||||
type: str
|
type: str
|
||||||
|
|
@ -63,21 +68,32 @@ class TollCallResponse():
|
||||||
name: str
|
name: str
|
||||||
content: str = ""
|
content: str = ""
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class TCOutResponse:
|
||||||
|
"""
|
||||||
|
Used to return result from tool call.
|
||||||
|
"""
|
||||||
|
callOk: bool
|
||||||
|
statusCode: int
|
||||||
|
statusMsg: str = ""
|
||||||
|
contentType: str = ""
|
||||||
|
contentData: bytes = b""
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class ToolCall():
|
class ToolCall():
|
||||||
|
name: str
|
||||||
name: str = ""
|
|
||||||
|
|
||||||
def tcf_meta(self) -> TCFunction|None:
|
def tcf_meta(self) -> TCFunction|None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def tc_handle(self, args: TCInProperties) -> tuple[bool, str]:
|
def tc_handle(self, args: TCInArgs, inHeaders: http.client.HTTPMessage) -> TCOutResponse:
|
||||||
return (False, "")
|
return TCOutResponse(False, 500)
|
||||||
|
|
||||||
def meta(self) -> ToolCallMeta:
|
def meta(self) -> ToolCallMeta:
|
||||||
tcf = self.tcf_meta()
|
tcf = self.tcf_meta()
|
||||||
return ToolCallMeta("function", tcf)
|
return ToolCallMeta("function", tcf)
|
||||||
|
|
||||||
def handler(self, callId: str, args: Any) -> TollCallResponse:
|
def handler(self, callId: str, args: Any, inHeaders: http.client.HTTPMessage) -> TollCallResponse:
|
||||||
got = self.tc_handle(args)
|
got = self.tc_handle(args, inHeaders)
|
||||||
return TollCallResponse(got[0], callId, self.name, got[1])
|
return TollCallResponse(got.callOk, callId, self.name, got.contentData.decode('utf-8'))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue