Skip to content

Commit 679f7d0

Browse files
Add llm completions custom timeout (#156)
* add llm completions timeout * add configurable timeout
1 parent 214ab44 commit 679f7d0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

launch/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
from launch.request_validation import validate_task_request
161161

162162
DEFAULT_NETWORK_TIMEOUT_SEC = 120
163+
DEFAULT_LLM_COMPLETIONS_TIMEOUT = 300
163164

164165
logger = logging.getLogger(__name__)
165166
logging.basicConfig()
@@ -2911,6 +2912,7 @@ def completions_sync(
29112912
temperature: float,
29122913
stop_sequences: Optional[List[str]] = None,
29132914
return_token_log_probs: Optional[bool] = False,
2915+
timeout: float = DEFAULT_LLM_COMPLETIONS_TIMEOUT,
29142916
) -> CompletionSyncV1Response:
29152917
"""
29162918
Run prompt completion on a sync LLM endpoint. Will fail if the endpoint is not sync.
@@ -2945,6 +2947,7 @@ def completions_sync(
29452947
body=request,
29462948
query_params=query_params,
29472949
skip_deserialization=True,
2950+
timeout=timeout,
29482951
)
29492952
resp = json.loads(response.response.data)
29502953
return resp
@@ -2957,6 +2960,7 @@ def completions_stream(
29572960
temperature: float,
29582961
stop_sequences: Optional[List[str]] = None,
29592962
return_token_log_probs: Optional[bool] = False,
2963+
timeout: float = DEFAULT_LLM_COMPLETIONS_TIMEOUT,
29602964
) -> Iterable[CompletionStreamV1Response]:
29612965
"""
29622966
Run prompt completion on an LLM endpoint in streaming fashion. Will fail if endpoint does not support streaming.
@@ -2989,6 +2993,7 @@ def completions_stream(
29892993
json=request,
29902994
auth=(self.configuration.username, self.configuration.password),
29912995
stream=True,
2996+
timeout=timeout,
29922997
)
29932998
sse_client = sseclient.SSEClient(response)
29942999
events = sse_client.events()

0 commit comments

Comments
 (0)