कोडिंग के लिए एक reasoning चैटबॉट बनाना
आइए सब कुछ जोड़कर कोडिंग सहायता के लिए एक reasoning चैटबॉट बनाते हैं!
आपको दो यूज़र संदेश दिए गए हैं: एक किसी ख़ास कार्य के लिए Python कोड माँगता है, और दूसरा फॉलो-अप संदेश किसी विशेष लाइब्रेरी का उपयोग करके उसे लिखने का अनुरोध करता है.
V4-Pro डिफ़ॉल्ट रूप से reasoning करता है, इसलिए आपको बस बातचीत पर लूप चलाना है और सही फ़ील्ड को history में जोड़ना है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में DeepSeek के साथ काम करना
अभ्यास निर्देश
- यूज़र प्रश्नों पर लूप चलाएँ.
- प्रत्येक यूज़र प्रश्न
qकोdeepseek-ai/DeepSeek-V4.1-Flashमॉडल पर भेजें. - असिस्टेंट का अंतिम उत्तर (केवल
.content, reasoning नहीं)messagesमें जोड़ें ताकि conversation history हल्की बनी रहे.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")
messages = []
user_msgs = ["Write some Python code to generate a list of numbers from 1-10.", "Update the code to use the NumPy library."]
# Loop over the user questions
for q in ____:
print("User: ", q)
user_dict = {"role": "user", "content": q}
messages.append(user_dict)
# Create the API request — V4-Pro reasons by default
response = client.chat.completions.create(
model="deepseek-ai/____",
messages=____,
max_tokens=500
)
# Append only the final answer to the conversation history
assistant_dict = {"role": "assistant", "content": response.choices[0].message.____}
messages.append(assistant_dict)
print("Assistant: ", response.choices[0].message.content, "\n")