-
Notifications
You must be signed in to change notification settings - Fork 0
/
llm_venice.py
75 lines (62 loc) · 1.99 KB
/
llm_venice.py
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
import json
import click
import httpx
import llm
from llm.default_plugins.openai_models import Chat
MODELS = (
"dolphin-2.9.2-qwen2-72b",
"llama-3.1-405b",
"llama-3.2-3b",
"llama-3.3-70b",
"nous-hermes3a",
"nous-theta-8b",
"qwen32b",
)
class VeniceChat(Chat):
needs_key = "venice"
key_env_var = "LLM_VENICE_KEY"
def __str__(self):
return f"Venice Chat: {self.model_id}"
@llm.hookimpl
def register_commands(cli):
@cli.group(name="venice")
def venice():
"llm-venice plugin commands"
@venice.command(name="refresh")
def refresh():
"Refresh the list of models from the Venice API"
key = llm.get_key("", "venice", "LLM_VENICE_KEY")
if not key:
raise click.ClickException("No key found for Venice")
headers = {"Authorization": f"Bearer {key}"}
response = httpx.get(
"https://api.venice.ai/api/v1/models", headers=headers
)
response.raise_for_status()
models = response.json()["data"]
text_models = [model["id"] for model in models if model.get("type") == "text"]
if not text_models:
raise click.ClickException("No text generation models found")
path = llm.user_dir() / "llm-venice.json"
path.write_text(json.dumps(text_models, indent=4))
click.echo(f"{len(text_models)} models saved to {path}", err=True)
click.echo(json.dumps(text_models, indent=4))
@llm.hookimpl
def register_models(register):
key = llm.get_key("", "venice", "LLM_VENICE_KEY")
if not key:
return
path = llm.user_dir() / "llm-venice.json"
if path.exists():
model_ids = json.loads(path.read_text())
else:
model_ids = MODELS
for model_id in model_ids:
register(
VeniceChat(
model_id=f"venice/{model_id}",
model_name=model_id,
api_base="https://api.venice.ai/api/v1",
can_stream=False
)
)