mirror of
https://github.com/Pythagora-io/gpt-pilot.git
synced 2026-01-09 21:27:53 -05:00
Fix for trimming bh and breakdown chat messages
This commit is contained in:
@@ -8,6 +8,7 @@ from core.agents.convo import AgentConvo
|
||||
from core.agents.mixins import ChatWithBreakdownMixin, TestSteps
|
||||
from core.agents.response import AgentResponse
|
||||
from core.config import CHECK_LOGS_AGENT_NAME, magic_words
|
||||
from core.config.constants import CONVO_ITERATIONS_LIMIT
|
||||
from core.db.models.project_state import IterationStatus
|
||||
from core.llm.parser import JSONParser
|
||||
from core.log import get_logger
|
||||
@@ -261,8 +262,8 @@ class BugHunter(ChatWithBreakdownMixin, BaseAgent):
|
||||
# TODO: remove when Leon checks
|
||||
convo.remove_last_x_messages(2)
|
||||
|
||||
if len(convo.messages) > 8:
|
||||
convo.trim(1, 2)
|
||||
if len(convo.messages) > CONVO_ITERATIONS_LIMIT:
|
||||
convo.slice(1, CONVO_ITERATIONS_LIMIT)
|
||||
|
||||
# TODO: in the future improve with a separate conversation that parses the user info and goes into an appropriate if statement
|
||||
if next_step.button == "done":
|
||||
@@ -341,8 +342,8 @@ class BugHunter(ChatWithBreakdownMixin, BaseAgent):
|
||||
user_feedback=hunting_cycle.get("user_feedback"),
|
||||
)
|
||||
|
||||
if len(convo.messages) > 8:
|
||||
convo.trim(1, 2)
|
||||
if len(convo.messages) > CONVO_ITERATIONS_LIMIT:
|
||||
convo.slice(1, CONVO_ITERATIONS_LIMIT)
|
||||
|
||||
return convo
|
||||
|
||||
|
||||
@@ -97,6 +97,18 @@ class AgentConvo(Convo):
|
||||
self.messages = self.messages[:trim_index] + self.messages[trim_index + trim_count :]
|
||||
return self
|
||||
|
||||
def slice(self, slice_index: int, slice_count: int) -> "AgentConvo":
|
||||
"""
|
||||
Create a new conversation containing messages from slice_index to the end, excluding slice_count messages.
|
||||
|
||||
:param slice_index: Starting index to slice from
|
||||
:param slice_count: Number of messages to exclude from the end
|
||||
:return: self for method chaining
|
||||
"""
|
||||
end_index = max(slice_index, len(self.messages) - slice_count)
|
||||
self.messages = self.messages[:slice_index] + self.messages[end_index:]
|
||||
return self
|
||||
|
||||
def require_schema(self, model: BaseModel) -> "AgentConvo":
|
||||
def remove_defs(d):
|
||||
if isinstance(d, dict):
|
||||
|
||||
@@ -7,6 +7,7 @@ from pydantic import BaseModel, Field
|
||||
from core.agents.convo import AgentConvo
|
||||
from core.agents.response import AgentResponse
|
||||
from core.config import GET_RELEVANT_FILES_AGENT_NAME, TASK_BREAKDOWN_AGENT_NAME, TROUBLESHOOTER_BUG_REPORT
|
||||
from core.config.constants import CONVO_ITERATIONS_LIMIT
|
||||
from core.llm.parser import JSONParser
|
||||
from core.log import get_logger
|
||||
from core.ui.base import ProjectStage
|
||||
@@ -82,8 +83,8 @@ class ChatWithBreakdownMixin:
|
||||
if chat.button == "yes":
|
||||
break
|
||||
|
||||
if len(convo.messages) > 11:
|
||||
convo.trim(3, 2)
|
||||
if len(convo.messages) > CONVO_ITERATIONS_LIMIT:
|
||||
convo.slice(3, CONVO_ITERATIONS_LIMIT)
|
||||
|
||||
convo.user(chat.text)
|
||||
breakdown: str = await llm(convo)
|
||||
|
||||
Reference in New Issue
Block a user