Skip to content

Commit 6196e2d

Browse files
DH-5557add truncation
1 parent 694d7c5 commit 6196e2d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

dataherald/sql_generator/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,18 @@ def construct_intermediate_steps(
127127
thought=str(step[0].log).split("Action:")[0],
128128
action=step[0].tool,
129129
action_input=step[0].tool_input,
130-
observation=step[1],
130+
observation=self.truncate_observations(step[1]),
131131
)
132132
)
133133
formatted_intermediate_steps[0].thought = suffix.split("Thought: ")[1].split(
134134
"{agent_scratchpad}"
135135
)[0]
136136
return formatted_intermediate_steps
137137

138+
def truncate_observations(self, obervarion: str, max_length: int = 2000) -> str:
139+
"""Truncate the tool input."""
140+
return obervarion[:max_length] + "... (truncated)" if len(obervarion) > max_length else obervarion
141+
138142
@abstractmethod
139143
def generate_response(
140144
self,

0 commit comments

Comments
 (0)