Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better parser for step call #18

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions notte/common/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ def step(self, text: str) -> EnvStepParams:
if action is None or not isinstance(action, str):
raise ValueError("No action found")
d = json.loads(action)
action_id = list(d.keys())[0]
params = d[action_id] if d[action_id] != {} else None
if "action-id" not in d:
raise ValueError("No action-id found in action")
action_id = d["action-id"]
params = d["params"] if d["params"] is not None else None
return EnvStepParams(action_id=action_id, params=params)

@override
Expand All @@ -111,8 +113,8 @@ def textify(self, obs: Observation) -> str:
Use the exact following format:
<action>
{
"action-id": {} # if an action has no params
"action-id": { "name":"value" } # for action with params
"action-id": "<YOUR_ACTION_ID>",
"params": { "<YOUR_PARAM_NAME>": "<YOUR_PARAM_VALUE>" }
}
</action>
\nIf you're done, just say <done/>. Nothing else!
Expand Down
2 changes: 1 addition & 1 deletion notte/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def chat(self, text: str) -> str:
return self._parser.textify(obs)
elif endpoint == "step":
step_params = self._parser.step(text)
obs = await self.step(step_params.action_id, step_params.params, enter=False)
obs = await self.step(step_params.action_id, step_params.params)
return self._parser.textify(obs)
return self._parser.rules()

Expand Down
Loading