This topic was automatically generated from Slack. You can find the original thread here.
Hey, looking for some assistance with some Python code that will talk to ChatGPT. I’m getting this error even though I believe I’ve changed the Python code to call into the API correctly. APIRemovedInV1
You tried to access openai.Completion, but this is no longer supported in openai>=1.0.0 - see the README at GitHub - openai/openai-python: The official Python library for the OpenAI API for the API. You can run openai migrate to automatically upgrade your codebase to use the 1.0.0 interface. Alternatively, you can pin your installation to the old version, e.g. pip install openai==0.28 A detailed migration guide is available here: v1.0.0 Migration Guide · openai/openai-python · Discussion #742 · GitHub
Hi ! We don’t use a specific version for the openai package in Python steps. Pipedream downloads the latest version when you deploy your workflow. If you need to use an older version, try pinning the package version.
Let me know if that helps
_# Use the updated method from the OpenAI 1.0.0 interface_
response = openai.Completion.create(
model="text-davinci-004", _# Replace with your preferred model_
prompt=user_request,
temperature=0.7,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
_# Parsing the response based on the new API structure_
**if** response.choices:
response_to_user = response.choices[0].text.strip()
**print**(f'Answer: {response_to_user}')
**return** {'response_to_user': response_to_user}
**else**:
**return** {'response_to_user': 'No response generated'}
I would recommend using the latest version since OpenAI recommends migrating.
But if you want to use an older version, add this to the top of your code: # pipedream add-package openai==0.28
i did… (hence why I’ve reverted to Python). I was sending a message to OpenAI fine and getting a response but then it was getting stuck looping and chewed up the credits so had to abandon it. I found a web article that was actually trying to do the same thing but in Python.
Let me revisit this again using your built-in actions because I wasn’t using the “complete” action - that may have been my issue. Because call is async, using “complete” I think behaves differently…
Thanks for sharing all this! I’m trying to understand if there is any improvements we need to make on our side — what’s your core use-case? Are you using the Create Completion action or the Chat (recommend this one) action?