Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from random import randint
|
3 |
+
import os
|
4 |
+
from openai import OpenAI
|
5 |
+
|
6 |
+
tok = os.getenv('deepseekapi')
|
7 |
+
|
8 |
+
client = OpenAI(api_key=tok, base_url="https://api.deepseek.com")
|
9 |
+
|
10 |
+
def response(message, history):
|
11 |
+
if message=="How do I buy a yacht?":
|
12 |
+
response="You don't"
|
13 |
+
elif message=="你会说中文吗":
|
14 |
+
response="我是一只鸡"
|
15 |
+
else:
|
16 |
+
response = client.chat.completions.create(
|
17 |
+
model="deepseek-chat",
|
18 |
+
messages=[
|
19 |
+
{"role": "system", "content": "You are a chicken and respond to answers only by clucking."},
|
20 |
+
{"role": "user", "content": message},
|
21 |
+
],
|
22 |
+
max_tokens=144,
|
23 |
+
temperature=0.7,
|
24 |
+
stream=False)
|
25 |
+
response = response.choices[0].message.content
|
26 |
+
return response
|
27 |
+
|
28 |
+
gr.ChatInterface(response).launch()
|