0

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

Gabry
  • 33
  • 1
  • 5
  • "I tried to upgrade python as suggested in other stackoverflow post but it doesnt seem to fix this issue." - then you either did it wrong, or the code is still being run using the old version of Python. Please keep in mind that installing a new version of Python on your computer **does not replace** any existing version, and that you should **never attempt to remove or modify any Python that came pre-installed on your computer, because your operating system may depend on it**. – Karl Knechtel Mar 21 '23 at 12:01
  • "In another post I saw calling the list "List" but it doesnt fix the issue" You **also** have to use `from typing import List` in your imports (or do something equivalent, e.g. `import typing` and then put `typing.List[float]` for the type signature), and you still need a Python version that is at least up to date enough to support that. Whatever answer you saw should have already explained that. – Karl Knechtel Mar 21 '23 at 12:01
  • Check the spelling of `model` in the parameter, in the error message it says the name is `mode`. – tim the fiend Mar 21 '23 at 12:05

0 Answers0