त्रुटियों का प्रबंधन

OpenAI API के साथ AI सिस्टम बनाना

Francesca Donadoni

Curriculum Manager, DataCamp

AI ऐप्लिकेशन में त्रुटियाँ

 

  • यूज़र अनुभव सरल बनाना
  • बाधाएँ हटाना

कंप्यूटर पर 404 त्रुटि ट्रबलशूट करता व्यक्ति

OpenAI API के साथ AI सिस्टम बनाना

OpenAI API लाइब्रेरी में त्रुटियाँ

response = client.chat.completions.create(
 model="text-davinci-001",
 messages=[
   {
    "role": "user", 
    "content": "List two data science professions with related skills in json format."
   }
 ],
 response_format={"type": "json_object"}
)
NotFoundError: Error code: 404 - {'error': {'message': 'The model `text-davinci-001` 
has been deprecated, learn more here: https://platform.openai.com/docs/deprecations'}}
OpenAI API के साथ AI सिस्टम बनाना

कनेक्शन त्रुटियाँ

 

  • आमतौर पर यूज़र या सर्विस साइड पर कनेक्शन समस्याओं के कारण

 

  • उदाहरण: InternalServerError, APIConnectionError, APITimeoutError

 

  • संभावित समाधान:
    • अपनी कनेक्शन कॉन्फ़िगरेशन जाँचें
    • न सुलझे तो सपोर्ट से संपर्क करें
OpenAI API के साथ AI सिस्टम बनाना

रिसोर्स लिमिट त्रुटियाँ

 

  • आमतौर पर रिक्वेस्ट की आवृत्ति या पास किए गए टेक्स्ट की मात्रा की सीमाओं के कारण

 

  • उदाहरण: ConflictError, RateLimitError

 

  • संभावित समाधान:
    • लिमिट प्रतिबंध जाँचें
    • सुनिश्चित करें कि रिक्वेस्ट लिमिट में हों
OpenAI API के साथ AI सिस्टम बनाना

प्रमाणीकरण त्रुटियाँ

client = OpenAI(api_key="This is an Invalid Key")

response = client.chat.completions.create( model="gpt-4o-mini", messages=[ { "role": "user", "content": "List two data science professions with related skills in json format." } ], response_format={"type": "json_object"} )
AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: 
ThisIsNo*AKey. You can find your API key at https://platform.openai.com/account/api-keys.'}}
OpenAI API के साथ AI सिस्टम बनाना

खराब अनुरोध (Bad request) त्रुटियाँ

response = client.chat.completions.create(
 model="gpt-4o-mini",
 messages=[
   {"role": "This is not a Valid Role", "content": "List two data science 
   professions with related skills in json format."}
 ],
 response_format={"type": "json_object"}
)
BadRequestError: Error code: 400 - {'error': {'message': "'NotARole' is not one of 
['system', 'assistant', 'user', 'function'] - 'messages.0.role'", 
'type': 'invalid_request_error', 'param': None, 'code': None}}
OpenAI API के साथ AI सिस्टम बनाना

एक्सेप्शन हैंडलिंग

try: 
    response = client.chat.completions.create(
     model="gpt-4o-mini",
     messages=[{"role": "user", 
      "content": "List five data science professions."}])

except openai.AuthenticationError as e: print(f"OpenAI API failed to authenticate: {e}") pass except openai.RateLimitError as e: print(f"OpenAI API request exceeded rate limit: {e}") pass
except Exception as e: print(f"Unable to generate a response. Exception: {e}") pass
OpenAI API के साथ AI सिस्टम बनाना

अभ्यास करते हैं!

OpenAI API के साथ AI सिस्टम बनाना

Preparing Video For Download...