कोडिंग के लिए reasoning चैटबॉट बनाना
आइए सब कुछ मिलाकर कोडिंग सहायता के लिए एक reasoning चैटबॉट बनाते हैं!
आपको दो user संदेश दिए गए हैं: पहला किसी खास टास्क के लिए Python कोड माँगता है, और फ़ॉलो-अप संदेश इसे किसी खास लाइब्रेरी के साथ लिखने का अनुरोध करता है.
V4-Pro डिफ़ॉल्ट रूप से reasoning करता है, इसलिए आपको बस बातचीत पर लूप चलाना है और सही फ़ील्ड को history में append करना है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में DeepSeek के साथ काम करना
अभ्यास निर्देश
- user सवालों पर लूप चलाएँ.
- हर user सवाल
qकोdeepseek-ai/DeepSeek-V4-Proमॉडल को भेजें. - असिस्टेंट का अंतिम उत्तर (.content, reasoning नहीं)
messagesमें append करें ताकि conversation history lean रहे.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
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")