最新公告
  • 欢迎您光临码农资源网,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!加入我们
  • 使用 Lyzrai 转换文本:分步指南

    使用 lyzrai 转换文本:分步指南

    写作是我们日常生活中必不可少的一部分。无论是起草电子邮件、创建文档还是讲述故事,我们都力求清晰和准确。然而,使用拼写检查器纠正错误可能具有挑战性。

    使用人工智能校对,这是一款旨在润色文本的出色工具。今天,我们将探索使用 ai 来改进写作、纠正语法、拼写、标点符号和格式的简单代码。

    问题陈述

    创建语法正确的文本至关重要,但通常很困难。手动校对非常耗时并且可能会漏掉错误。此代码使用lyzr.ai检查和编辑文本,提高写作效率。

    先决条件

    开始之前,您应该了解 python 编程并可以使用 api 密钥访问 openai api。熟悉安装和导入 python 库和 lyzr.ai 的框架也会有所帮助。

    安装 lyzr automata 框架

    pip install lyzr-automata
    
    # for google colab or notebook
    !pip install lyzr-automata
    

    代码和说明

    让我们逐步分解代码。

    from lyzr_automata.ai_models.openai import openaimodel
    from lyzr_automata import agent, task
    from lyzr_automata.tasks.task_literals import inputtype, outputtype
    from lyzr_automata.pipelines.linear_sync_pipeline import linearsyncpipeline
    from lyzr_automata import logger
    
    api_key = input('enter openai api key')
    text = input('enter the text here: ')
    

    我们首先从 lyzr.ai 库导入必要的工具,并提示用户输入 openai api 密钥和文本进行校对。

    open_ai_model_text = openaimodel(
        api_key=api_key,
        parameters={
            "model": "gpt-4-turbo-preview",
            "temperature": 0.5,
            "max_tokens": 1500,
        },
    )
    

    我们使用 api 密钥和参数设置 ai 模型,控制 ai 的行为和响应长度。

    def ai_proofreader(text):
        proofreader = agent(
            prompt_persona="""you are an expert proofreader who can find grammatical errors, and you excel at checking for grammar, spelling, punctuation, and formatting errors.""",
            role="ai proofreader",
        )
    
        rephrase_text = task(
            name="rephrasing text",
            agent=proofreader,
            output_type=outputtype.text,
            input_type=inputtype.text,
            model=open_ai_model_text,
            instructions=f"check the entire text: '{text}' and rephrase it according to grammar, spelling, punctuation, and formatting errors. [important] avoid introduction and conclusion in the response.",
            log_output=true,
            enhance_prompt=false,
            default_input=text
        )
    
        remarks = task(
            name="remarks",
            agent=proofreader,
            output_type=outputtype.text,
            input_type=inputtype.text,
            model=open_ai_model_text,
            instructions=f"check the entire text: '{text}' and provide remarks in bullet points according to grammar, spelling, punctuation, and formatting errors. [important] avoid introduction and conclusion in the response.",
            log_output=true,
            enhance_prompt=false,
            default_input=text
        )
    
        logger = logger()
    
        main_output = linearsyncpipeline(
            logger=logger,
            name="ai proofreader",
            completion_message="app generated all things!",
            tasks=[
                rephrase_text,
                remarks,
            ],
        ).run()
    
        return main_output
    

    我们定义了一个名为 ai_proofreader 的函数。在内部,我们创建一个名为 proofreader 的代理,充当专家校对员。创建了两项任务:一项用于改写文本,另一项用于提供注释。这两项任务都使用 proofreader 代理和 ai 模型。

    记录器监控该过程。然后,我们建立一个按顺序执行任务的管道,生成正确的文本和注释。

    generated_output = ai_proofreader(text=text)
    rephrased_text = generated_output[0]['task_output']
    remarks = generated_output[1]['task_output']
    

    我们用用户的文本调用该函数,并获得改写的文本和注释作为输出。

    示例输入

    text = """ i rajesh have 2+ years of experience in python developer, 
    i know to create backend applications, 
    i am seeking a new role for new learnings """
    

    输出

    """ 
    My name is Rajesh, and I possess over two years of experience as a Python developer. 
    I am skilled in creating backend applications and am currently seeking a new role to further my learning 
    
    - The phrase "I Rajesh have 2+ years of experience in python developer" should be corrected to "I, Rajesh, have over two years of experience as a Python developer." This correction addresses a punctuation issue (adding commas around "Rajesh"), a numerical expression ("2+" to "over two"), and clarifies the role ("in python developer" to "as a Python developer").
    - "python" should be capitalized to "Python" to properly denote the programming language.
    - The phrase "I know to create backend applications" could be more fluidly expressed as "I know how to create backend applications" or "I am skilled in creating backend applications" for clarity and grammatical correctness.
    - The phrase "I am seeking a new role for new learnings" could be improved for clarity and professionalism. A better alternative might be "I am seeking a new role to further my learning" or "I am seeking a new role to continue my professional development."
    - The entire passage could benefit from better punctuation and formatting for clarity and flow. For instance, using semicolons or periods to separate independent clauses can improve readability: "My name is Rajesh, and I possess over two years of experience as a Python developer; I am skilled in creating backend applications and am currently seeking a new role to further my learning."
    - Consistency in tense and style would improve the professional tone of the passage.
    """
    

    关于 lyzr.ai

    lyzr.ai 提供了一个低代码代理开发套件,用于快速创建 genai 应用程序。通过这个简单的代理框架,您可以构建安全可靠的生成式人工智能应用程序,用于各种用途,包括校对和写作。

    参考资料

    如需了解更多信息,请访问 lyzr 的网站、预订演示或加入 discord 和 slack 上的社区频道。

    • lyzr 网站
    • 预订演示
    • lyzr 社区频道:discord、slack

    ai 校对器:github

    想要了解更多内容,请持续关注码农资源网,一起探索发现编程世界的无限可能!
    本站部分资源来源于网络,仅限用于学习和研究目的,请勿用于其他用途。
    如有侵权请发送邮件至1943759704@qq.com删除

    码农资源网 » 使用 Lyzrai 转换文本:分步指南
    • 7会员总数(位)
    • 25846资源总数(个)
    • 0本周发布(个)
    • 0 今日发布(个)
    • 293稳定运行(天)

    提供最优质的资源集合

    立即查看 了解详情