fix: aislamiento estricto de conversaciones de chat por usuario e inferencia simultanea (v3.8.26)
This commit is contained in:
@@ -160,10 +160,20 @@ async def get_agent_response(
|
||||
for msg in request.messages:
|
||||
formatted_messages.append({"role": msg.role, "content": msg.content})
|
||||
|
||||
# Identificador individual único de usuario / sesión para aislar los slots de KV Cache en Llama.cpp
|
||||
if current_user and getattr(current_user, "id", None):
|
||||
user_identifier = f"usr_{current_user.id}"
|
||||
elif request.conversation_id:
|
||||
user_identifier = str(request.conversation_id).strip()
|
||||
else:
|
||||
client_ip = req.client.host if (req and req.client) else "local"
|
||||
user_identifier = f"anon_{client_ip}"
|
||||
|
||||
payload = {
|
||||
"model": config["model"],
|
||||
"messages": formatted_messages,
|
||||
"temperature": 0.1 # Temperatura estricta para evitar alucinaciones
|
||||
"temperature": 0.1, # Temperatura estricta para evitar alucinaciones
|
||||
"user": user_identifier # Aislamiento individual por usuario en Llama.cpp
|
||||
}
|
||||
|
||||
target_url = f"{config['base_url']}/chat/completions"
|
||||
@@ -180,7 +190,11 @@ async def get_agent_response(
|
||||
ai_data = response.json()
|
||||
raw_reply = ai_data["choices"][0]["message"]["content"]
|
||||
clean_reply, options = _extract_options_from_reply(raw_reply, effective_role)
|
||||
return ChatResponse(response=clean_reply, quick_options=options)
|
||||
return ChatResponse(
|
||||
response=clean_reply,
|
||||
quick_options=options,
|
||||
conversation_id=user_identifier
|
||||
)
|
||||
except httpx.TimeoutException:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_504_GATEWAY_TIMEOUT,
|
||||
|
||||
Reference in New Issue
Block a user