当前位置: 首页 > news >正文

OpenAI Embeddings API: How to extract the embedding vector?

题意:“OpenAI 嵌入 API:如何提取嵌入向量?”

问题背景:

I use nearly the same code as here in this GitHub repo to get embeddings from OpenAI:

“我使用几乎与此 GitHub 仓库中的代码相同的代码,从 OpenAI 获取嵌入:”

oai = OpenAI(
# This is the default and can be omitted
api_key="sk-.....",
)def get_embedding(text_to_embed, openai):response = openai.embeddings.create(model= "text-embedding-ada-002",input=[text_to_embed])return responseembedding_raw = get_embedding(text,oai)

According to the GitHub repo, the vector should be in response['data'][0]['embedding']. But it isn't in my case.

根据 GitHub 仓库的说明,向量应该在 response['data'][0]['embedding'] 中。但在我的情况下并没有。

When I printed the response variable, I got this:

“当我打印 `response` 变量时,我得到了这个结果:”

print(embedding_raw)

Output:        输出信息:

CreateEmbeddingResponse(data=[Embedding(embedding=[0.009792150929570198, -0.01779201813042164, 0.011846082285046577, -0.0036859565880149603, -0.0013213189085945487, 0.00037509595858864486,..... -0.0121011883020401, -0.015751168131828308], index=0, object='embedding')], model='text-embedding-ada-002', object='list', usage=Usage(prompt_tokens=360, total_tokens=360))

How can I access the embedding vector?

“我该如何访问嵌入向量?”

问题解决:

Simply return just the embedding vector as follows:

“只需按如下方式返回嵌入向量即可:”

def get_embedding(text_to_embed, openai):response = openai.embeddings.create(model= "text-embedding-ada-002",input=[text_to_embed])return response.data[0].embedding # Change thisembedding_raw = get_embedding(text,oai)


http://www.mrgr.cn/news/4111.html

相关文章:

  • SVG中的paint-order属性实现文字描边
  • Hadoop 中的大数据技术:Zookeeper安装 (2)
  • 05创建型设计模式——原型模式
  • 汇凯贵金属:金子在家怎么清洗才干净
  • 非常nice! IDEA远程Debug调试程序
  • epoll机制中最核⼼的数据结构是什么?
  • 并查集在哪些具体应用中最常用
  • 计算机相关法律法规及违规案例
  • 机器学习在旅游业的革新之旅
  • ubuntu18.04更改系统语言及换源的方法步骤
  • 深入解析css-学习小结
  • C语言 | Leetcode C语言题解之第342题4的幂
  • PostgreSQL的pg_dump中 --inserts参数测试
  • CMOS 逆变器的功耗
  • WPS Office两个严重漏洞曝光,已被武器化且在野利用
  • MCU数据采集模块:核心功能与工作机制深度解析
  • Verilog刷题笔记55
  • Ubuntu清除缓存的方法--防止系统崩溃
  • 麻将手游开发的未来之路:技术与创新并行
  • TOMCAT入门到精通