File size: 1,785 Bytes
61e5bf4
b0d08f5
cc86e76
61e5bf4
 
 
 
85ab20e
3514214
 
85ab20e
3514214
61e5bf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
import streamlit as st
import requests

# Set up Streamlit page configuration
st.set_page_config(page_title="DeepSeek Chatbot", page_icon="🤖", layout="wide")

# API setup
url = "https://api.hyperbolic.xyz/v1/chat/completions"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtaXRyYWxlc3RhcmlwZXJzYWRhQGdtYWlsLmNvbSIsImlhdCI6MTczNjUwMzQxMX0.yuIoZsH1jouAlixx_h_eQ-bltZ1sg4alrJHMHr1axvA"
}

# Chat history container
if 'messages' not in st.session_state:
    st.session_state.messages = []

# Function to send message and get response
def get_response(user_input):
    data = {
        "messages": [{"role": "user", "content": user_input}],
        "model": "deepseek-ai/DeepSeek-V3",
        "max_tokens": 512,
        "temperature": 0.1,
        "top_p": 0.9
    }
    
    response = requests.post(url, headers=headers, json=data)
    return response.json()

# Streamlit chat UI
st.title("DeepSeek AI Chatbot")

# Display the chat history
for message in st.session_state.messages:
    if message["role"] == "user":
        st.chat_message("user").markdown(message["content"])
    else:
        st.chat_message("assistant").markdown(message["content"])

# Accept user input
user_input = st.text_input("You: ", "")

# Handle user input and update the chat
if user_input:
    st.session_state.messages.append({"role": "user", "content": user_input})
    response = get_response(user_input)
    
    # Assuming the response is in the 'choices' field of the API response
    bot_response = response.get('choices', [{}])[0].get('message', {}).get('content', 'Sorry, I did not understand that.')
    st.session_state.messages.append({"role": "assistant", "content": bot_response})
    st.experimental_rerun()