abetlen / abetlen/llama-cpp-python

how to make multiple inference requests from a single model object

Ouverte
#1,529 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Python
Étoiles
10.6k
Forks
1.4k
Métriques de merge des PR
Métriques de PR en attente

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.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.