mirror of
https://github.com/zylon-ai/private-gpt.git
synced 2025-12-22 23:22:57 +01:00
fix: when two user messages were sent
This commit is contained in:
parent
05a986231c
commit
0eb24a54ec
1 changed files with 13 additions and 16 deletions
|
|
@ -1,6 +1,4 @@
|
||||||
"""This file should be imported if and only if you want to run the UI locally."""
|
"""This file should be imported if and only if you want to run the UI locally."""
|
||||||
|
|
||||||
import itertools
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
|
|
@ -113,21 +111,20 @@ class PrivateGptUi:
|
||||||
yield full_response
|
yield full_response
|
||||||
|
|
||||||
def build_history() -> list[ChatMessage]:
|
def build_history() -> list[ChatMessage]:
|
||||||
history_messages: list[ChatMessage] = list(
|
history_messages: list[ChatMessage] = []
|
||||||
itertools.chain(
|
|
||||||
*[
|
for interaction in history:
|
||||||
[
|
history_messages.append(
|
||||||
ChatMessage(content=interaction[0], role=MessageRole.USER),
|
ChatMessage(content=interaction[0], role=MessageRole.USER)
|
||||||
ChatMessage(
|
|
||||||
# Remove from history content the Sources information
|
|
||||||
content=interaction[1].split(SOURCES_SEPARATOR)[0],
|
|
||||||
role=MessageRole.ASSISTANT,
|
|
||||||
),
|
|
||||||
]
|
|
||||||
for interaction in history
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
)
|
if len(interaction) > 1 and interaction[1] is not None:
|
||||||
|
history_messages.append(
|
||||||
|
ChatMessage(
|
||||||
|
# Remove from history content the Sources information
|
||||||
|
content=interaction[1].split(SOURCES_SEPARATOR)[0],
|
||||||
|
role=MessageRole.ASSISTANT,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# max 20 messages to try to avoid context overflow
|
# max 20 messages to try to avoid context overflow
|
||||||
return history_messages[:20]
|
return history_messages[:20]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue