File size: 5,199 Bytes
3a5a2dc 98c28c1 48142c9 3a5a2dc 91a1375 a665f3a 3a5a2dc a665f3a 3a5a2dc a665f3a 3a5a2dc a665f3a 3a5a2dc a665f3a 3a5a2dc 98c28c1 3a5a2dc 0606965 3a5a2dc 077f8e0 3a5a2dc 18adb0b 3a5a2dc 18adb0b 98c28c1 3a5a2dc 077f8e0 3a5a2dc 077f8e0 3a5a2dc 98c28c1 3a5a2dc 98c28c1 077f8e0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
import asyncio
import gradio as gr
import requests, re
# β¦(μλ΅)β¦
# ββββββββββββββββββββββββββββββββββββ
# 1. λ¨μΌ ν€ μ²λ¦¬ ν¨μλ‘ κΈ°μ‘΄ λ‘μ§ μ΄λ
# ββββββββββββββββββββββββββββββββββββ
async def process_single_key(key, rate_limit, claude_model):
_key = key.strip()
if re.match(re.compile("sk-or-v1-[a-z0-9]{64}"), _key):
return {"key": _key, **get_key_openrouter_info(_key)}
if re.match(re.compile("sk-ant-api03-[a-zA-Z0-9\\-_]{93}AA"), _key) or (
_key.startswith("sk-ant-") and len(_key) == 93
) or (len(_key) == 89 and re.match(re.compile("sk-[a-zA-Z0-9]{86}"), _key)):
return {"key": _key, **await get_key_ant_info(_key, rate_limit, claude_model)}
if re.match(re.compile(r"sk-[a-zA-Z0-9]{48}"), _key) and len(_key) == 51 and "T3BlbkFJ" not in _key:
return {"key": _key, **get_key_stability_info(_key)}
if re.match(re.compile(r"sk-[a-f0-9]{32}"), _key):
return {"key": _key, **get_key_deepseek_info(_key)}
if _key.startswith("sk-"):
return {"key": _key, **get_key_oai_info(_key)}
if _key.startswith("AIzaSy"):
return {"key": _key, **get_key_gemini_info(_key)}
if _key.startswith("pst-"):
return {"key": _key, **get_key_nai_info(_key)}
if (_key.startswith("r8_") and len(_key) == 40) or (_key.islower() and len(_key) == 40):
return {"key": _key, **get_key_replicate_info(_key)}
if _key.startswith("xai-"):
return {"key": _key, **get_key_xai_info(_key)}
if len(_key.split(":")) == 2 and _key.split(":")[1].islower() and len(_key.split(":")[1]) == 32 and "openai.azure.com" not in _key.split(":")[1]:
endpoint, api_key = _key.split(":")
return {"key": _key, **get_key_azure_info(endpoint, api_key)}
if "openai.azure.com" in _key.split(";")[0]:
endpoint, api_key = _key.split(";")
return {"key": _key, **get_key_azure_info(endpoint, api_key)}
if _key.startswith("AKIA") and len(_key.split(":")[0]) == 20 and _key.split(":")[0].isupper():
return {"key": _key, **await get_key_aws_info(_key)}
if re.match(re.compile(r"[a-f0-9]{32}"), _key) or re.match(re.compile(r"sk_[a-f0-9]{48}"), _key):
return {"key": _key, **get_key_elevenlabs_info(_key)}
if re.match(re.compile(r"[a-zA-Z0-9]{32}"), _key):
return {"key": _key, **get_key_mistral_info(_key)}
if re.match(re.compile(r"gsk_[a-zA-Z0-9]{20}WGdyb3FY[a-zA-Z0-9]{24}"), _key):
return {"key": _key, **get_key_groq_info(_key)}
if re.match(re.compile(r"[\\w\\-]+:[\\w\\-@\\.]+:[\\w-]+:.+"), _key):
return {"key": _key, **await get_key_gcp_info(_key, 0)}
if re.match(re.compile(r"[\\w\\-]+:[\\w\\-@\\.]+:.+\\n"), _key):
return {"key": _key, **await get_key_gcp_info(_key, 1)}
return {"key": _key, **not_supported(_key)}
# ββββββββββββββββββββββββββββββββββββ
# 2. μ¬λ¬ ν€ νκΊΌλ²μ μ²λ¦¬
# ββββββββββββββββββββββββββββββββββββ
async def sort_keys(text, rate_limit, claude_model):
keys = [k for k in text.splitlines() if k.strip()]
tasks = [process_single_key(k, rate_limit, claude_model) for k in keys]
results = await asyncio.gather(*tasks)
return results # JSON μ»΄ν¬λνΈκ° 리μ€νΈλ μ 보μ¬μ€
def clear_inputs(text): # κ·Έλλ‘
return ""
# ββββββββββββββββββββββββββββββββββββ
# 3. UI β μ
λ ₯μ°½ μ€ μ λλ¦¬κ³ , μ ν¨μ μ°κ²°
# ββββββββββββββββββββββββββββββββββββ
with gr.Blocks() as demo:
gr.Markdown(
"""
# β¦ (μ€λ΅) β¦
"""
)
claude_options = [
"claude-3-haiku-20240307",
"claude-3-sonnet-20240229",
"claude-3-opus-20240229",
"claude-3-5-sonnet-20240620",
"claude-3-5-sonnet-20241022",
"claude-3-5-haiku-20241022",
]
with gr.Row():
with gr.Column():
key = gr.Textbox(
lines=5, # μ¬λ¬ μ€ μ
λ ₯
max_lines=20,
label="API Key(s) β μ€λ°κΏμΌλ‘ μ¬λ¬ κ° μ
λ ₯",
)
claude_model = gr.Dropdown(
claude_options,
value="claude-3-haiku-20240307",
label="Claude API model (rate-limit checkμ©)",
)
rate_limit = gr.Checkbox(label="Check concurrent rate limit (Claude, experimental)")
with gr.Row():
clear_button = gr.Button("Clear")
submit_button = gr.Button("Submit", variant="primary")
with gr.Column():
info = gr.JSON(label="API Key Information", open=True)
clear_button.click(fn=clear_inputs, inputs=[key], outputs=[key])
submit_button.click(fn=sort_keys, inputs=[key, rate_limit, claude_model], outputs=[info], api_name="sort_keys")
demo.launch()
|