OpenAI
1. Overview
OpenAI's text embeddings measure the relevance between text strings and are commonly used in the following scenarios:
Search: Rank search results based on relevance to a query.
Clustering: Group similar text strings together.
Recommendations: Suggest items with related text content.
Anomaly Detection: Identify outlier text with low correlation to other data.
Diversity Measurement: Analyze the distribution of text similarity.
Classification: Categorize text based on the most similar labels.
Available model list:
text-embedding-3-smalltext-embedding-3-largetext-embedding-ada-002
2. Request Description
Request method:
POSTRequest address:
https://gateway.theturbo.ai/v1/audio/speech
3. Input Parameters
3.1 Header Parameters
Content-Type
string
Yes
Set the request header type, which must be application/json
application/json
Accept
string
Yes
Set the response type, which is recommended to be unified as application/json
application/json
Authorization
string
Yes
API_KEY required for authentication. Format: Bearer $YOUR_API_KEY
Bearer $YOUR_API_KEY
3.2 Body Parameters (application/json)
model
string
Yes
Model ID to use. See available models listed in the Overview for details, such as text-embedding-ada-002.
text-embedding-ada-002
input
string/array
Yes
Input content. The array dimension must not exceed 2048, and the input token count must not exceed 8192.
Hello, please tell me a joke.
encoding_format
string
No
Return vector format: supports float and base64.
float
4. Request Example
POST /v1/embeddings
Content-Type: application/json
Accept: application/json
Authorization: Bearer $YOUR_API_KEY
{
"model": "text-embedding-ada-002",
"input": "How is the whether today?"
}curl https://gateway.theturbo.ai/v1/embeddings \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer $YOUR_API_KEY" \
-d "{
\"model\": \"text-embedding-ada-002\",
\"input\": \"How is the whether today?\"
}"package main
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
)
const (
YOUR_API_KEY = "sk-123456789012345678901234567890123456789012345678"
REQUEST_PAYLOAD = `{
"model": "text-embedding-ada-002",
"input": "How is the whether today?"
}`
)
func main() {
requestURL := "https://gateway.theturbo.ai/v1/embeddings"
requestMethod := "POST"
requestPayload := strings.NewReader(REQUEST_PAYLOAD)
req, err := http.NewRequest(requestMethod, requestURL, requestPayload)
if err != nil {
fmt.Println("Create request failed, err: ", err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
req.Header.Add("Authorization", "Bearer "+YOUR_API_KEY)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Do request failed, err: ", err)
return
}
defer resp.Body.Close()
respBodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Read response body failed, err: ", err)
return
}
fmt.Println(string(respBodyBytes))
}5. Response Example
{
"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
}
}Last updated