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

WBOY
发布: 2024-08-07 15:13:38
转载
225人浏览过

使用 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

以上就是使用 Lyzrai 转换文本:分步指南的详细内容,更多请关注php中文网其它相关文章!

豆包AI编程
豆包AI编程

智能代码生成与优化,高效提升开发速度与质量!

下载
来源:dev.to网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号