openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions) when calling the chat completions endpoints multiple times

Open adeolaemmanuelmorren opened this issue 1 year ago • 3 comments

Describe the bug

when calling

openai.ChatCompletion.create( model="gpt-3.5-turbo-0301", messages=[ { "role": "user", "content" : prompt } ], temperature=0.7, max_tokens=MAX_OUTPUT_BASE, n=1)

multiple times in a loop I noticed that the first few attempts run perfectly fine I believe the first 3-5, however after that it fails with the error code openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions)

which is very odd as the prior ones are running smoothly within the same exact function call...

I can verify that I'm running on openai==0.27.0 with python 3.9

To Reproduce

  1. create an array of texts 2 run the following for text in texts:

     MAX_TOKENS = 3500
     # used for testing to see how the token limit progrsses over time
    
    
     response = openai.ChatCompletion.create(
       model="gpt-3.5-turbo-0301",
       messages=[
         {
             "role": "user",
             "content" : "text"
         }
       ],            
       temperature=0.7, 
       max_tokens=MAX_TOKENS, n=1)
    

Code snippets

No response

OS

macos

Python version

python 3.9

Library version

openai-python v0.27.0

adeolaemmanuelmorren avatar Mar 06 '23 18:03 adeolaemmanuelmorren

A substitude but temporal way is to create a new chat class like the "Answer" class

from openai.openai_object import OpenAIObject

class NewChat(OpenAIObject):
    api_prefix = "v1"

    @classmethod
    def get_url(self, base):
        return "/%s/%s" % (self.api_prefix, base)

    @classmethod
    def create(cls, **params):
        instance = cls()
        return instance.request("post", cls.get_url("chat/completions"), params)

this works for me so far

aforwardz avatar Mar 07 '23 03:03 aforwardz

sry, just update openai to v0.27.0

aforwardz avatar Mar 07 '23 07:03 aforwardz

sry, just update openai to v0.27.0

@aforwardz hmmm. I have updated to 0.27.0 but I will give your code a shot, thank you! Although I do think that should not be necessary for us to have to do

Adeolamorren avatar Mar 07 '23 12:03 Adeolamorren

This looks like a temporary issue while our code was updating, sorry. If you see this again, please reopen the ticket.

athyuttamre avatar Mar 17 '23 20:03 athyuttamre