Skip to content

Commit

Permalink
uni-api: add google API
Browse files Browse the repository at this point in the history
  • Loading branch information
xddxdd committed Jan 10, 2025
1 parent 6f6a806 commit 6b9048f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5 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.

31 changes: 31 additions & 0 deletions nixos/optional-apps/uni-api/apis/google.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"gemini-1.0-pro": "google/gemini-1.0-pro",
"gemini-1.0-pro-001": "google/gemini-1.0-pro-001",
"gemini-1.0-pro-latest": "google/gemini-1.0-pro-latest",
"gemini-1.0-pro-vision-latest": "google/gemini-1.0-pro-vision-latest",
"gemini-1.5-flash": "google/gemini-1.5-flash",
"gemini-1.5-flash-001": "google/gemini-1.5-flash-001",
"gemini-1.5-flash-001-tuning": "google/gemini-1.5-flash-001-tuning",
"gemini-1.5-flash-002": "google/gemini-1.5-flash-002",
"gemini-1.5-flash-8b": "google/gemini-1.5-flash-8b",
"gemini-1.5-flash-8b-001": "google/gemini-1.5-flash-8b-001",
"gemini-1.5-flash-8b-exp-0827": "google/gemini-1.5-flash-8b-exp-0827",
"gemini-1.5-flash-8b-exp-0924": "google/gemini-1.5-flash-8b-exp-0924",
"gemini-1.5-flash-8b-latest": "google/gemini-1.5-flash-8b-latest",
"gemini-1.5-flash-exp-0827": "google/gemini-1.5-flash-exp-0827",
"gemini-1.5-flash-latest": "google/gemini-1.5-flash-latest",
"gemini-1.5-pro": "google/gemini-1.5-pro",
"gemini-1.5-pro-001": "google/gemini-1.5-pro-001",
"gemini-1.5-pro-002": "google/gemini-1.5-pro-002",
"gemini-1.5-pro-exp-0801": "google/gemini-1.5-pro-exp-0801",
"gemini-1.5-pro-exp-0827": "google/gemini-1.5-pro-exp-0827",
"gemini-1.5-pro-latest": "google/gemini-1.5-pro-latest",
"gemini-2.0-flash-exp": "google/gemini-2.0-flash-exp",
"gemini-2.0-flash-thinking-exp": "google/gemini-2.0-flash-thinking-exp",
"gemini-2.0-flash-thinking-exp-1219": "google/gemini-2.0-flash-thinking-exp-1219",
"gemini-exp-1114": "google/gemini-exp-1114",
"gemini-exp-1121": "google/gemini-exp-1121",
"gemini-exp-1206": "google/gemini-exp-1206",
"gemini-pro": "google/gemini-pro",
"gemini-pro-vision": "google/gemini-pro-vision"
}
2 changes: 2 additions & 0 deletions nixos/optional-apps/uni-api/apis/openrouter.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@
"microsoft/phi-3-mini-128k-instruct": "microsoft/phi-3-mini-128k-instruct",
"microsoft/phi-3-mini-128k-instruct:free": "microsoft/phi-3-mini-128k-instruct:free",
"microsoft/phi-3.5-mini-128k-instruct": "microsoft/phi-3.5-mini-128k-instruct",
"microsoft/phi-4": "microsoft/phi-4",
"microsoft/wizardlm-2-7b": "microsoft/wizardlm-2-7b",
"microsoft/wizardlm-2-8x22b": "microsoft/wizardlm-2-8x22b",
"mistralai/codestral-mamba": "mistralai/codestral-mamba",
"mistralai/ministral-3b": "mistralai/ministral-3b",
"mistralai/ministral-8b": "mistralai/ministral-8b",
"mistralai/mistral-7b-instruct": "mistralai/mistral-7b-instruct",
"mistralai/mistral-7b-instruct-v0.1": "mistralai/mistral-7b-instruct-v0.1",
"mistralai/mistral-7b-instruct-v0.2": "mistralai/mistral-7b-instruct-v0.2",
"mistralai/mistral-7b-instruct-v0.3": "mistralai/mistral-7b-instruct-v0.3",
"mistralai/mistral-7b-instruct:free": "mistralai/mistral-7b-instruct:free",
"mistralai/mistral-7b-instruct:nitro": "mistralai/mistral-7b-instruct:nitro",
Expand Down
1 change: 1 addition & 0 deletions nixos/optional-apps/uni-api/apis/siliconflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"LoRA/Qwen/Qwen2.5-32B-Instruct": "qwen/qwen-2.5-32b-instruct:lora",
"LoRA/Qwen/Qwen2.5-72B-Instruct": "qwen/qwen-2.5-72b-instruct:lora",
"LoRA/Qwen/Qwen2.5-7B-Instruct": "qwen/qwen-2.5-7b-instruct:lora",
"LoRA/RVC-Boss/GPT-SoVITS": "rvc-boss/gpt-sovits:lora",
"LoRA/black-forest-labs/FLUX.1-dev": "black-forest-labs/flux.1-dev:lora",
"LoRA/meta-llama/Meta-Llama-3.1-8B-Instruct": "meta-llama/meta-llama-3.1-8b-instruct:lora",
"OpenGVLab/InternVL2-26B": "opengvlab/internvl-2-26b",
Expand Down
9 changes: 9 additions & 0 deletions nixos/optional-apps/uni-api/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ let
};
model = loadModels ./apis/mistral.json;
}
{
provider = "gemini";
base_url = "https://generativelanguage.googleapis.com/v1beta";
api = {
_secret = config.age.secrets.uni-api-google-api-key.path;
};
model = loadModels ./apis/google.json;
}
{
provider = "cloudflare";
api = {
Expand Down Expand Up @@ -116,6 +124,7 @@ in
"ai-985-games-api-key"
"cloudflare-account-id"
"cloudflare-api-key"
"google-api-key"
"groq-api-key"
"lingyiwanwu-api-key"
"mistral-api-key"
Expand Down
34 changes: 32 additions & 2 deletions nixos/optional-apps/uni-api/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ai-985-games": "https://ai.985.games/v1",
"cloudflare": "https://playground.ai.cloudflare.com/api",
"groq": "https://api.groq.com/openai/v1",
"google": "__GOOGLE__",
"lingyiwanwu": "https://api.lingyiwanwu.com/v1",
"mistral": "https://api.mistral.ai/v1",
"novita": "https://api.novita.ai/v3/openai",
Expand All @@ -35,7 +36,10 @@
"pixtral-",
],
"meta-llama": ["llama-"],
"google": ["gemma-"],
"google": [
"gemini-",
"gemma-",
],
"01-ai": ["yi-"],
"thudm": [
"glm-",
Expand All @@ -50,7 +54,7 @@
}


def get_models(api_name: str, base_url: str) -> List[str]:
def get_api_secret(api_name: str) -> str:
secret = subprocess.check_output(
[
"nix",
Expand All @@ -64,6 +68,32 @@ def get_models(api_name: str, base_url: str) -> List[str]:
],
text=True,
).strip()
return secret


def get_models_google(api_name: str) -> List[str]:
secret = get_api_secret(api_name)

r = urllib.request.Request(
f"https://generativelanguage.googleapis.com/v1beta/models?key={secret}",
method="GET",
headers={
"User-Agent": "lantian",
},
)
content = urllib.request.urlopen(r).read()

models = json.loads(content)
# Remove "models/" prefix
# uni-api only supports Gemini models
return [m["name"][7:] for m in models["models"] if "models/gemini" in m["name"]]


def get_models(api_name: str, base_url: str) -> List[str]:
if base_url == "__GOOGLE__":
return get_models_google(api_name)

secret = get_api_secret(api_name)

r = urllib.request.Request(
f"{base_url}/models",
Expand Down

0 comments on commit 6b9048f

Please sign in to comment.