Reimplement methods required for triton streaming

This commit is contained in:
Minwoo Lee 2025-02-08 12:31:01 +09:00 • committed by GitHub
parent b3de3216a8
commit 0c30909fe9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,7 +3,7 @@ Translates from OpenAI's `/v1/chat/completions` endpoint to Triton's `/generate`
"""
import json
from typing import Any, Dict, List, Literal, Optional, Union
from typing import Any, AsyncIterator, Dict, Iterator, List, Literal, Optional, Union
from httpx import Headers, Response
@ -52,6 +52,17 @@ class TritonConfig(BaseConfig):
) -> Dict:
return {"Content-Type": "application/json"}
def get_complete_url(
self,
api_base: str,
model: str,
optional_params: dict,
stream: Optional[bool] = None,
) -> str:
if stream:
return api_base + "_stream"
return api_base
def get_supported_openai_params(self, model: str) -> List:
return ["max_tokens", "max_completion_tokens"]
@ -149,6 +160,18 @@ class TritonConfig(BaseConfig):
else:
raise ValueError(f"Invalid Triton API base: {api_base}")
def get_model_response_iterator(
self,
streaming_response: Union[Iterator[str], AsyncIterator[str], ModelResponse],
sync_stream: bool,
json_mode: Optional[bool] = False,
) -> Any:
return TritonResponseIterator(
streaming_response=streaming_response,
sync_stream=sync_stream,
json_mode=json_mode,
)
class TritonGenerateConfig(TritonConfig):
"""