More repeatable embeddings
As you continue to work with embeddings, you'll find yourself making repeated calls to OpenAI's embedding model. To make these calls in a more repeatable and modular way, it would be better to define a custom function called create_embeddings() that would output embeddings for any number of text inputs. In this exercise, you'll do just that!
Questo esercizio fa parte del corso
Introduction to Embeddings with the OpenAI API
Istruzioni dell'esercizio
- Define a
create_embeddings()function that sends an input,texts, to the embedding model, and returns a list containing the embeddings for each input text. - Embed
short_descriptionusingcreate_embeddings(), and extract and print the embeddings in a single list. - Embed
list_of_descriptionsusingcreate_embeddings()and print.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Define a create_embeddings function
def create_embeddings(texts):
response = client.____(
model="text-embedding-3-small",
input=____
)
response_dict = response.model_dump()
return [data['____'] for data in ____['data']]
# Embed short_description and print
print(____)
# Embed list_of_descriptions and print
print(____)