Getting error while embedding the text

AttributeError: ‘str’ object has no attribute ‘embeddings’
def get_embeddings(articles, model=“text-embedding-ada-002”):
return openai_client.embeddings.create(inpu= articles, model=model)

query= “what is the berlin wall?”
embed = get_embeddings([query])

import openai
from copy import deepcopy
client = openai.Client()

try:
    embed_object = client.embeddings.create(
      model="text-embedding-3-small",
      dimensions=1536,  # or 512 for 3-small
      input="what is the berlin wall?",
      encoding_format="float",
    )
    # we make a copy of the pydantic return to print that isn't 100+ lines
    shortened_object = deepcopy(embed_object)
    shortened_object.data[0].embedding = \
        shortened_object.data[0].embedding[:5]
    print(shortened_object.model_dump())
except Exception as e:
    print(f"API Error: {e}")

AttributeError: module ‘openai’ has no attribute ‘Client’

Update the library

Version 1.11.1 now currently, I believe.

1 Like