abetlen / abetlen/llama-cpp-python
how to make multiple inference requests from a single model object
- 主要語言
- 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.

problem that has been bothering me for a long time.
貢獻指南
評估
這個 Issue 還沒有評估資料。