我用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
属性错误:模块“openai”没有属性“Embedding
注意:我使用的是最新的openai包和python3.11.1
如果一切顺利,错误根本不应该出现。
1条答案
按热度按时间0yg35tkg1#
我测试了你的代码:
3.11.1
和OpenAI Python库0.25.0
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,…]
test.py
解决方案
STEP 1:升级Python
参见this。
STEP 2:升级OpenAI Python库