工具与嵌入
文本嵌入
将文本转换为向量表示
POST
/
v1
/
embeddings
curl https://www.qingbo.dev/v1/embeddings \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": "清波 API 是统一的 AI 模型网关"
}'
from openai import OpenAI
client = OpenAI(
base_url="https://www.qingbo.dev/v1",
api_key="YOUR_API_KEY"
)
response = client.embeddings.create(
model="text-embedding-3-small",
input="清波 API 是统一的 AI 模型网关"
)
vector = response.data[0].embedding
print(f"向量维度: {len(vector)}")
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://www.qingbo.dev/v1',
apiKey: 'YOUR_API_KEY'
});
const response = await client.embeddings.create({
model: 'text-embedding-3-small',
input: '清波 API 是统一的 AI 模型网关'
});
console.log(`向量维度: ${response.data[0].embedding.length}`);
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
payload := map[string]string{
"model": "text-embedding-3-small",
"input": "清波 API 是统一的 AI 模型网关",
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://www.qingbo.dev/v1/embeddings", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}
import java.net.http.*;
import java.net.URI;
public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"model": "text-embedding-3-small",
"input": "清波 API 是统一的 AI 模型网关"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://www.qingbo.dev/v1/embeddings"))
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
{
"object": "list",
"model": "text-embedding-3-small",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023, -0.0091, 0.0152, ...]
}
],
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
同步接口 — 请求完成后直接返回向量结果。
curl https://www.qingbo.dev/v1/embeddings \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": "清波 API 是统一的 AI 模型网关"
}'
from openai import OpenAI
client = OpenAI(
base_url="https://www.qingbo.dev/v1",
api_key="YOUR_API_KEY"
)
response = client.embeddings.create(
model="text-embedding-3-small",
input="清波 API 是统一的 AI 模型网关"
)
vector = response.data[0].embedding
print(f"向量维度: {len(vector)}")
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://www.qingbo.dev/v1',
apiKey: 'YOUR_API_KEY'
});
const response = await client.embeddings.create({
model: 'text-embedding-3-small',
input: '清波 API 是统一的 AI 模型网关'
});
console.log(`向量维度: ${response.data[0].embedding.length}`);
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
payload := map[string]string{
"model": "text-embedding-3-small",
"input": "清波 API 是统一的 AI 模型网关",
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://www.qingbo.dev/v1/embeddings", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}
import java.net.http.*;
import java.net.URI;
public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"model": "text-embedding-3-small",
"input": "清波 API 是统一的 AI 模型网关"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://www.qingbo.dev/v1/embeddings"))
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
{
"object": "list",
"model": "text-embedding-3-small",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023, -0.0091, 0.0152, ...]
}
],
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
请求参数
嵌入模型 ID,如
text-embedding-3-small、text-embedding-3-large要嵌入的文本,支持字符串或字符串数组(批量嵌入)
响应
固定为
"list"使用的模型
⌘I
curl https://www.qingbo.dev/v1/embeddings \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": "清波 API 是统一的 AI 模型网关"
}'
from openai import OpenAI
client = OpenAI(
base_url="https://www.qingbo.dev/v1",
api_key="YOUR_API_KEY"
)
response = client.embeddings.create(
model="text-embedding-3-small",
input="清波 API 是统一的 AI 模型网关"
)
vector = response.data[0].embedding
print(f"向量维度: {len(vector)}")
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://www.qingbo.dev/v1',
apiKey: 'YOUR_API_KEY'
});
const response = await client.embeddings.create({
model: 'text-embedding-3-small',
input: '清波 API 是统一的 AI 模型网关'
});
console.log(`向量维度: ${response.data[0].embedding.length}`);
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
payload := map[string]string{
"model": "text-embedding-3-small",
"input": "清波 API 是统一的 AI 模型网关",
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://www.qingbo.dev/v1/embeddings", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}
import java.net.http.*;
import java.net.URI;
public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"model": "text-embedding-3-small",
"input": "清波 API 是统一的 AI 模型网关"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://www.qingbo.dev/v1/embeddings"))
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
{
"object": "list",
"model": "text-embedding-3-small",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023, -0.0091, 0.0152, ...]
}
],
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}