(
request: Request,
inner_send_chan: MemoryObjectSendStream[typing.Any],
body: CreateCompletionRequest | CreateChatCompletionRequest,
body_model: str | None,
llama_call,
kwargs,
)
| 189 | |
| 190 | |
| 191 | async def get_event_publisher( |
| 192 | request: Request, |
| 193 | inner_send_chan: MemoryObjectSendStream[typing.Any], |
| 194 | body: CreateCompletionRequest | CreateChatCompletionRequest, |
| 195 | body_model: str | None, |
| 196 | llama_call, |
| 197 | kwargs, |
| 198 | ): |
| 199 | server_settings = next(get_server_settings()) |
| 200 | interrupt_requests = ( |
| 201 | server_settings.interrupt_requests if server_settings else False |
| 202 | ) |
| 203 | async with contextlib.asynccontextmanager(get_llama_proxy)() as llama_proxy: |
| 204 | llama = prepare_request_resources(body, llama_proxy, body_model, kwargs) |
| 205 | async with inner_send_chan: |
| 206 | try: |
| 207 | iterator = await run_in_threadpool(llama_call, llama, **kwargs) |
| 208 | async for chunk in iterate_in_threadpool(iterator): |
| 209 | await inner_send_chan.send(dict(data=json.dumps(chunk))) |
| 210 | if await request.is_disconnected(): |
| 211 | raise anyio.get_cancelled_exc_class()() |
| 212 | if interrupt_requests and llama_outer_lock.locked(): |
| 213 | await inner_send_chan.send(dict(data="[DONE]")) |
| 214 | raise anyio.get_cancelled_exc_class()() |
| 215 | await inner_send_chan.send(dict(data="[DONE]")) |
| 216 | except anyio.get_cancelled_exc_class() as e: |
| 217 | print("disconnected") |
| 218 | with anyio.move_on_after(1, shield=True): |
| 219 | print( |
| 220 | f"Disconnected from client (via refresh/close) {request.client}" |
| 221 | ) |
| 222 | raise e |
| 223 | |
| 224 | |
| 225 | def _logit_bias_tokens_to_input_ids( |
nothing calls this directly
no test coverage detected
searching dependent graphs…