Skywork Client使用
2024-08-20
python
import time
import hashlib
import requests
url = "https://api-maas.singularity-ai.com/sky-work/api/v1/chat"
app_key = "替换成你的apikey"
app_secret = "替换成你的app_secret"
timestamp = str(int(time.time()))
sign_content = app_key + app_secret + timestamp
sign_result = hashlib.md5(sign_content.encode("utf-8")).hexdigest()
# 设置请求头,请求的数据格式为json
headers = {
"app_key": app_key,
"timestamp": timestamp,
"sign": sign_result,
"Content-Type": "application/json",
}
# 设置请求URL和参数
data = {
"messages": [{"role": "user", "content": "给我一个赚取10w的方法"}],
"intent": "", # 用于强制指定意图,默认为空将进行意图识别判定是否搜索增强,取值 'chat'则不走搜索增强
"stream": True,
}
# 发起请求并获取响应
print("----- streaming request -----")
response = requests.post(url, headers=headers, json=data, stream=True)
# 处理响应流
for line in response.iter_lines():
if line:
# 处理接收到的数据
print(line.decode("utf-8"))
print("----- standard request -----")
# 设置请求URL和参数
data = {
"messages": [{"role": "user", "content": "给我一个赚取10w的方法"}],
"intent": "", # 用于强制指定意图,默认为空将进行意图识别判定是否搜索增强,取值 'chat'则不走搜索增强
}
response = requests.post(url, headers=headers, json=data)
print(response.text)