Skip to content

Instantly share code, notes, and snippets.

@jaglinux
Last active January 26, 2025 15:23
Show Gist options
  • Save jaglinux/ec74fdf00830bbe5f82045a8f18dc83b to your computer and use it in GitHub Desktop.
Save jaglinux/ec74fdf00830bbe5f82045a8f18dc83b to your computer and use it in GitHub Desktop.
Deepseek api
# 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)
@jaglinux
Copy link
Author

How to run this code / README

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment