Files
dsProject/dsLightRag/Volcengine/State.py
2025-09-07 08:56:35 +08:00

53 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
import requests
from volcengine.base.Request import Request
from volcengine.Credentials import Credentials
from volcengine.auth.SignerV4 import SignerV4
from Config.Config import VOLC_ACCESSKEY, VOLC_SECRETKEY
from Volcengine.VikingDBMemoryService import MEMORY_COLLECTION_NAME
AK = VOLC_ACCESSKEY
SK = VOLC_SECRETKEY
Domain = "api-knowledgebase.mlp.cn-beijing.volces.com"
def prepare_request(method, path, ak, sk, data=None):
r = Request()
r.set_shema("http") # 注意:这里用 http因为 SignerV4 内部会拼 host
r.set_method(method)
r.set_host(Domain)
r.set_path(path)
if data is not None:
r.set_body(json.dumps(data))
# 使用 air 服务和 cn-north-1 区域
credentials = Credentials(ak, sk, 'air', 'cn-north-1')
SignerV4.sign(r, credentials)
return r
def internal_request(method, api, payload, params=None):
req = prepare_request(
method=method,
path=api,
ak=AK,
sk=SK,
data=payload
)
r = requests.request(
method=req.method,
url="{}://{}{}".format(req.schema, req.host, req.path),
headers=req.headers,
data=req.body,
params=params,
)
return r
# 查询记忆库信息
path = '/api/memory/collection/info'
payload = {
"CollectionName": MEMORY_COLLECTION_NAME
}
rsp = internal_request("POST", path, payload)
print(rsp.json())