Skip to content

Commit

Permalink
uni-api: add a few more providers
Browse files Browse the repository at this point in the history
  • Loading branch information
xddxdd committed Dec 8, 2024
1 parent e7ddf0d commit 0e8d674
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 65 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions nixos/optional-apps/uni-api/apis/ai-985-games.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"360gpt2-pro": "@ai-985-games/360gpt2-pro",
"GLM-4-Flash": "thudm/glm-4-flash",
"hunyuan-lite": "tencent/hunyuan-lite",
"internlm2.5-latest": "internlm/internlm-2.5-latest",
"qwen2.5-72b-instruct": "qwen/qwen-2.5-72b-instruct",
"qwq-32b-preview": "qwen/qwq-32b-preview",
"yi-lightning": "01-ai/yi-lightning",
"yi-medium-200k": "01-ai/yi-medium-200k"
}
1 change: 1 addition & 0 deletions nixos/optional-apps/uni-api/apis/cloudflare.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@cf/meta/llama-3.2-11b-vision-instruct": "meta/llama-3.2-11b-vision-instruct",
"@cf/meta/llama-3.2-1b-instruct": "meta/llama-3.2-1b-instruct",
"@cf/meta/llama-3.2-3b-instruct": "meta/llama-3.2-3b-instruct",
"@cf/meta/llama-3.3-70b-instruct-fp8-fast": "meta/llama-3.3-70b-instruct-fp8-fast",
"@cf/microsoft/phi-2": "microsoft/phi-2",
"@cf/mistral/mistral-7b-instruct-v0.1": "mistral/mistral-7b-instruct-v0.1",
"@cf/openchat/openchat-3.5-0106": "openchat/openchat-3.5-0106",
Expand Down
11 changes: 6 additions & 5 deletions nixos/optional-apps/uni-api/apis/groq.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"llama-3.2-1b-preview": "meta-llama/llama-3.2-1b-preview",
"llama-3.2-3b-preview": "meta-llama/llama-3.2-3b-preview",
"llama-3.2-90b-vision-preview": "meta-llama/llama-3.2-90b-vision-preview",
"llama-3.3-70b-specdec": "meta-llama/llama-3.3-70b-specdec",
"llama-3.3-70b-versatile": "meta-llama/llama-3.3-70b-versatile",
"llama-guard-3-8b": "meta-llama/llama-guard-3-8b",
"llama3-70b-8192": "@groq/llama-3-70b-8192",
"llama3-8b-8192": "@groq/llama-3-8b-8192",
"llama3-groq-70b-8192-tool-use-preview": "@groq/llama-3-groq-70b-8192-tool-use-preview",
"llama3-groq-8b-8192-tool-use-preview": "@groq/llama-3-groq-8b-8192-tool-use-preview",
"llava-v1.5-7b-4096-preview": "@groq/llava-v1.5-7b-4096-preview",
"llama3-70b-8192": "meta-llama/llama-3-70b-8192",
"llama3-8b-8192": "meta-llama/llama-3-8b-8192",
"llama3-groq-70b-8192-tool-use-preview": "meta-llama/llama-3-groq-70b-8192-tool-use-preview",
"llama3-groq-8b-8192-tool-use-preview": "meta-llama/llama-3-groq-8b-8192-tool-use-preview",
"mixtral-8x7b-32768": "mistralai/mixtral-8x7b-32768",
"whisper-large-v3": "@groq/whisper-large-v3",
"whisper-large-v3-turbo": "@groq/whisper-large-v3-turbo"
Expand Down
13 changes: 13 additions & 0 deletions nixos/optional-apps/uni-api/apis/lingyiwanwu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"yi-large": "01-ai/yi-large",
"yi-large-fc": "01-ai/yi-large-fc",
"yi-large-preview": "01-ai/yi-large-preview",
"yi-large-rag": "01-ai/yi-large-rag",
"yi-large-turbo": "01-ai/yi-large-turbo",
"yi-lightning": "01-ai/yi-lightning",
"yi-medium": "01-ai/yi-medium",
"yi-medium-200k": "01-ai/yi-medium-200k",
"yi-spark": "01-ai/yi-spark",
"yi-vision": "01-ai/yi-vision",
"yi-vision-solution": "01-ai/yi-vision-solution"
}
1 change: 1 addition & 0 deletions nixos/optional-apps/uni-api/apis/novita.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"meta-llama/llama-3.2-11b-vision-instruct": "meta-llama/llama-3.2-11b-vision-instruct",
"meta-llama/llama-3.2-1b-instruct": "meta-llama/llama-3.2-1b-instruct",
"meta-llama/llama-3.2-3b-instruct": "meta-llama/llama-3.2-3b-instruct",
"meta-llama/llama-3.3-70b-instruct": "meta-llama/llama-3.3-70b-instruct",
"microsoft/wizardlm-2-7b": "microsoft/wizardlm-2-7b",
"microsoft/wizardlm-2-8x22b": "microsoft/wizardlm-2-8x22b",
"mistralai/mistral-7b-instruct": "mistralai/mistral-7b-instruct",
Expand Down
7 changes: 7 additions & 0 deletions nixos/optional-apps/uni-api/apis/openrouter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"ai21/jamba-instruct": "ai21/jamba-instruct",
"alpindale/goliath-120b": "alpindale/goliath-120b",
"alpindale/magnum-72b": "alpindale/magnum-72b",
"amazon/nova-lite-v1": "amazon/nova-lite-v1",
"amazon/nova-micro-v1": "amazon/nova-micro-v1",
"amazon/nova-pro-v1": "amazon/nova-pro-v1",
"anthracite-org/magnum-v2-72b": "anthracite-org/magnum-v2-72b",
"anthracite-org/magnum-v4-72b": "anthracite-org/magnum-v4-72b",
"anthropic/claude-2": "anthropic/claude-2",
"anthropic/claude-2.0": "anthropic/claude-2.0",
Expand Down Expand Up @@ -40,6 +44,7 @@
"eva-unit-01/eva-qwen-2.5-72b": "eva-unit-01/eva-qwen-2.5-72b",
"google/gemini-exp-1114:free": "google/gemini-exp-1114:free",
"google/gemini-exp-1121:free": "google/gemini-exp-1121:free",
"google/gemini-exp-1206:free": "google/gemini-exp-1206:free",
"google/gemini-flash-1.5": "google/gemini-flash-1.5",
"google/gemini-flash-1.5-8b": "google/gemini-flash-1.5-8b",
"google/gemini-flash-1.5-8b-exp": "google/gemini-flash-1.5-8b-exp",
Expand Down Expand Up @@ -92,6 +97,7 @@
"meta-llama/llama-3.2-3b-instruct:free": "meta-llama/llama-3.2-3b-instruct:free",
"meta-llama/llama-3.2-90b-vision-instruct": "meta-llama/llama-3.2-90b-vision-instruct",
"meta-llama/llama-3.2-90b-vision-instruct:free": "meta-llama/llama-3.2-90b-vision-instruct:free",
"meta-llama/llama-3.3-70b-instruct": "meta-llama/llama-3.3-70b-instruct",
"meta-llama/llama-guard-2-8b": "meta-llama/llama-guard-2-8b",
"microsoft/phi-3-medium-128k-instruct": "microsoft/phi-3-medium-128k-instruct",
"microsoft/phi-3-medium-128k-instruct:free": "microsoft/phi-3-medium-128k-instruct:free",
Expand Down Expand Up @@ -183,6 +189,7 @@
"qwen/qwq-32b-preview": "qwen/qwq-32b-preview",
"raifle/sorcererlm-8x22b": "raifle/sorcererlm-8x22b",
"sao10k/l3-euryale-70b": "sao10k/l3-euryale-70b",
"sao10k/l3-lunaris-8b": "sao10k/l3-lunaris-8b",
"sao10k/l3.1-euryale-70b": "sao10k/l3.1-euryale-70b",
"sophosympatheia/midnight-rose-70b": "sophosympatheia/midnight-rose-70b",
"teknium/openhermes-2.5-mistral-7b": "teknium/openhermes-2.5-mistral-7b",
Expand Down
4 changes: 3 additions & 1 deletion nixos/optional-apps/uni-api/apis/siliconflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"deepseek-ai/DeepSeek-V2-Chat": "deepseek-ai/deepseek-v2-chat",
"deepseek-ai/DeepSeek-V2.5": "deepseek-ai/deepseek-v2.5",
"fishaudio/fish-speech-1.4": "fishaudio/fish-speech-1.4",
"fishaudio/fish-speech-1.5": "fishaudio/fish-speech-1.5",
"google/gemma-2-27b-it": "google/gemma-2-27b-it",
"google/gemma-2-9b-it": "google/gemma-2-9b-it",
"internlm/internlm2_5-20b-chat": "internlm/internlm-2_5-20b-chat",
Expand All @@ -65,5 +66,6 @@
"stabilityai/stable-diffusion-3-5-large": "stabilityai/stable-diffusion-3-5-large",
"stabilityai/stable-diffusion-3-5-large-turbo": "stabilityai/stable-diffusion-3-5-large-turbo",
"stabilityai/stable-diffusion-3-medium": "stabilityai/stable-diffusion-3-medium",
"stabilityai/stable-diffusion-xl-base-1.0": "stabilityai/stable-diffusion-xl-base-1.0"
"stabilityai/stable-diffusion-xl-base-1.0": "stabilityai/stable-diffusion-xl-base-1.0",
"tencent/HunyuanVideo": "tencent/hunyuanvideo"
}
86 changes: 41 additions & 45 deletions nixos/optional-apps/uni-api/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ let
};
model = loadModels ./apis/cloudflare.json;
}
{
provider = "lingyiwanwu";
base_url = "https://api.lingyiwanwu.com/v1/chat/completions";
api = {
_secret = config.age.secrets.uni-api-lingyiwanwu-api-key.path;
};
model = loadModels ./apis/lingyiwanwu.json;
}
# Third party free providers
{
provider = "ai-985-games";
base_url = "https://ai.985.games/v1/chat/completions";
api = {
_secret = config.age.secrets.uni-api-ai-985-games-api-key.path;
};
model = loadModels ./apis/ai-985-games.json;
}
{
provider = "siliconflow-pool";
base_url = "http://api.888188.me/v1/chat/completions";
Expand Down Expand Up @@ -84,51 +101,30 @@ let
};
in
{
age.secrets.uni-api-novita-api-key = {
file = inputs.secrets + "/uni-api/novita-api-key.age";
owner = "uni-api";
group = "uni-api";
};
age.secrets.uni-api-openrouter-api-key = {
file = inputs.secrets + "/uni-api/openrouter-api-key.age";
owner = "uni-api";
group = "uni-api";
};
age.secrets.uni-api-siliconflow-api-key = {
file = inputs.secrets + "/uni-api/siliconflow-api-key.age";
owner = "uni-api";
group = "uni-api";
};
age.secrets.uni-api-siliconflow-pool-api-key = {
file = inputs.secrets + "/uni-api/siliconflow-pool-api-key.age";
owner = "uni-api";
group = "uni-api";
};
age.secrets.uni-api-mistral-api-key = {
file = inputs.secrets + "/uni-api/mistral-api-key.age";
owner = "uni-api";
group = "uni-api";
};
age.secrets.uni-api-groq-api-key = {
file = inputs.secrets + "/uni-api/groq-api-key.age";
owner = "uni-api";
group = "uni-api";
};
age.secrets.uni-api-cloudflare-account-id = {
file = inputs.secrets + "/uni-api/cloudflare-account-id.age";
owner = "uni-api";
group = "uni-api";
};
age.secrets.uni-api-cloudflare-api-key = {
file = inputs.secrets + "/uni-api/cloudflare-api-key.age";
owner = "uni-api";
group = "uni-api";
};
age.secrets.uni-api-admin-api-key = {
file = inputs.secrets + "/uni-api/admin-api-key.age";
owner = "uni-api";
group = "uni-api";
};
age.secrets = builtins.listToAttrs (
builtins.map
(
f:
lib.nameValuePair "uni-api-${f}" {
file = inputs.secrets + "/uni-api/${f}.age";
owner = "uni-api";
group = "uni-api";
}
)
[
"admin-api-key"
"ai-985-games-api-key"
"cloudflare-account-id"
"cloudflare-api-key"
"groq-api-key"
"lingyiwanwu-api-key"
"mistral-api-key"
"novita-api-key"
"openrouter-api-key"
"siliconflow-api-key"
"siliconflow-pool-api-key"
]
);

systemd.services.uni-api = {
description = "Uni-API Server";
Expand Down
39 changes: 28 additions & 11 deletions nixos/optional-apps/uni-api/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
HOME = pathlib.Path.home()

APIS = {
"ai-985-games": "https://ai.985.games/v1",
"cloudflare": "https://playground.ai.cloudflare.com/api",
"groq": "https://api.groq.com/openai/v1",
"lingyiwanwu": "https://api.lingyiwanwu.com/v1",
"mistral": "https://api.mistral.ai/v1",
"novita": "https://api.novita.ai/v3/openai",
"openrouter": "https://openrouter.ai/api/v1",
Expand All @@ -33,7 +35,18 @@
"pixtral-",
],
"meta-llama": ["llama-"],
"google": ["gemma"],
"google": ["gemma-"],
"01-ai": ["yi-"],
"thudm": [
"glm-",
"chatglm-",
],
"tencent": ["hunyuan"],
"internlm": ["internlm-"],
"qwen": [
"qwen-",
"qwq-",
],
}


Expand Down Expand Up @@ -88,22 +101,22 @@ def normalize_model_id(api_name: str, model_id: str) -> str:
# Remove provider's own differentiator in model prefix
result = re.sub(r"^@[^/]+/", "", result)

# Guess provider for model
if "/" not in result:
provider = guess_provider(result)
if not provider:
provider = f"@{api_name}"
result = f"{provider}/{result}"
assert "/" in result

# Move extra prefix to the end as model variants
if result.count("/") > 1:
splitted = result.split("/")
suffix = "/".join(splitted[:-2])
result = f"{splitted[-2]}/{splitted[-1]}:{suffix}"

# Add separator between model name and version
result = re.sub(r"^([^/]+)/([a-zA-Z]{2,})([0-9]+)", r"\1/\2-\3", result)
result = re.sub(r"(^|/)([a-zA-Z]{2,})([0-9]+)([^/]*)$", r"\1\2-\3\4", result)

# Guess provider for model
if "/" not in result:
provider = guess_provider(result)
if not provider:
provider = f"@{api_name}"
result = f"{provider}/{result}"
assert "/" in result

return result

Expand All @@ -119,9 +132,13 @@ def process_api(input_obj: Tuple[str, str]):
with open(f"{SCRIPT_PATH}/apis/{api_name}.json", "w") as f:
json.dump(mappings, f, indent=2, sort_keys=True)
f.write("\n")
return True


if __name__ == "__main__":
os.makedirs(f"{SCRIPT_PATH}/apis", exist_ok=True)
pool = multiprocessing.Pool()
pool.map(process_api, APIS.items())
try:
pool.map(process_api, APIS.items())
except Exception as e:
print(e)

0 comments on commit 0e8d674

Please sign in to comment.