Skip to content

Observation #23

@AymanBx

Description

@AymanBx

def summarize_observation(self, action, observation, log_file, bs = 10000):
""" Summarize the observation if it is too long with a sliding window of size bs """
bs = 10000
blocks = [observation[i:i+bs] for i in range(0, len(observation), bs)]
descriptions = []
for idx, b in enumerate(blocks):
start_line_number = bs*idx+1
end_line_number = bs*idx+1 + len(b)
prompt = f"""
{action}
The full observation is too long. Given this (partial) observation from character {start_line_number} to character {end_line_number}:
```
{b}
```
Summarize the observation concisely in this format:
[Observation]: Summarize all relevant details in the observation objectively
Do not include any result that is guessed rather than directly confirmed by the observation. Do not include additional information or suggestions.
"""
completion = complete_text_fast(prompt, log_file=log_file +f"_{idx}")
descriptions.append(completion)
if len(descriptions) == 1:
completion = descriptions[0]
else:
descriptions = "\n\n".join(["Segment {idx}: \n\n" + s for s in descriptions])
prompt = f"""
{action}
The full observation is too long.
Given summaries for each segments of the whole observation, summarize to get a cohesive description of the entire observation.
{descriptions}
Summarize the observation concisely in this format:
[Observation]: Summarize all relevant details in the observation objectively
Do not include any result that is guessed rather than directly confirmed by the observation. Do not include additional information or suggestions.
"""
completion = complete_text_fast(prompt, log_file=log_file)
try:
return completion.split("[Observation]:")[1]
except:
return completion

If we use "Observation" in the stop sequence then we lose summarization. We can either change "Observation" to "Summary" in the prompt here or remove the word "Observation" from the stop sequence.

Similarly, the word "Observation" is used in the retrieval step prompt... (The next function)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions