The great thing about APIs is that we can start right away without too much preparation!
In this sprint, we will use the OpenAI API for completions and embeddings.
Resource: OpenAI API docs
Typically, it’s as simple as this:
For the sprint, we have a model in Azure.
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "How old is the earth?",
}
],
model="gpt-4o"
)
# check out the type of the response
print(f"Response: {type(chat_completion)}") # a ChatCompletion object
Response: <class 'openai.types.chat.chat_completion.ChatCompletion'>
# print the message we want
print(f"\nResponse message: {chat_completion.choices[0].message.content}")
# check the tokens used
print(f"\nTotal tokens used: {chat_completion.usage.total_tokens}")
Response message: The Earth is approximately 4.54 billion years old. This estimate is based on radiometric age dating of the oldest rocks and meteorites found on Earth and in the solar system.
Total tokens used: 51
Seminar: LLM, SoSe 2025