class ShopAgent(object):
    def __init__(self):
        super().__init__()

    def forward(self, observation, available_actions):
        if available_actions['has_search_bar']:
            action = 'search[shoes]'
        else:
            action_arg = random.choice(available_actions['clickables'])
            action = f'click[{action_arg}]'
        return action


import os
import sys
import json
import random
import argparse
from concurrent.futures import ThreadPoolExecutor
import time

from web_run.web_env import webshopEnv
from web_run.llms import get_llm_backend, OPENAI_CHAT_MODELS, OPENAI_LLM_MODELS
from web_run.multi_agent_arch import SearchAgent, ClickAgent, ControlAgent
import web_run.agent_arch as agent_arch
from web_run.utils import session_save, get_instruction, get_env_botton
from web_run.evaluate import get_file_sess_idx
from web_run.config import available_agent_names

parser = argparse.ArgumentParser(description='Parsing the input of agents, llms and llm context length.')
parser.add_argument("--agent_name", type=str, help="Name of the agent.", default="React")
parser.add_argument("--llm_name", type=str, help="Name of the llm", default="gpt-3.5-turbo")
parser.add_argument("--max_context_len", type=int, help="Maximum context length", default=1700)
args = parser.parse_args()


import os
import argparse
import numpy as np
import pandas as pd
import concurrent
import joblib
from hotpotqa_run.utils import summarize_trial_detailed, log_trial
import hotpotqa_run.utils as utils
from hotpotqa_run.agent_arch import get_agent
from hotpotqa_run.llms import get_llm_backend
from hotpotqa_run.config import available_agent_names

parser = argparse.ArgumentParser(description='Parsing the input of agents, llms and llm context length.')
parser.add_argument("--agent_name", type=str, help="Name of the agent.", default="React")
parser.add_argument("--llm_name", type=str, help="Name of the llm", default="gpt-3.5-turbo")
parser.add_argument("--max_context_len", type=int, help="Maximum context length", default=1700)
args = parser.parse_args()

agent_name = args.agent_name
llm_name = args.llm_name


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

available_agent_names = ["Zeroshot_Webrun_Agent","ZeroshotThink_Webrun_Agent",
                         "React_Webrun_Agent","Planner_Webrun_Agent",
                         "PlannerReact_Webrun_Agent","Search_Click_Control_Webrun_Agent"]
OPENAI_API_KEY = ""


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

import random
import re
import json
import time
import os
import tiktoken
import web_run.pre_prompt as pre_prompt
from web_run.utils import get_query
from web_run.llms import token_enc

class BaseAgent(object):
    def __init__(self, llm, context_len=2000):
        self.type = "Base_Webrun_Agent"


import requests
from bs4 import BeautifulSoup
from bs4.element import Comment

WEBSHOP_URL = "http://127.0.0.1:3000"
ACTION_TO_TEMPLATE = {
    'Description': 'description_page.html',
    'Features': 'features_page.html',
    'Reviews': 'review_page.html',
    'Attributes': 'attributes_page.html',
}
MAX_PRO_OB = 8

def clean_str(p):
  return p.encode().decode("unicode-escape").encode("latin1").decode("utf-8")

def tag_visible(element):
    ignore = {'style', 'script', 'head', 'title', 'meta', '[document]'}
    return (
        element.parent.name not in ignore and not isinstance(element, Comment)


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

import json
import re

def obser_parser(observation, instruction_text):
    obs = observation.encode().decode("unicode-escape").encode("latin1").decode("utf-8")
    # obs = obs.replace("[SEP]",'|')
    obs = obs.replace("[button]","[")
    obs = obs.replace("[button_]","]")
    if obs.startswith('Instruction:'):
        obs = obs.replace(instruction_text,"")
        obs = obs.replace('Instruction:',"")
    if obs.startswith('You have clicked'):
        obs = obs.split('\n')[0]
    obs = obs.lstrip()


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

import time
import os
import web_run.pre_prompt as pre_prompt
from web_run.utils import get_query
from web_run.llms import token_enc

control_dict = {"Search_Webrun_Agent":"search",
                "Think_Webrun_Agent":"think",
                "Click_Webrun_Agent":"click"}

class ClickAgent:
    def __init__(self, llm, context_len=2000):
        self.type = "Click_Webrun_Agent"


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

zeroshot = """Following the instruction to simulate the web shopping. Based on your observation, you may operate one of the following actions
search: using this action to search products.
click: click observed [button], the clickable buttons are in [], for example click [Back to Search] can return back to research.
Use your best knowledge and take actions. You response should follow action[detail] format, such as search[3 ounce bright citrus deodorant sensitive skin], click[B078GWRC1J], click[bright citrus].
"""

zeroshot_think = """You are simulating web shopping. Based on your observation, you may operate one of the following actions:
search: using this action to search products.
think: using this action to plan your actions and reasoning.
click: using this action to click observed [button], the clickable buttons are in [], for example click [Back to Search] can return back to research.
Use your best knowledge and take actions. You response should follow action[detail] format, such as search[3 ounce bright citrus deodorant sensitive skin], think[B078GWRC1J and B078GTKVXY are bright citrus deodorant less then 50 dollars. I can check B078GWRC1J first.], click[B078GWRC1J], click[bright citrus].
"""

oneshot = """Webshop


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

import json
import os
import re
from collections import defaultdict
from web_run.config import available_agent_names

def get_complexity(ins_attr_file="../webshop/data/items_human_ins_new.json"):
    with open(ins_attr_file) as f:
        human_attr = json.load(f)
    complexity_dict = {}
    for asin in human_attr:
        for ins in human_attr[asin]:
            instruction = ins["instruction"]
            attribute_complexity = len(ins["instruction_attributes"])


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

import os
import sys
import json
import random
import tiktoken
token_enc = tiktoken.get_encoding("cl100k_base")
import openai
from langchain import PromptTemplate, OpenAI, LLMChain
from transformers import AutoTokenizer, AutoModelForCausalLM
from langchain.chat_models import ChatOpenAI
from langchain.chains import LLMChain
from langchain import PromptTemplate
from langchain.prompts.chat import (
    ChatPromptTemplate,


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

available_agent_names = ["Zeroshot_HotPotQA_run_Agent","ZeroshotThink_HotPotQA_run_Agent","React_HotPotQA_run_Agent","Planner_HotPotQA_run_Agent","PlannerReact_HotPotQA_run_Agent"]
OPENAI_API_KEY = ""


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

import ast
import json
import time
import gym
import requests
from bs4 import BeautifulSoup

# import wikipedia

def clean_str(p):
  return p.encode().decode("unicode-escape").encode("latin1").decode("utf-8")

class textSpace(gym.spaces.Space):


import wikienv, wrappers

def step(env, action):
    attempts = 0
    while attempts < 10:
        try:
            return env.step(action)
        except requests.exceptions.Timeout:
            attempts += 1

class HotPotQAEnv:
  def __init__(self, n_tasks=100):
    self.n_tasks = n_tasks
    self.sessions = {}
    env = wikienv.WikiEnv()
    env = wrappers.HotPotQAWrapper(env, split="dev")
    env = wrappers.LoggingWrapper(env)
    for idx in range(self.n_tasks):
      self.sessions[idx] = {'session': idx,
                            'question': question = env.reset(idx=idx)
                            }


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

import random
import re, string, os
import json
import time
import tiktoken
from langchain.llms.base import BaseLLM
from langchain import OpenAI, Wikipedia
from langchain.docstore.base import Docstore
from langchain.agents.react.base import DocstoreExplorer
from langchain.prompts import PromptTemplate
from collections import Counter

from hotpotqa_run.pre_prompt import (react_agent_prompt, zeroshot_agent_prompt,
                         plan_prompt, planner_agent_prompt, plannerreact_agent_prompt)


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

import os
import joblib
import json

def summarize_trial(agents):
    correct = [a for a in agents if a.is_correct()]
    incorrect = [a for a in agents if a.is_finished() and not a.is_correct()]
    not_finish = [a for a in agents if not a.is_finished()]
    return correct, incorrect, not_finish

def remove_fewshot(prompt: str) -> str:
    prefix = prompt.split('Here are some examples:')[0]
    suffix = prompt.split('(END OF EXAMPLES)')[1]
    return prefix.strip('\n').strip() + '\n' +  suffix.strip('\n').strip()


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

import json
import os
import gym
import numpy as np
import re
import string
from collections import Counter

DATA_DIR = "data"
HOTPOTQA_SPLIT_FILE = {
  "train": "hotpot_train_v1.1_simplified.json",
  "dev": "hotpot_dev_v1_simplified.json",
  "test": "hotpot_test_v1_simplified.json",


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

from langchain.prompts import PromptTemplate

ZEROSHOT_INSTRUCTION = """Solve a question answering task with interleaving Thought, Action, Observation steps. Thought can reason about the current situation, and Action can be three types:
(1) Search[entity], which searches the exact entity on Wikipedia and returns the first paragraph if it exists. If not, it will return some similar entities to search. For example, Search[Milhouse]
(2) Lookup[keyword], which returns the next sentence containing keyword in the last passage successfully found by Search. For example, Lookup[named after]
(3) Finish[answer], which returns the answer and finishes the task. For example, Finish[Richard Nixon]
You may take as many steps as necessary.
Question: {question}{scratchpad}"""

zeroshot_agent_prompt = PromptTemplate(
                        input_variables=["question", "scratchpad"],
                        template = ZEROSHOT_INSTRUCTION,
                        )


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

REACT_EXAMPLE = """Question: Musician and satirist Allie Goertz wrote a song about the "The Simpsons" character Milhouse, who Matt Groening named after who?
Thought 1: The question simplifies to "The Simpsons" character Milhouse is named after who. I only need to search Milhouse and find who it is named after.
Action 1: Search[Milhouse]
Observation 1: Milhouse Mussolini Van Houten is a recurring character in the Fox animated television series The Simpsons voiced by Pamela Hayden and created by Matt Groening.
Thought 2: The paragraph does not tell who Milhouse is named after, maybe I can look up "named after".
Action 2: Lookup[named after]
Observation 2: (Result 1 / 1) Milhouse was named after U.S. president Richard Nixon, whose middle name was Milhous.
Thought 3: Milhouse was named after U.S. president Richard Nixon, so the answer is Richard Nixon.
Action 3: Finish[Richard Nixon]

Question: Were Pavel Urysohn and Leonid Levin known for the same type of work?
Thought 1: I need to search Pavel Urysohn and Leonid Levin, find their types of work, then find if they are the same.
Action 1: Search[Pavel Urysohn]
Observation 1: Pavel Samuilovich Urysohn (February 3, 1898 â August 17, 1924) was a Soviet mathematician who is best known for his contributions in dimension theory.


"""
 Copyright (c) 2023, salesforce.com, inc.
 All rights reserved.
 SPDX-License-Identifier: Apache License 2.0
 For full license text, see the LICENSE file in the repo root or https://www.apache.org/licenses/LICENSE-2.0
"""

import json
import os
import re
from collections import defaultdict
import pandas as pd
import hotpotqa_run.utils as utils

def eval_success(result_file) -> list:
    df = pd.read_csv(result_file)
    return df['success'].tolist()

def eval_reward(result_file) -> list:
    df = pd.read_csv(result_file)
    return df['reward'].tolist()


webshop/test.py

import re
def idx_parser(text):
    pattern = r"\d\s\w*"  # Matches a word boundary, followed by a digit, and then any word characters

    match = re.search(pattern, text)
    if match:
        return int(match.group(0))
    else:
        return None

text = "5\n\nAction: Buy Now"
idx = idx_parser(text)
print(idx)


import logging
import pytest
import random
import shutil
from pathlib import Path
from web_agent_site.utils import *

def test_random_idx():
    random.seed(24)
    weights = [random.randint(0, 10) for _ in range(0, 50)]
    cml_weights = [0]
    for w in weights:
        cml_weights.append(cml_weights[-1] + w)
    idx_1, expected_1 = random_idx(cml_weights), 44
    idx_2, expected_2 = random_idx(cml_weights), 15
    idx_3, expected_3 = random_idx(cml_weights), 36
    assert idx_1 == expected_1
    assert idx_2 == expected_2
    assert idx_3 == expected_3

def test_setup_logger():


import pytest
from math import isclose
from web_agent_site.engine.goal import *

def test_get_type_reward():
    # Exact Match
    goal = {
        'query': "Query 1",
        'product_category': "a › b › c",
        'name': "Name 1"
    }
    purchased = {
        'query': "Query 1",
        'product_category': "a › b › c",
        'name': "Name 1"
    }
    result = get_type_reward(purchased, goal)
    assert result['r_type'] == 1.
    assert result['query_match'] == True
    assert result['category_match'] == True
    assert result['title_score'] == 1


import pytest
from web_agent_site.engine.normalize import *

def test_normalize_color():
    suite = [
        ("", ""),
        ("black forest", "black"),
        ("violet lavender", "lavender"),
        ("steelivy fuchsia", "fuchsia"),
        ("123alabaster", "alabaster"),
        ("webshop", "webshop")
    ]
    for color_string, expected in suite:
        output = normalize_color(color_string)
        assert type(output) is str
        assert output == expected

def test_normalize_color_size():
    product_prices = {
        (1, "black forest", "3 meter"): 10.29,
        (2, "violet lavender", "xx-large"): 23.42,


import json
import pytest
import requests_mock

from transfer.predict_help import (
    convert_dict_to_actions,
    parse_item_page_amz, parse_results_amz,
    parse_item_page_ebay, parse_results_ebay,
    parse_item_page_ws, parse_results_ws,
    Page, WEBSHOP_URL, WEBSHOP_SESSION
)

@requests_mock.Mocker(kw="mock")
def test_parse_item_page_ws(**kwargs):
    # Read mock response data
    mock_file = open("tests/transfer/mocks/mock_parse_item_page_ws", "rb")
    mock_body = mock_file.read()
    mock_file.close()

    mock_desc_file = open("tests/transfer/mocks/mock_parse_item_page_ws_desc", "rb")
    mock_desc_body = mock_desc_file.read()


"""
Test the text gym environment.

TODO: move to testing dir for more rigorous tests
"""
import gym
from rich import print
from rich.markup import escape

from web_agent_site.envs import WebAgentTextEnv
from web_agent_site.models import RandomPolicy
from web_agent_site.utils import DEBUG_PROD_SIZE

if __name__ == '__main__':
    env = gym.make('WebAgentTextEnv-v0', observation_mode='text', num_products=DEBUG_PROD_SIZE)
    env.reset()

    try:
        policy = RandomPolicy()

        observation = env.observation


"""
Test the site gym environment.

TODO: move to testing dir for more rigorous tests
"""
import gym
from rich import print
from rich.markup import escape

from web_agent_site.envs import WebAgentSiteEnv
from web_agent_site.models import (
    HumanPolicy,
    RandomPolicy,
)
from web_agent_site.utils import DEBUG_PROD_SIZE

if __name__ == '__main__':
    #env = gym.make('WebAgentSite-v0')
    #env = WebAgentSiteEnv(render=True, pause=2.0)
    #env = WebAgentSiteEnv(observation_mode='html', render=False)


import argparse, json, logging, random
from pathlib import Path
from ast import literal_eval

from flask import (
    Flask,
    request,
    redirect,
    url_for
)

from rich import print

from web_agent_site.engine.engine import (
    load_products,
    init_search_engine,
    convert_web_app_string_to_var,
    get_top_n_product_from_keywords,
    get_product_per_page,
    map_action_to_html,
    END_BUTTON


import bisect
import hashlib
import logging
import random
from os.path import dirname, abspath, join

BASE_DIR = dirname(abspath(__file__))
DEBUG_PROD_SIZE = None  # set to `None` to disable

# DEFAULT_ATTR_PATH = join(BASE_DIR, '../data/items_ins_v2_1000.json')
# DEFAULT_FILE_PATH = join(BASE_DIR, '../data/items_shuffle_1000.json')
DEFAULT_ATTR_PATH = join(BASE_DIR, '../data/items_ins_v2.json')
DEFAULT_FILE_PATH = join(BASE_DIR, '../data/items_shuffle.json')
DEFAULT_REVIEW_PATH = join(BASE_DIR, '../data/reviews.json')

FEAT_CONV = join(BASE_DIR, '../data/feat_conv.pt')
FEAT_IDS = join(BASE_DIR, '../data/feat_ids.pt')

HUMAN_ATTR_PATH = join(BASE_DIR, '../data/new_human_ins_sampled_1.json')

# HUMAN_ATTR_PATH = join(BASE_DIR, '../data/items_human_ins.json')


"""
Model implementations. The model interface should be suitable for both
the ``site env'' and the ``text env''.
"""
import random

random.seed(4)

class BasePolicy:
    def __init__(self):
        pass

    def forward(observation, available_actions):
        """
        Args:
            observation (`str`):
                HTML string

            available_actions ():
                ...


from web_agent_site.models.models import (
    HumanPolicy,
    RandomPolicy,
)


import json
import yaml
import random
from pathlib import Path
from collections import defaultdict

from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.feature_extraction import text as sk_text
import pandas as pd
from tqdm import tqdm
from rich import print

ITEMS_PATH = './data/ITEMS_mar1.json'
REVIEWS_PATH = './data/reviews.json'
ATTR_DIR = './data/attributes'

random.seed(0)

def get_stop_words():
    extra_stop_words = set([str(i) for i in range(1000)])


import yaml
from pathlib import Path
from rich import print

ATTR_DIR = './data/attributes'

ATTR_PATHS = [
    'narrow_2-gram.yaml',
    'narrow_1-gram.yaml',
    'broad_2-gram.yaml',
    'broad_1-gram.yaml',
]
ATTR_PATHS = [Path(ATTR_DIR) / af for af in ATTR_PATHS]

def annotate(attr_path):
    with open(attr_path) as f:
        attrs_by_cat = yaml.safe_load(f)

    unique_attrs = set()
    all_attrs = []


import gym
import random
import requests
import string
import time

from bs4 import BeautifulSoup
from bs4.element import Comment
from gym import spaces
from os.path import join, dirname, abspath
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import ElementNotInteractableException
from web_agent_site.engine.engine import parse_action, END_BUTTON

class WebAgentSiteEnv(gym.Env):
    """Gym environment for HTML mode of WebShop environment"""

    def __init__(self, observation_mode='html', **kwargs):


import gym
import json
import random
import string
import time
import torch

from bs4 import BeautifulSoup
from bs4.element import Comment
from collections import defaultdict
from flask import Flask
from web_agent_site.engine.engine import (
    load_products,
    init_search_engine,
    get_top_n_product_from_keywords,
    map_action_to_html,
    parse_action,
    get_product_per_page,
    ACTION_TO_TEMPLATE,
    END_BUTTON, NEXT_PAGE, PREV_PAGE, BACK_TO_SEARCH,
)


from gym.envs.registration import register

from web_agent_site.envs.web_agent_site_env import WebAgentSiteEnv
from web_agent_site.envs.web_agent_text_env import WebAgentTextEnv

register(
  id='WebAgentSiteEnv-v0',
  entry_point='web_agent_site.envs:WebAgentSiteEnv',
)

register(
  id='WebAgentTextEnv-v0',
  entry_point='web_agent_site.envs:WebAgentTextEnv',
)


import re
from typing import Tuple

COLOR_SET = [
    'alabaster', 'apricot', 'aqua', 'ash', 'asphalt', 'azure',
    'banana', 'beige', 'black', 'blue', 'blush', 'bordeaux', 'bronze',
    'brown', 'burgundy', 'camel', 'camo', 'caramel', 'champagne',
    'charcoal', 'cheetah', 'chestnut', 'chocolate', 'christmas', 'coffee',
    'cognac', 'copper', 'coral', 'cranberry', 'cream', 'crystal', 'dark',
    'denim', 'eggplant', 'elephant', 'espresso', 'fuchsia', 'gold', 'granite',
    'grape', 'graphite', 'grass', 'gray', 'green', 'grey', 'heather', 'indigo',
    'ivory', 'ivy', 'khaki', 'lavender', 'lemon', 'leopard', 'light', 'lilac',
    'lime', 'magenta', 'maroon', 'mauve', 'merlot', 'midnight', 'mint', 'mocha',
    'multicolor', 'mushroom', 'mustard', 'natural', 'navy', 'nude', 'olive',
    'orange', 'peach', 'pewter', 'pink',    'plum', 'purple', 'rainbow', 'red',
    'rose', 'royal', 'rust', 'sand', 'sapphire', 'seashell', 'silver', 'skull',
    'slate', 'steel', 'stone', 'stonewash', 'sunflower', 'tan', 'taupe', 'teal',
    'tiger', 'turquoise', 'violet', 'walnut', 'wheat', 'white', 'wine', 'yellow',
]

SIZE_SET = [


"""
Functions for specifying goals and reward calculations.
"""
import itertools
import random
import spacy
from collections import defaultdict
from rich import print
from thefuzz import fuzz
from web_agent_site.engine.normalize import normalize_color

nlp = spacy.load("en_core_web_lg")

PRICE_RANGE = [10.0 * i for i in range(1, 100)]

def get_goals(all_products, product_prices, human_goals=True):
    if human_goals:
        return get_human_goals(all_products, product_prices)
    else:
        return get_synthetic_goals(all_products, product_prices)


"""
"""
import os
import re
import json
import random
from collections import defaultdict
from ast import literal_eval
from decimal import Decimal

import cleantext
from tqdm import tqdm
from rank_bm25 import BM25Okapi
from flask import render_template_string
from rich import print
from pyserini.search.lucene import LuceneSearcher

from web_agent_site.utils import (
    BASE_DIR,
    DEFAULT_FILE_PATH,
    DEFAULT_REVIEW_PATH,


class ShopAgent(object):
    def __init__(self):
        super().__init__()

    def forward(self, observation, available_actions):
        if available_actions['has_search_bar']:
            action = 'search[shoes]'
        else:
            action_arg = random.choice(available_actions['clickables'])
            action = f'click[{action_arg}]'
        return action