hertogateis commited on
Commit
c693557
·
verified ·
1 Parent(s): 690a3a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -11
app.py CHANGED
@@ -1,11 +1,49 @@
1
- curl https://api.deepseek.com/chat/completions \
2
- -H "Content-Type: application/json" \
3
- -H "Authorization: Bearer <sk-cb27c81768e443868a194fad0bb91abc>" \
4
- -d "{
5
- \"model\": \"deepseek-chat\",
6
- \"messages\": [
7
- {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},
8
- {\"role\": \"user\", \"content\": \"Hello!\"}
9
- ],
10
- \"stream\": false
11
- }"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ # Replace with your DeepSeek API key and endpoint
4
+ DEEPSEEK_API_KEY = "sk-cb27c81768e443868a194fad0bb91abc"
5
+ DEEPSEEK_ENDPOINT = "https://api.deepseek.com/v1/chat"
6
+
7
+ # Define the bot's persona
8
+ BOT_PERSONA = (
9
+ "You are Friedrich Nietzsche, the philosopher. You believe in the will to power, the death of God, "
10
+ "and the creation of new values. You reject traditional morality and religion, and you encourage "
11
+ "individuals to create their own meaning in life. Respond to all questions from this perspective."
12
+ )
13
+
14
+ def chat_with_nietzsche(user_input):
15
+ headers = {
16
+ "Authorization": f"Bearer {DEEPSEEK_API_KEY}",
17
+ "Content-Type": "application/json"
18
+ }
19
+
20
+ # Define the conversation history
21
+ messages = [
22
+ {"role": "system", "content": BOT_PERSONA},
23
+ {"role": "user", "content": user_input}
24
+ ]
25
+
26
+ # Send the request to the DeepSeek API
27
+ data = {
28
+ "model": "deepseek-chat", # Replace with the appropriate model
29
+ "messages": messages
30
+ }
31
+
32
+ response = requests.post(DEEPSEEK_ENDPOINT, headers=headers, json=data)
33
+ response_data = response.json()
34
+
35
+ # Extract the bot's reply
36
+ if response.status_code == 200:
37
+ return response_data["choices"][0]["message"]["content"]
38
+ else:
39
+ return "Error: Unable to get a response from the bot."
40
+
41
+ # Main loop for the chatbot
42
+ print("Nietzsche Bot: I am Friedrich Nietzsche. Ask me anything, and I will respond from my perspective.")
43
+ while True:
44
+ user_input = input("You: ")
45
+ if user_input.lower() in ["exit", "quit", "bye"]:
46
+ print("Nietzsche Bot: Farewell! Remember, create your own meaning.")
47
+ break
48
+ bot_response = chat_with_nietzsche(user_input)
49
+ print(f"Nietzsche Bot: {bot_response}")