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

Parse response of demo agent #305

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion demo_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def image_to_jpg_base64_url(image: np.ndarray | Image.Image):

return f"data:image/jpeg;base64,{image_base64}"

def extract_code_blocks(text) -> list[tuple[str, str]]:
pattern = re.compile(r"```(\w*\n)?(.*?)```", re.DOTALL)

matches = pattern.findall(text)
return [(match[0].strip(), match[1].strip()) for match in matches]

class DemoAgent(Agent):
"""A basic agent using OpenAI API, to demonstrate BrowserGym's functionalities."""
Expand Down Expand Up @@ -322,7 +327,7 @@ def get_action(self, obs: dict) -> tuple[str, dict]:
{"role": "user", "content": user_msgs},
],
)
action = response.choices[0].message.content
action = extract_code_blocks(response.choices[0].message.content)[1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried this? The new extract_code_blocks() function returns a list of tuples, but action is expected to be a string


self.action_history.append(action)

Expand Down
Loading