Skip to content

Commit 35c49ca

Browse files
author
Paweł Kędzia
committed
Use chat endpoint for completions across Ollama, OpenAI, and vllm; add get_proper_endpoint helper in dispatcher; remove vllm from builtin OpenAI API types.
1 parent c52711e commit 35c49ca

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

llm_router_api/core/api_types/dispatcher.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ def _get_impl(cls, api_type: str) -> ApiTypesI:
103103
)
104104
return impl()
105105

106+
def get_proper_endpoint(self, api_type: str, endpoint_url: str) -> str:
107+
endpoint_url = endpoint_url.strip("/")
108+
if endpoint_url in ["chat/completions", "api/chat/completions"]:
109+
return self.chat_ep(api_type=api_type)
110+
111+
return self.completions_ep(api_type=api_type)
112+
106113
@classmethod
107114
def chat_ep(cls, api_type: str) -> str:
108115
"""

llm_router_api/core/api_types/ollama.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def chat_method(self) -> str:
1818
return "POST"
1919

2020
def completions_ep(self) -> str:
21-
return "/api/generate"
21+
return self.chat_ep()
2222

2323
def completions_method(self) -> str:
2424
return "POST"

llm_router_api/core/api_types/openai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def chat_method(self) -> str:
3535
return "POST"
3636

3737
def completions_ep(self) -> str:
38-
return "/v1/completions"
38+
return self.chat_ep()
3939

4040
def completions_method(self) -> str:
4141
return "POST"

llm_router_api/core/api_types/vllm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def chat_method(self) -> str:
1717
return "POST"
1818

1919
def completions_ep(self) -> str:
20-
return "/v1/completions"
20+
return self.chat_ep()
2121

2222
def completions_method(self) -> str:
2323
return "POST"

llm_router_api/endpoints/builtin/openai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(
8080
prompt_handler=prompt_handler,
8181
model_handler=model_handler,
8282
dont_add_api_prefix=True,
83-
api_types=["openai", "lmstudio", "vllm"],
83+
api_types=["openai", "lmstudio"],
8484
direct_return=direct_return,
8585
method="POST",
8686
)

0 commit comments

Comments
 (0)