Hataların ele alınması

OpenAI API ile AI Sistemleri Geliştirme

Francesca Donadoni

Curriculum Manager, DataCamp

Yapay zeka uygulamalarında hatalar

 

  • Kullanıcı deneyimini sadeleştirme
  • Engelleri kaldırma

Bir bilgisayarda 404 hatasını gideren bir adam

OpenAI API ile AI Sistemleri Geliştirme

OpenAI API kitaplığında hatalar

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 ile AI Sistemleri Geliştirme

Bağlantı hataları

 

  • Genellikle kullanıcı veya servis tarafındaki bağlantı sorunlarından kaynaklanır

 

  • Örnekler: InternalServerError, APIConnectionError, APITimeoutError

 

  • Olası çözüm:
    • Bağlantı yapılandırmanızı kontrol edin
    • Olmazsa destekle iletişime geçin
OpenAI API ile AI Sistemleri Geliştirme

Kaynak sınırı hataları

 

  • Genellikle istek sıklığına veya iletilen metin miktarına konan sınırlardan kaynaklanır

 

  • Örnekler: ConflictError, RateLimitError

 

  • Olası çözüm:
    • Limit kısıtlarını kontrol edin
    • İsteklerin limitler içinde olduğundan emin olun
OpenAI API ile AI Sistemleri Geliştirme

Kimlik doğrulama hataları

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 ile AI Sistemleri Geliştirme

Geçersiz istek hataları

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 ile AI Sistemleri Geliştirme

İstisnaların yönetimi

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 ile AI Sistemleri Geliştirme

Hadi pratik yapalım!

OpenAI API ile AI Sistemleri Geliştirme

Preparing Video For Download...