Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python OpenAI API error: module 'openai' has no attribute 'Completion'. Did you mean: 'completions'?
- https://stackoverflow.com/questions/78046390/python-openai-api-error-module-openai-has-no-attribute-completion-did-you
- I try to make a bot for my website in Python. But I have an error.
- The Error:
- You: hello
- Traceback (most recent call last):
- File "D:\module2.py", line 20, in <module>
- response = chat_with_gpt(user_input)
- ^^^^^^^^^^^^^^^^^^^^^^^^^
- File "D:\module2.py", line 6, in chat_with_gpt
- response = openai.Completion.create(
- ^^^^^^^^^^^^^^^^^
- AttributeError: module 'openai' has no attribute 'Completion'. Did you mean: 'completions'?
- This is the Python code:
- I tried many combinations, and I also tried with text-davinci-003, but nothing worked.
- import openai
- openai.api_key = "API-KEY"
- def chat_with_gpt(prompt):
- response = openai.Completion.create(
- # engine="text-davinci-003", # Adjust the engine as necessary
- engine="gpt-3.5-turbo", # Adjust the engine as necessary
- prompt=prompt,
- max_tokens=150
- )
- return response.choices[0].text.strip()
- if __name__ == "__main__":
- while True:
- user_input = input("You: ")
- user_input = user_input.lower()
- if user_input in ["quit", "exit", "bye"]:
- break
- response = chat_with_gpt(user_input)
- print("Chatbot:", response)
- pythonpython-3.xbotsopenai-apigpt-3
- Share
- Edit
- Delete
- Flag
- edited 1 hour ago
- Rok Benko's user avatar
- Rok Benko
- 18.7k33 gold badges3030 silver badges5454 bronze badges
- asked 1 hour ago
- Anao_ O's user avatar
- Anao_ O
- 3344 bronze badges
- 1
- Why do you think that openai should have an attribute called Completion? –
- mkrieger1
- 1 hour ago
- And did you make sure that it shouldn't have been completions as suggested by the error message ? –
- Thierry Lathuille
- 1 hour ago
- I made my code, buy the code here: stackoverflow.com/questions/76040193/… –
- Anao_ O
- 1 hour ago
- I change it with: response = openai.completions.create( and I get the error: ` File "C:\Users\necul\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai_utils_utils.py", line 298, in wrapper raise TypeError(msg) TypeError: Missing required arguments; Expected either ('model' and 'prompt') or ('model', 'prompt' and 'stream') arguments to be given >>> ` –
- Anao_ O
- 1 hour ago
- @Anao_O See my answer. –
- Rok Benko
- 1 hour ago
- Add a comment
- 1 Answer
- Sorted by:
- 2
- There are a few problems in your code:
- using the wrong method name (i.e., Completion)
- using the deprecated parameter (i.e., engine)
- using the incompatible model with the Completions API
- The following code should work:
- response = openai.completions.create( # Changed
- model="gpt-3.5-turbo-instruct", # Changed
- prompt=prompt,
- max_tokens=150
- )
- Share
- Edit
- Follow
- Flag
- answered 1 hour ago
- Rok Benko's user avatar
- Rok Benko
- 18.7k33 gold badges3030 silver badges5454 bronze badges
- yes, thanks, better. But also, I get this error: ` File "C:\Users\necul\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai_base_client.py", line 877, in _request raise self._make_status_error_from_response(err.response) from None openai.RateLimitError: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}` –
- Anao_ O
- 1 hour ago
- See OpenAI API error 429: "You exceeded your current quota, please check your plan and billing details". –
- Rok Benko
- 1 hour ago
- 1
- thanks. Indeed. Were very good you solutions. –
- Anao_ O
- 1 hour ago
- Add a comment
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement