Embeddings
Note
调用前请先构建客户端,构建代码如下:
OpenAiClient client = OpenAiClient.builder()
.apiHost("https://api.openai.com")
.apiKey(System.getProperty("openai.token"))
.build();
System.getProperty("openai.token")
是访问 API 授权的关键。
Create embeddings
创建表示输入文本的嵌入向量。
EmbeddingEntity configure=EmbeddingEntity.builder()
.model("text-similarity-ada-001")
.input("Hello OpenAi Java SDK")
.build();
client.createEmbeddings(configure);
Return
{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
0.0023064255,
-0.009327292,
.... (1536 floats total for ada-002)
-0.0028842222,
],
"index": 0
}
],
"model": "text-embedding-ada-002",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}