Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
62 lines (48 loc) · 2.02 KB
/
Copy path__init__.py
File metadata and controls
62 lines (48 loc) · 2.02 KB
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
from collections.abc import Callable
from typing import Any
from dotenv import load_dotenv
from rlm.clients.base_lm import BaseLM
from rlm.core.types import ClientBackend
ClientFactory = Callable[[str, dict[str, Any]], BaseLM]
load_dotenv()
def get_client(
backend: ClientBackend | str,
backend_kwargs: dict[str, Any],
) -> BaseLM:
"""
Routes a specific backend and the args (as a dict) to the appropriate client if supported.
Currently supported backends: ['openai']
"""
if backend == "openai":
from rlm.clients.openai import OpenAIClient
return OpenAIClient(**backend_kwargs)
elif backend == "vllm":
from rlm.clients.openai import OpenAIClient
assert "base_url" in backend_kwargs, (
"base_url is required to be set to local vLLM server address for vLLM"
)
return OpenAIClient(**backend_kwargs)
elif backend == "portkey":
from rlm.clients.portkey import PortkeyClient
return PortkeyClient(**backend_kwargs)
elif backend == "openrouter":
from rlm.clients.openai import OpenAIClient
backend_kwargs.setdefault("base_url", "https://openrouter.ai/api/v1")
return OpenAIClient(**backend_kwargs)
elif backend == "vercel":
from rlm.clients.openai import OpenAIClient
backend_kwargs.setdefault("base_url", "https://ai-gateway.vercel.sh/v1")
return OpenAIClient(**backend_kwargs)
elif backend == "anthropic":
from rlm.clients.anthropic import AnthropicClient
return AnthropicClient(**backend_kwargs)
elif backend == "gemini":
from rlm.clients.gemini import GeminiClient
return GeminiClient(**backend_kwargs)
elif backend == "azure_openai":
from rlm.clients.azure_openai import AzureOpenAIClient
return AzureOpenAIClient(**backend_kwargs)
else:
raise ValueError(
f"Unknown backend: {backend}. Supported backends: ['openai', 'vllm', 'portkey', 'openrouter', 'anthropic', 'azure_openai', 'gemini', 'vercel']"
)