import json
import requests
def embedding_cosine_similarity(text_1, text_2):
    # 请求头
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer gpustack_dee9ca823290886c_5edfc86aeeeceb1e9ee5162941cb2cb5'
    }

    # 请求体
    data = {
        "text_1": text_1,
        "text_2": text_2,
        "model": "bge-rerank"
    }

    # 发送 POST 请求
    response = requests.post("http://172.18.30.122:9500/v1" + "/score", headers=headers, data=json.dumps(data))
    if response.status_code == 200:
        result_json= response.json()
        # print(result_json)
        score = result_json["data"][0]["score"]
        return score
    else:
        raise Exception(f"Error: {response.status_code}\n{response.text}")  # 抛出异常
    
print(embedding_cosine_similarity("你好","Hello"))