File size: 988 Bytes
7a8b419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py
from gradio_client import Client
import gradio as gr
from tools import add_numbers

def chatbot_function_calling(user_message, history):
    if "add" in user_message.lower():
        # Przykładowe parsowanie komendy
        try:
            parts = user_message.split()
            a = int(parts[1])
            b = int(parts[2])
            result = add_numbers(a, b)
            response = f"Result: {result}"
        except Exception as e:
            response = f"Error: {str(e)}"
    else:
        response = "I'm sorry, I don't understand the command."
    
    history.append((user_message, response))
    return history, history

iface = gr.ChatInterface(
    fn=chatbot_function_calling,
    chatbot=gr.Chatbot(height=400),
    textbox=gr.Textbox(show_label=False, placeholder="Send a message..."),
    title="Function Calling Chatbot",
    description="This chatbot can perform simple operations like addition."
)

iface.launch(server_name="0.0.0.0", server_port=7860)