condenser.py 945 B

1234567891011121314151617181920212223242526
  1. from opendevin.core.logger import opendevin_logger as logger
  2. from opendevin.llm.llm import LLM
  3. class MemoryCondenser:
  4. def condense(self, summarize_prompt: str, llm: LLM):
  5. """
  6. Attempts to condense the monologue by using the llm
  7. Parameters:
  8. - llm (LLM): llm to be used for summarization
  9. Raises:
  10. - Exception: the same exception as it got from the llm or processing the response
  11. """
  12. try:
  13. messages = [{'content': summarize_prompt, 'role': 'user'}]
  14. resp = llm.do_completion(messages=messages)
  15. summary_response = resp['choices'][0]['message']['content']
  16. return summary_response
  17. except Exception as e:
  18. logger.error('Error condensing thoughts: %s', str(e), exc_info=False)
  19. # TODO If the llm fails with ContextWindowExceededError, we can try to condense the monologue chunk by chunk
  20. raise