refactor: extract get_most_recent_id
This commit is contained in:
parent
b3010bb649
commit
909825bf1b
|
|
@ -48,9 +48,7 @@ def delete_key_facts(fact_ids: List[int]) -> str:
|
||||||
# Try to get the current human input to protect its facts
|
# Try to get the current human input to protect its facts
|
||||||
current_human_input_id = None
|
current_human_input_id = None
|
||||||
try:
|
try:
|
||||||
recent_inputs = get_human_input_repository().get_recent(1)
|
current_human_input_id = get_human_input_repository().get_most_recent_id()
|
||||||
if recent_inputs and len(recent_inputs) > 0:
|
|
||||||
current_human_input_id = recent_inputs[0].id
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
||||||
|
|
||||||
|
|
@ -133,9 +131,7 @@ def run_key_facts_gc_agent() -> None:
|
||||||
# Try to get the current human input ID to exclude its facts
|
# Try to get the current human input ID to exclude its facts
|
||||||
current_human_input_id = None
|
current_human_input_id = None
|
||||||
try:
|
try:
|
||||||
recent_inputs = get_human_input_repository().get_recent(1)
|
current_human_input_id = get_human_input_repository().get_most_recent_id()
|
||||||
if recent_inputs and len(recent_inputs) > 0:
|
|
||||||
current_human_input_id = recent_inputs[0].id
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,7 @@ def delete_key_snippets(snippet_ids: List[int]) -> str:
|
||||||
# Try to get the current human input to protect its snippets
|
# Try to get the current human input to protect its snippets
|
||||||
current_human_input_id = None
|
current_human_input_id = None
|
||||||
try:
|
try:
|
||||||
recent_inputs = get_human_input_repository().get_recent(1)
|
current_human_input_id = get_human_input_repository().get_most_recent_id()
|
||||||
if recent_inputs and len(recent_inputs) > 0:
|
|
||||||
current_human_input_id = recent_inputs[0].id
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
||||||
|
|
||||||
|
|
@ -125,9 +123,7 @@ def run_key_snippets_gc_agent() -> None:
|
||||||
# Try to get the current human input ID to exclude its snippets
|
# Try to get the current human input ID to exclude its snippets
|
||||||
current_human_input_id = None
|
current_human_input_id = None
|
||||||
try:
|
try:
|
||||||
recent_inputs = get_human_input_repository().get_recent(1)
|
current_human_input_id = get_human_input_repository().get_most_recent_id()
|
||||||
if recent_inputs and len(recent_inputs) > 0:
|
|
||||||
current_human_input_id = recent_inputs[0].id
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,12 +109,14 @@ def run_research_agent(
|
||||||
base_task = base_task_or_query
|
base_task = base_task_or_query
|
||||||
try:
|
try:
|
||||||
human_input_repository = get_human_input_repository()
|
human_input_repository = get_human_input_repository()
|
||||||
recent_inputs = human_input_repository.get_recent(1)
|
most_recent_id = human_input_repository.get_most_recent_id()
|
||||||
if recent_inputs and len(recent_inputs) > 0 and recent_inputs[0].content != base_task_or_query:
|
if most_recent_id is not None:
|
||||||
last_human_input = recent_inputs[0].content
|
recent_input = human_input_repository.get(most_recent_id)
|
||||||
base_task = (
|
if recent_input and recent_input.content != base_task_or_query:
|
||||||
f"<last human input>{last_human_input}</last human input>\n{base_task}"
|
last_human_input = recent_input.content
|
||||||
)
|
base_task = (
|
||||||
|
f"<last human input>{last_human_input}</last human input>\n{base_task}"
|
||||||
|
)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
logger.error(f"Failed to access human input repository: {str(e)}")
|
logger.error(f"Failed to access human input repository: {str(e)}")
|
||||||
# Continue without appending last human input
|
# Continue without appending last human input
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,7 @@ def delete_research_notes(note_ids: List[int]) -> str:
|
||||||
# Try to get the current human input to protect its notes
|
# Try to get the current human input to protect its notes
|
||||||
current_human_input_id = None
|
current_human_input_id = None
|
||||||
try:
|
try:
|
||||||
recent_inputs = get_human_input_repository().get_recent(1)
|
current_human_input_id = get_human_input_repository().get_most_recent_id()
|
||||||
if recent_inputs and len(recent_inputs) > 0:
|
|
||||||
current_human_input_id = recent_inputs[0].id
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
||||||
|
|
||||||
|
|
@ -138,9 +136,7 @@ def run_research_notes_gc_agent(threshold: int = 30) -> None:
|
||||||
# Try to get the current human input ID to exclude its notes
|
# Try to get the current human input ID to exclude its notes
|
||||||
current_human_input_id = None
|
current_human_input_id = None
|
||||||
try:
|
try:
|
||||||
recent_inputs = get_human_input_repository().get_recent(1)
|
current_human_input_id = get_human_input_repository().get_most_recent_id()
|
||||||
if recent_inputs and len(recent_inputs) > 0:
|
|
||||||
current_human_input_id = recent_inputs[0].id
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
console.print(f"Warning: Could not retrieve current human input: {str(e)}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,25 @@ class HumanInputRepository:
|
||||||
logger.error(f"Failed to fetch recent human inputs: {str(e)}")
|
logger.error(f"Failed to fetch recent human inputs: {str(e)}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def get_most_recent_id(self) -> Optional[int]:
|
||||||
|
"""
|
||||||
|
Get the ID of the most recent human input record.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Optional[int]: The ID of the most recent human input, or None if no records exist
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
peewee.DatabaseError: If there's an error accessing the database
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
recent_inputs = self.get_recent(1)
|
||||||
|
if recent_inputs and len(recent_inputs) > 0:
|
||||||
|
return recent_inputs[0].id
|
||||||
|
return None
|
||||||
|
except peewee.DatabaseError as e:
|
||||||
|
logger.error(f"Failed to fetch most recent human input ID: {str(e)}")
|
||||||
|
raise
|
||||||
|
|
||||||
def get_by_source(self, source: str) -> List[HumanInput]:
|
def get_by_source(self, source: str) -> List[HumanInput]:
|
||||||
"""
|
"""
|
||||||
Retrieve human input records by source.
|
Retrieve human input records by source.
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,7 @@ def emit_research_notes(notes: str) -> str:
|
||||||
human_input_id = None
|
human_input_id = None
|
||||||
try:
|
try:
|
||||||
human_input_repo = get_human_input_repository()
|
human_input_repo = get_human_input_repository()
|
||||||
recent_inputs = human_input_repo.get_recent(1)
|
human_input_id = human_input_repo.get_most_recent_id()
|
||||||
if recent_inputs and len(recent_inputs) > 0:
|
|
||||||
human_input_id = recent_inputs[0].id
|
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
logger.warning(f"No HumanInputRepository available: {str(e)}")
|
logger.warning(f"No HumanInputRepository available: {str(e)}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -109,9 +107,7 @@ def emit_key_facts(facts: List[str]) -> str:
|
||||||
human_input_id = None
|
human_input_id = None
|
||||||
try:
|
try:
|
||||||
human_input_repo = get_human_input_repository()
|
human_input_repo = get_human_input_repository()
|
||||||
recent_inputs = human_input_repo.get_recent(1)
|
human_input_id = human_input_repo.get_most_recent_id()
|
||||||
if recent_inputs and len(recent_inputs) > 0:
|
|
||||||
human_input_id = recent_inputs[0].id
|
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
logger.warning(f"No HumanInputRepository available: {str(e)}")
|
logger.warning(f"No HumanInputRepository available: {str(e)}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -186,9 +182,7 @@ def emit_key_snippet(snippet_info: SnippetInfo) -> str:
|
||||||
human_input_id = None
|
human_input_id = None
|
||||||
try:
|
try:
|
||||||
human_input_repo = get_human_input_repository()
|
human_input_repo = get_human_input_repository()
|
||||||
recent_inputs = human_input_repo.get_recent(1)
|
human_input_id = human_input_repo.get_most_recent_id()
|
||||||
if recent_inputs and len(recent_inputs) > 0:
|
|
||||||
human_input_id = recent_inputs[0].id
|
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
logger.warning(f"No HumanInputRepository available: {str(e)}")
|
logger.warning(f"No HumanInputRepository available: {str(e)}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue