57 lines
2.5 KiB
Python
57 lines
2.5 KiB
Python
import sys
|
|
from ahserver.serverenv import ServerEnv
|
|
from appPublic.dictObject import DictObject
|
|
import time
|
|
import jwt
|
|
|
|
def generate_zhipuai_token(apikey: str, exp_seconds: int=86400):
|
|
try:
|
|
id, secret = apikey.split(".")
|
|
except Exception as e:
|
|
raise Exception("invalid apikey", e)
|
|
|
|
payload = {
|
|
"api_key": id,
|
|
"exp": int(round(time.time() * 1000)) + exp_seconds * 1000,
|
|
"timestamp": int(round(time.time() * 1000)),
|
|
}
|
|
|
|
return jwt.encode(
|
|
payload,
|
|
secret,
|
|
algorithm="HS256",
|
|
headers={"alg": "HS256", "sign_type": "SIGN"},
|
|
)
|
|
|
|
async def get_llm_user_apikey(apiname, user):
|
|
if apiname == 'qianwen':
|
|
return DictObject(apikey='sk-ca5dfeb58d494f32a9cf1e9f064370c8')
|
|
|
|
if apiname=='baiduqianfan':
|
|
return DictObject(apikey='SjAN4GHU07LuB8ZYOIstB31G',
|
|
secretkey='QbakADoGJsM2qjUzIogTkBZruToxYAve')
|
|
if apiname=='baichuanai':
|
|
return DictObject(apikey='sk-f1fca6335df32d13c096e5f2e72821db')
|
|
if apiname=='deepseek':
|
|
return DictObject(apikey='sk-a6a2d5eca1b7419b95f2c263c362be1e')
|
|
|
|
if apiname == 'minimax':
|
|
return DictObject(apikey='eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJHcm91cE5hbWUiOiJtb3FpbmcgeXUiLCJVc2VyTmFtZSI6Im1vcWluZyB5dSIsIkFjY291bnQiOiIiLCJTdWJqZWN0SUQiOiIxNzY4NTM3NjQ1ODMyNDg3NjAyIiwiUGhvbmUiOiIxMzgwMTAxNTI5MiIsIkdyb3VwSUQiOiIxNzY4NTM3NjQ1ODI4MjkyOTMwIiwiUGFnZU5hbWUiOiIiLCJNYWlsIjoiIiwiQ3JlYXRlVGltZSI6IjIwMjQtMDQtMTAgMTg6MDA6NTMiLCJpc3MiOiJtaW5pbWF4In0.VaRRHr9XMUSYhZOKVS2PRZv6Y9VCaW4JX2ks4QZX3aFr_emjnDbGv5HfNskf54piflEAeTMW4Qw1nG7bqhYea7N5LKHGf0YpesPGSoqxwyZUR4oaJNNVUsSe6eiLbdYSDO2wMb_hV5xyawh-lYe1reBKWaPVuOjfTrDhxzA0IBmzl-jAQhL8-kIZet2uX-p3NjxElpo_zjmVV_hA1BJEvTwuAk8ka-1SBZmXciMhBi1fJG4jcqoHCCN_JHJ7pgjKr5bk2Zw5qCqiU2Ecsc-kPIEK1SI5EYoLszT43UpJ8_wV4Pm07UBCn3vktAa0fjKDSUArPkBoYWSkgKDMWlmxig', groupid='1768537645828292930')
|
|
if apiname == 'zhipuai':
|
|
return DictObject(token=generate_zhipuai_token('ffd0affcb6b5f9368f517c09c75a6817.jp9DdpcgwdxXvDiT'))
|
|
if apiname == 'moonshot':
|
|
return DictObject(apikey='sk-fHOyIKC2mlIDfGwUQV6SwjwVJkjBJgkNWYv82yt3OdpYh592')
|
|
if apiname == 'openai':
|
|
return DictObject(apikey='sk-proj-gFbYlxVnhmfqf8MXhX42T3BlbkFJprO7jXabkwtjmrNeH77Z')
|
|
if apiname == 'doubao':
|
|
return DictObject(apikey='a2fddeaa-c31c-4cbe-aacb-732318408dac')
|
|
|
|
if apiname == 'tianqi':
|
|
return DictObject(apikey='94b72c37e62e49f796502d29955447ab', secretkey='afcac498e0a74302bec06d22dcdff213')
|
|
|
|
print(f'{user=} not have apikey for {apiname=}')
|
|
return DictObject()
|
|
|
|
g = ServerEnv()
|
|
g.get_llm_user_apikey = get_llm_user_apikey
|