In [ ]:
import openai
In [ ]:
openai.api_key ="sk-xxxxxxxxxxxxxxxx"
In [ ]:
prompt = 'What is Earth.'
#Davinci only supports completions, not chatcompletion
response = openai.Completion.create(
model='text-davinci-003',
prompt=prompt,
temperature=0.8,
max_tokens=1000
)
In [ ]:
response
Out[ ]:
<OpenAIObject text_completion id=cmpl-8NCa3gDCl6m5yZ0jXJt8bpDhL1WAu at 0x1c1ee40d120> JSON: { "warning": "This model version is deprecated. Migrate before January 4, 2024 to avoid disruption of service. Learn more https://platform.openai.com/docs/deprecations", "id": "cmpl-8NCa3gDCl6m5yZ0jXJt8bpDhL1WAu", "object": "text_completion", "created": 1700540595, "model": "text-davinci-003", "choices": [ { "text": "\n\nEarth is the third planet from the Sun and the only astronomical object known to harbor life. It is the fifth-largest planet in the Solar System and is the largest of the Solar System's four terrestrial planets. As the world's only known inhabited planet, Earth has served as the stage for many of humanity's most significant historical and cultural developments over the last several thousand years.", "index": 0, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 4, "completion_tokens": 77, "total_tokens": 81 } }
In [ ]:
print(response["choices"][0]["text"])
Earth is the third planet from the Sun and the only astronomical object known to harbor life. It is the fifth-largest planet in the Solar System and is the largest of the Solar System's four terrestrial planets. As the world's only known inhabited planet, Earth has served as the stage for many of humanity's most significant historical and cultural developments over the last several thousand years.