langchain的react模板提示词

提示词

Answer the following questions as best you can. You have access to the following tools:
open: open(url: str) - 使用浏览器打开特定的url,并返回网页内容
find: find(css: str) - 从网页的源代码中分析出要寻找的元素的css定位符,输入网页元素的css定位符,定位到元素,用于执行后续的操作
click: click(arg: str = None) - 点击网页元素,需要提前执行find定位到对应的网页元素
send_keys: send_keys(text) - 输入文本,需要提前执行find定位到对应的网页元素
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [open, find, click, send_keys]
Action Input: the input to the action
Observation: the result of the action
 (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin!
Question: 每次只返回一个action或者tool打开 https://petclinic-angular-web.k8s.hogwarts.ceshiren.com/#/owners, 在搜索框中输入Davis,点击查找按钮,并返回搜索之后的搜索结果
Thought:

React过程

Answer the following questions as best you can. You have access to the following tools:
open: open(url: str) - 使用浏览器打开特定的url,并返回网页内容
find: find(css: str) - 从网页的源代码中分析出要寻找的元素的css定位符,输入网页元素的css定位符,定位到元素,用于执行后续的操作
click: click(arg: str = None) - 点击网页元素,需要提前执行find定位到对应的网页元素
send_keys: send_keys(text) - 输入文本,需要提前执行find定位到对应的网页元素
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [open, find, click, send_keys]
Action Input: the input to the action
Observation: the result of the action
 (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin!
Question: 每次只返回一个action或者tool。打开 https://petclinic-angular-web.k8s.hogwarts.ceshiren.com/#/owners, 在搜索框中输入Davis,点击查找按钮,并返回搜索之后的搜索结果
Thought: 需要先打开网页,然后找到搜索框,输入文本,点击查找按钮,最后返回搜索结果
Action: open
Action Input: https://petclinic-angular-web.k8s.hogwarts.ceshiren.com/#/owners
Observation: <button _ngcontent-cln-c48="" type="submit" class="btn btn-default">Find Owner</button><input _ngcontent-cln-c48="" size="30" maxlength="80" id="lastName" name="lastName" value="" class="form-control ng-untouched ng-pristine ng-valid" ng-reflect-maxlength="80" ng-reflect-name="lastName">
Thought: 通过find定位到搜索框,然后输入文本,再通过find定位到查找按钮,最后点击
Action: find
Action Input: #lastName
Observation: None
Thought: 通过send_keys输入文本
Action: send_keys
Action Input: Davis
Observation: <button _ngcontent-cln-c48="" type="submit" class="btn btn-default">Find Owner</button><button _ngcontent-cln-c48="" class="btn btn-default">Add Owner</button><input _ngcontent-cln-c48="" size="30" maxlength="80" id="lastName" name="lastName" value="" class="form-control ng-untouched ng-valid ng-dirty" ng-reflect-maxlength="80" ng-reflect-name="lastName" ng-reflect-model="Davis">
Thought: 通过find定位到查找按钮,然后点击
Action: find
Action Input: .btn-default
Observation: None
Thought: 通过click点击查找按钮
Action: click
Action Input: None
Observation: <button _ngcontent-cln-c48="" type="submit" class="btn btn-default" style="">Find Owner</button><button _ngcontent-cln-c48="" class="btn btn-default">Add Owner</button><input _ngcontent-cln-c48="" size="30" maxlength="80" id="lastName" name="lastName" value="" class="form-control ng-valid ng-dirty ng-touched" ng-reflect-maxlength="80" ng-reflect-name="lastName" ng-reflect-model="Davis">
Thought: 通过find定位到搜索结果
Action: find
Action Input: .ownerFullName
Observation: None
Thought: 通过click点击搜索结果
Action: click
Action Input: None
Observation: <button _ngcontent-cln-c48="" type="submit" class="btn btn-default" style="">Find Owner</button><button _ngcontent-cln-c48="" class="btn btn-default">Add Owner</button><input _ngcontent-cln-c48="" size="30" maxlength="80" id="lastName" name="lastName" value="" class="form-control ng-valid ng-dirty ng-touched" ng-reflect-maxlength="80" ng-reflect-name="lastName" ng-reflect-model="Davis">
Thought: 通过find定位到搜索结果的文本内容
Action: find
Action Input: .ownerFullName
Observation: None
Thought: 通过text属性获取搜索结果的文本内容
Action: text
Action Input: None
Observation: text is not a valid tool, try one of [open, find, click, send_keys].
Thought: 通过get_attribute获取搜索结果的文本内容
Action: get_attribute
Action Input: text
Observation: get_attribute is not a valid tool, try one of [open, find, click, send_keys].
Thought: 通过get_attribute获取搜索结果的文本内容
Action: get_attribute
Action Input: innerHTML
Observation: get_attribute is not a valid tool, try one of [open, find, click, send_keys].
Thought: 通过get_attribute获取搜索结果的文本内容
Action: get_attribute
Action Input: textContent
Observation: get_attribute is not a valid tool, try one of [open, find, click, send_keys].
Thought: 通过get_attribute获取搜索结果的文本内容
Action: get_attribute
Action Input: value
Observation: get_attribute is not a valid tool, try one of [open, find, click, send_keys].
Thought: 通过get_attribute获取搜索结果的文本内容
Action: get_attribute
Action Input: innerText
Observation: get_attribute is not a valid tool, try one of [open, find, click, send_keys].
Thought:

源代码

from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By


class WebAutoFrameWork:
    """
    完成对浏览器的操作,包括打开网页,点击,输入等操作
    """

    def __init__(self):
        self.driver = None
        self.element = None

    def init(self):
        if not self.driver:
            self.driver = webdriver.Firefox()
            self.driver.implicitly_wait(5)

    def open(self, url):
        self.init()

        self.driver.get(url)
        return self.source()

    def source(self):
        """
        获取网页的源代码

        原有的selenium的page source不太合适,因为它只返回html的内容,不包括js生成的内容

        document.body.outerHTML可以获取到所有的内容,但是这个内容是动态生成的,不是最终的内容

        :return:
        """

        return self.driver.execute_script(
            """
            var content="";
            document.querySelectorAll('button').forEach(x=> content+=x.outerHTML);
            document.querySelectorAll('input').forEach(x=> content+=x.outerHTML);
            //document.querySelectorAll('table').forEach(x=> content+=x.outerHTML);
            return content;
            """
        )

    def click(self):
        """
        点击当前的元素
        :return:
        """
        self.element.click()
        sleep(1)
        return self.source()

    def send_keys(self, text):
        """
        输入文本到当前的元素
        :param text:
        :return:
        """
        self.element.send_keys(text)
        return self.source()

    def find(self, locator):
        """
        根据css定位符找到元素
        :param locator:
        :return:
        """
        print(f"find css = {locator}")
        element = self.driver.find_element(by=By.CSS_SELECTOR, value=locator)
        self.element = element
        return self.source()

企业落地人工智能

  • 私有大模型 llama mixtral
  • RAG PrivateGPT
  • offline生成测试用例、测试数据、测试代码
  • online agent模式 手工转自动化并执行
  • 缺陷挖掘 PrivateGPT + 提示词+规则说明
  • 知识图谱与模型驱动 业务需求 测试用例(web 接口) 代码

老师,agent的导入部署部分,这里还没有,那个是可以分享一下的吗