File size: 922 Bytes
c1f2586
 
 
3c90bae
c1f2586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import cohere

API_KEY = "yGlhFfYaems7Qn25x5DYVa2eS4NiLz6Bzuh5aXyc"
co = cohere.ClientV2(api_key=API_KEY)

def chatbot(user_message, history):
    # Send only the latest user message to Cohere
    cohere_messages = [{
        "role": "user",
        "content": [{"type": "text", "text": user_message}]
    }]
    
    response = co.chat(
        messages=cohere_messages,
        temperature=0.3,
        model="command-a-03-2025",
    )
    
    assistant_reply = response.message.content[0].text
    
    # Instead of appending, overwrite history with just this turn
    return [
        {"role": "user", "content": user_message},
        {"role": "assistant", "content": assistant_reply},
    ]

with gr.Blocks() as demo:
    gr.Markdown("## 🤖 SIRMVIT CSE Chatbot ")
    gr.ChatInterface(fn=chatbot, type="messages")

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