abetlen / abetlen/llama-cpp-python

how to make multiple inference requests from a single model object

Open
#1,529 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
10.6k
Forks
1.4k
PR merge metrics
PR metrics pending

Description

```
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.