#Help with first API+Python project
1 messages · Page 1 of 1 (latest)
Ok I'm confused
There's a curl request, but I cant find a Python request
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Say this is a test!"}],
"temperature": 0.7
}'```
$OPENAI_API_KEY
You need to specify openai api key
basically, you need to install python in your development env and install openai package.
and then start integrating that.
did you install openai in your dev env?
pip install openai
I am using this command
pipenv but yeah
it is already installed
Okay so I am having further problems
try:
openai.api_key = api_key
response = openai.Completion.create(
engine=model,
prompt=prompt,
max_tokens=max_tokens,
temperature=temperature,
n=1,
stop=None
)
# Extract and return the text from the response, if available
text = response.choices[0].text.strip()
return text
except Exception as e:
return f"An error occurred: {e}"
def main():
# Define your prompt
prompt = "Escribe un correo felicitando ascenso de puesto"
# Get the response from OpenAI
answer = get_openai_response(prompt)
# Print the prompt and its answer
print(f"Prompt: {prompt}")
print(f"Answer: {answer}")```
I have this which the playground of the API gave me
however when I tried it out
it gives me this error:
You tried to access openai.Completion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python 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: https://github.com/openai/openai-python/discussions/742```
and this is after I had installed with pipenv install openai
Any help anybody?
or do I need to work w/o env then?
I tried doing a clean pipenv, and do a clean pipenv install openai but I get the following error