Skip to content

Commit

Permalink
发布,修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
duolabmeng6 committed Nov 30, 2024
1 parent 204182b commit 5770580
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions app/apiDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,14 @@ def get_user_provider(self, api_key: str, model_name: str) -> Tuple[List[Dict],

filtered_usability_model = []
for model in usability_model:
# 检查用户是否有权限使用该模型
for user_model in user_use_model:
if user_model == model['original_model']:
if user_model.endswith('*'):
# 如果用户模型以*结尾,检查原始模型名称是否以*之前的部分开头
if model['original_model'].startswith(user_model[:-1]):
filtered_usability_model.append(model)
break
elif user_model == model['original_model']:
filtered_usability_model.append(model)
break

Expand Down Expand Up @@ -184,32 +190,35 @@ def is_model_allowed(user_model: str, model_name: str) -> bool:
def init():
config = pyefun.读入文本("./api.yaml")
db = apiDB(config)
# ret = db.verify_token("sk-abcdefg")
# print("token状态", ret)
ret = db.verify_token("sk-aliyun")
print("token状态", ret)

# ret = db.verify_token("sk-111111")
# print("token状态", ret)
api_key = "sk-111111"
api_key = "sk-aliyun"
model = "qwen2-72b"
model2 = "gemini-1.5-pro"


provider, err = db.get_user_provider(api_key, model)
print("配置:", err, json.dumps(provider, indent=4))

#
provider2, err = db.get_user_provider(api_key, model2)
print("配置:", err, json.dumps(provider, indent=4))
balance = Balance(api_key + model, provider2)
balance = Balance(api_key + model2, provider)


for i in range(10):
p = balance.next()
print(p.data)

for i in range(10):
p = balance.next()
print(p.data)

yield


asyncio.run(init())
print("配置:", err, json.dumps(provider2, indent=4))
# balance = Balance(api_key + model, provider2)
# balance = Balance(api_key + model2, provider)
#
#
# for i in range(10):
# p = balance.next()
# print(p.data)
#
# for i in range(10):
# p = balance.next()
# print(p.data)
#
# yield


init()
# asyncio.run(init())

0 comments on commit 5770580

Please sign in to comment.