File size: 805 Bytes
e397647
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import urllib3
import json

def embeddings_run(input, url="https://sanbo1200-jina-embeddings-v3.hf.space/api/v1/embeddings", model="jinaai/jina-embeddings-v3"):
    # 创建 PoolManager 实例
    http = urllib3.PoolManager()
    
    headers = {
        'Content-Type': 'application/json'
    }
    
    data = {
        "input": input,
        "model": model
    }
    
    # 发送 POST 请求
    response = http.request(
        'POST',
        url,
        headers=headers,
        body=json.dumps(data).encode('utf-8')
    )
    
    # 检查响应状态
    if response.status == 200:
        return json.loads(response.data.decode('utf-8'))
    else:
        response.raise_for_status()

if __name__ == "__main__":
    input = "Your text string goes here"
    print(f"---{embeddings_run(input)}")