Last active
January 26, 2025 15:23
-
-
Save jaglinux/ec74fdf00830bbe5f82045a8f18dc83b to your computer and use it in GitHub Desktop.
Deepseek api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download this code and on your terminal, type the below commands. This is only required first time. | |
# pip3 install openai | |
# export DeepSeek_API_Key=<your DeepSeek API Key> | |
# Then run the below command to ask questions to deepseek model | |
# python3 deepseek.py | |
import os, sys | |
from openai import OpenAI | |
ds_key = os.environ.get('DeepSeek_API_Key', None) | |
if ds_key is None: | |
print("DeepSeek_API_Key not found. On your terminal set the key") | |
print("export DeepSeek_API_Key=<your DeepSeek API Key>") | |
print("Exiting...") | |
sys.exit(1) | |
question = input("Enter your question: ") | |
client = OpenAI(api_key=ds_key, base_url="https://api.deepseek.com") | |
response = client.chat.completions.create( | |
model="deepseek-chat", | |
messages=[ | |
{"role": "system", "content": "You are a helpful assistant"}, | |
{"role": "user", "content": question}, | |
], | |
stream=False | |
) | |
print(response.choices[0].message.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to run this code / README
Download this code and on your terminal, type the below commands. This is only required first time.
Then run the below command to ask questions to deepseek model
python3 deepseek.py