Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,18 @@
|
|
| 1 |
import requests
|
| 2 |
import json
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
API_KEY = "DEEPSEEK_API_KEY"
|
| 6 |
-
#API_URL = "https://api.deepseek.com/v1/chat/completions" # Example endpoint, check documentation
|
| 7 |
|
| 8 |
-
|
| 9 |
-
prompt = "Halo, bisakah kamu membantu saya membuat rencana perjalanan ke Bali?"
|
| 10 |
|
| 11 |
-
|
| 12 |
-
payload = {
|
| 13 |
-
"model": "deepseek-v3",
|
| 14 |
-
"messages": [
|
| 15 |
-
{"role": "user", "content": "Halo, apa kabar?"}
|
| 16 |
-
],
|
| 17 |
-
"max_tokens": 150,
|
| 18 |
-
"temperature": 0.7,
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
# Set headers
|
| 22 |
-
headers = {
|
| 23 |
-
"Authorization": f"Bearer {API_KEY}",
|
| 24 |
-
"Content-Type": "application/json",
|
| 25 |
-
}
|
| 26 |
-
#response = requests.get(API_URL, headers=headers)
|
| 27 |
-
#print(response.status_code, response.json())
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
# Make the API request
|
| 31 |
-
#response = requests.post(API_URL, headers=headers, data=json.dumps(payload))
|
| 32 |
-
|
| 33 |
-
# Check the response
|
| 34 |
-
if response.status_code == 200:
|
| 35 |
-
result = response.json()
|
| 36 |
-
generated_text = result['choices'][0]['message']['content']
|
| 37 |
-
print("Generated Text:", generated_text)
|
| 38 |
-
else:
|
| 39 |
-
print("Error:", response.status_code, response.text)
|
|
|
|
| 1 |
import requests
|
| 2 |
import json
|
| 3 |
|
| 4 |
+
# Please install OpenAI SDK first: `pip3 install openai`
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
from openai import OpenAI
|
|
|
|
| 7 |
|
| 8 |
+
client = OpenAI(api_key="<DEEPSEEK_API_KEY>", base_url="https://api.deepseek.com")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
response = client.chat.completions.create(
|
| 11 |
+
model="deepseek-chat",
|
| 12 |
+
messages=[
|
| 13 |
+
{"role": "system", "content": "You are a helpful assistant"},
|
| 14 |
+
{"role": "user", "content": "Hello"},
|
| 15 |
+
],
|
| 16 |
+
stream=False
|
| 17 |
+
)
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|