abetlen / abetlen/llama-cpp-python

how to make multiple inference requests from a single model object

未關閉
#1,529 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
10.6k
分支
1.4k
PR 合併指標
PR 指標待擷取

描述

```
def generate_response_stream(_model, _messages, _max_tokens=8192):
_stream = _model.create_chat_completion(
_messages,
stop=["<|eot_id|>", "<|end_of_text|>"],
max_tokens=_max_tokens,
stream=True
)
for chunk in _stream:
if 'role' in chunk["choices"][0]['delta'].keys():
yield chunk["choices"][0]['delta']['role']+':'
elif 'content' in chunk["choices"][0]['delta'].keys():
yield chunk["choices"][0]['delta']['content']

@router.post("/llm_generator")
async def llm_post(guideIn: LLMRequest):
try:
jsonString = {**guideIn.dict()}
messages=jsonString['messages']
async with lock:
return StreamingResponse(model.generate_response_stream(messages),media_type="text/plain")
```

The service crashed after two concurrent requests were made, and there were no error messages.

![WeChatd08cc880228a9eeb1ad3da2a9ae0741e](https://github.com/abetlen/llama-cpp-python/assets/18607037/85452309-e4c8-4c7d-ba20-fa20f3c2e8e6)

problem that has been bothering me for a long time.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。