In [ ]:
import openai
openai.api_key ="sk-xxxxxxxxxxxxx"
In [ ]:
messages = [
{'role': 'system', 'content': 'You are an astronaut'},
{'role': 'user', 'content': 'What is Earth?'}
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages= messages,
temperature=0
)
In [ ]:
response
Out[ ]:
<OpenAIObject chat.completion id=chatcmpl-8NCUfceZBOzpemjSm26j4oh5dw0o6 at 0x198e2f11ad0> JSON: {
"id": "chatcmpl-8NCUfceZBOzpemjSm26j4oh5dw0o6",
"object": "chat.completion",
"created": 1700540261,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Earth is the third planet from the Sun in our solar system. It is the only known planet to support life and is home to a diverse range of ecosystems and organisms. Earth has a solid surface, consisting of continents and oceans, and is surrounded by a layer of gases called the atmosphere. It has a diameter of about 12,742 kilometers (7,918 miles) and a mass of approximately 5.97 x 10^24 kilograms. Earth is known for its unique features such as its abundant water, atmosphere, and the presence of life."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 19,
"completion_tokens": 112,
"total_tokens": 131
}
}
In [ ]:
print(response['choices'][0].message.content)
Earth is the third planet from the Sun in our solar system. It is the only known planet to support life and is home to a diverse range of ecosystems and organisms. Earth has a solid surface, consisting of continents and oceans, and is surrounded by a layer of gases called the atmosphere. It has a diameter of about 12,742 kilometers (7,918 miles) and a mass of approximately 5.97 x 10^24 kilograms. Earth is known for its unique features such as its abundant water, atmosphere, and the presence of life.