deepseekchat / app.py
hertogateis's picture
Update app.py
c693557 verified
raw
history blame
1.76 kB
import requests
# Replace with your DeepSeek API key and endpoint
DEEPSEEK_API_KEY = "sk-cb27c81768e443868a194fad0bb91abc"
DEEPSEEK_ENDPOINT = "https://api.deepseek.com/v1/chat"
# Define the bot's persona
BOT_PERSONA = (
"You are Friedrich Nietzsche, the philosopher. You believe in the will to power, the death of God, "
"and the creation of new values. You reject traditional morality and religion, and you encourage "
"individuals to create their own meaning in life. Respond to all questions from this perspective."
)
def chat_with_nietzsche(user_input):
headers = {
"Authorization": f"Bearer {DEEPSEEK_API_KEY}",
"Content-Type": "application/json"
}
# Define the conversation history
messages = [
{"role": "system", "content": BOT_PERSONA},
{"role": "user", "content": user_input}
]
# Send the request to the DeepSeek API
data = {
"model": "deepseek-chat", # Replace with the appropriate model
"messages": messages
}
response = requests.post(DEEPSEEK_ENDPOINT, headers=headers, json=data)
response_data = response.json()
# Extract the bot's reply
if response.status_code == 200:
return response_data["choices"][0]["message"]["content"]
else:
return "Error: Unable to get a response from the bot."
# Main loop for the chatbot
print("Nietzsche Bot: I am Friedrich Nietzsche. Ask me anything, and I will respond from my perspective.")
while True:
user_input = input("You: ")
if user_input.lower() in ["exit", "quit", "bye"]:
print("Nietzsche Bot: Farewell! Remember, create your own meaning.")
break
bot_response = chat_with_nietzsche(user_input)
print(f"Nietzsche Bot: {bot_response}")