mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-14 09:18:04 -05:00
* Replace OpenDevin with OpenHands * Update CONTRIBUTING.md * Update README.md * Update README.md * update poetry lock; move opendevin folder to openhands * fix env var * revert image references in docs * revert permissions * revert permissions --------- Co-authored-by: Xingyao Wang <xingyao6@illinois.edu>
25 lines
926 B
Python
25 lines
926 B
Python
from openhands.core.logger import openhands_logger as logger
|
|
from openhands.llm.llm import LLM
|
|
|
|
|
|
class MemoryCondenser:
|
|
def condense(self, summarize_prompt: str, llm: LLM):
|
|
"""Attempts to condense the memory by using the llm
|
|
|
|
Parameters:
|
|
- llm (LLM): llm to be used for summarization
|
|
|
|
Raises:
|
|
- Exception: the same exception as it got from the llm or processing the response
|
|
"""
|
|
try:
|
|
messages = [{'content': summarize_prompt, 'role': 'user'}]
|
|
resp = llm.completion(messages=messages)
|
|
summary_response = resp['choices'][0]['message']['content']
|
|
return summary_response
|
|
except Exception as e:
|
|
logger.error('Error condensing thoughts: %s', str(e), exc_info=False)
|
|
|
|
# TODO If the llm fails with ContextWindowExceededError, we can try to condense the memory chunk by chunk
|
|
raise
|