【问题标题】:OpenAI API error: "AttributeError: module 'openai' has no attribute 'Embedding'"OpenAI API 错误:\"AttributeError: 模块 \'openai\' 没有属性 \'Embedding\'\"
【发布时间】:2023-02-26 17:48:14
【问题描述】:

我正在使用 openai 库运行 python 脚本。每当我在本地计算机上运行此函数时,它都会抛出以下错误

 def gpt3_embedding(content, engine='text-embedding-ada-002'):
     #delay_print('Making a vector')
     content = content.encode(encoding='ASCII',errors='ignore').decode()
     response = openai.Embedding.create(input=content,model=engine)
     vector = response['data'][0]['embedding']  # this is a normal list
     #delay_print('Vector returned')
     return vector

AttributeError: 模块 'openai' 没有属性 'Embedding

注意:我使用的是最新的 openai 包和 python 3.11.1

如果一切顺利,错误应该不会出现。

【问题讨论】:

    标签: python openai-api


    【解决方案1】:

    我测试了你的代码:

    • Python 3.11.1 和 OpenAI Python 库 0.25.0
    • Python 3.11.1 和 OpenAI Python 库 0.26.3(最新版本)

    在这两种情况下,我都运行了test.py,OpenAI API 返回了嵌入:

    [-0.02801201120018959, 0.022157097235322, -0.011196479201316833, 0.005577428266406059, 0.012320289388298988, 0.007221521344035864, 0.00034121860517188907, -0.020603187382221222, -0.011182605288922787, -0.011349095962941647, -0.007270080968737602, 0.03884775936603546, -0.016232814639806747, 7.668747275602072e-05, -0.018938282504677773, 0.040873393416404724, 0.01576109230518341, 0.032798610627651215, 0.0067047071643173695, -0.03257662057876587, -0.01071088295429945, -0.002186920726671815, 0.018535930663347244, -0.0074435085989534855, -0.0016180785605683923, -0.009108412079513073, 0.023946870118379593, -0.03690537437796593, -0.024030115455389023, -0.007582250516861677, 0.015539104118943214, -0.02534816414117813, -0.008275960572063923, -0.015261620283126831, -0.019853981211781502, 0.0053346301428973675, 0.0011671670945361257, -0.02440471760928631, 0.05225023627281189, -0.010988366790115833, -0.004113700240850449 , 0.020686432719230652, ...]

    测试.py

    import openai
    
    response = openai.Embedding.create(
      input = 'Create embedding for this text',
      model = 'text-embedding-ada-002'
    )
    
    content = response['data'][0]['embedding']
    
    print(content)
    

    【讨论】:

      猜你喜欢
      • 2023-02-26
      • 2022-11-04
      • 2023-01-03
      • 2023-02-16
      • 2019-05-10
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多