File size: 1,011 Bytes
688882b
fc2df1e
688882b
70ecc61
688882b
 
 
 
b55a082
70ecc61
 
e977e9d
688882b
fc2df1e
 
 
 
 
 
 
 
688882b
fc2df1e
688882b
 
 
fc2df1e
688882b
fc2df1e
 
 
 
 
 
 
 
 
688882b
fc2df1e
 
 
 
 
 
 
 
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
import os
import gradio as gr
from huggingface_hub import login
from smolagents import DuckDuckGoSearchTool, ToolCallingAgent, InferenceClientModel

login(os.environ.get('HF_TOKEN'))

def create_agent():
    tools = [DuckDuckGoSearchTool()]
    model = InferenceClientModel("Qwen/Qwen2.5-72B-Instruct")

    return ToolCallingAgent(tools=tools,  model=model, add_base_tools=True)



def respond(
    message,
    history: list[dict[str, str]],
    system_message,
    max_tokens,
    temperature,
    top_p
):
    agent = create_agent()
    full_prompt = f"{system_message}\n\nChat history:\n{history}\n\nUser: {message}"
    response = agent.run(full_prompt, stream=False)

    yield response



"""
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
"""
chatbot = gr.ChatInterface(
    respond,
    type="messages",
    additional_inputs=[],
)

with gr.Blocks() as demo:
    chatbot.render()


if __name__ == "__main__":
    demo.launch()