Spaces:
Running
Running
File size: 955 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 34 35 |
import grequests
import json
def embeddings_run(inputs, url="https://sanbo1200-jina-embeddings-v3.hf.space/api/v1/embeddings", model="jinaai/jina-embeddings-v3"):
headers = {
"Content-Type": "application/json"
}
# 支持单个或批量请求
if isinstance(inputs, str):
inputs = [inputs]
# 创建请求列表
requests = [
grequests.post(
url,
headers=headers,
json={"input": input, "model": model}
) for input in inputs
]
# 并发执行请求
responses = grequests.map(requests)
# 处理响应
results = []
for response in responses:
if response and response.status_code == 200:
results.append(response.json())
return results[0] if len(inputs) == 1 else results
if __name__ == "__main__":
input_text = "Your text string goes here"
print(f"---{embeddings_run(input_text)}") |