File size: 1,504 Bytes
bdfa8f2
 
 
 
 
 
 
 
4d8b82c
183253d
 
 
4d8b82c
 
 
 
 
bdfa8f2
4d8b82c
 
bdfa8f2
4d8b82c
 
 
bdfa8f2
183253d
4d8b82c
183253d
 
 
 
 
 
4d8b82c
183253d
 
 
4d8b82c
 
183253d
 
bdfa8f2
a490ba2
4d8b82c
 
 
a490ba2
c3fc29a
d56935b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr
import requests

def register_tool(tool_data):
    # Send a POST request to register the tool
    response = requests.post("https://huggingface.co/chat/tools/new", json=tool_data)
    return response.json()

def create_tool(tool_name, tool_data):
    print("fn create_tool")
    print(tool_name)
    print(dir(tool_data))
    tool_payload = {
        "displayName": tool_data.get("displayName"),
        "description": tool_data.get("description"),
        "color": tool_data.get("color"),  # Example color
        "icon": tool_data.get("icon"),
        "baseUrl": "K00B404/toolshed",
        "endpoint": "/router",
        "name": tool_data.get("name"),
        "inputs": inputs,
        "outputComponent": tool_data.get("outputComponent"),  # Adjust based on your tool's output
        "outputComponentIdx": tool_data.get("outputComponentIdx"),
        "showOutput": tool_data.get("showOutput")
    }
    print(dir(tool_payload))
    return register_tool(tool_payload)
    
def no_tool_match(tool_name: str, tool_inputs: dict):
    print("fn no match")
    print(tool)
    print(dir(tool_inputs))
    
def tool_router(tool_name: str, tool_inputs: dict):
    print("fn tool_router")
    print(tool_name)
    print(dir(tool_data))
    if tool_name == "create_tool":
        create_tool(tool_name, tool_inputs)
    else:
        no_tool_match()

demo = gr.Interface(
    fn=tool_router,
    inputs=["text", {}],
    outputs=["text", "number"],
)

demo.launch(show_api=True, share=True)