Spaces:
Running
Running
File size: 882 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 |
from urllib.request import Request, urlopen
import json
def embeddings_run(input, url="https://sanbo1200-jina-embeddings-v3.hf.space/api/v1/embeddings", model="jinaai/jina-embeddings-v3"):
headers = {
"Content-Type": "application/json"
}
data = {
"input": input,
"model": model
}
# 创建请求
request = Request(
url,
headers=headers,
data=json.dumps(data).encode('utf-8'),
method='POST'
)
# 发送请求并获取响应
try:
with urlopen(request) as response:
if response.status == 200:
return json.loads(response.read().decode('utf-8'))
except Exception as e:
raise Exception(f"Request failed: {str(e)}")
if __name__ == "__main__":
input_text = "Your text string goes here"
print(f"---{embeddings_run(input_text)}") |