In following this tutorial (https://github.com/openai/openai-cookbook/blob/main/examples/Question_answering_using_embeddings.ipynb) to try to embed my dataset in the gpt embeddings i get the following error while running this def :
def get_embedding(text: str, model: str=EMBEDDING_MODEL) -> list[float]:
result = openai.Embedding.create(
model=model,
input=text
)
return result["data"][0]["embedding"]
def compute_doc_embeddings(df: pd.DataFrame) -> dict[tuple[str, str], list[float]]:
"""
Create an embedding for each row in the dataframe using the OpenAI Embeddings API.
Return a dictionary that maps between each embedding vector and the index of the row that it corresponds to.
"""
return {
idx: get_embedding(r.content) for idx, r in df.iterrows()
}
i get the following error
TypeError Traceback (most recent call last)
Cell In[24], line 1
----> 1 def get_embedding(text: str, mode: str=EMBEDDING_MODEL) -> list[float]:
2 result = openai.Embedding.create(
3 model=model,
4 input=text
5 )
6 return result["data"][0]["embedding"]
TypeError: 'type' object is not subscriptable
I tried to upgrade python as suggested in other stackoverflow post but it doesnt seem to fix this issue. In another post I saw calling the list "List" but it doesnt fix the issue