讲师中心 微信公众号
AI工具推荐 视频效率加速

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

小瑶大大_2645

小瑶大大_2645

发布时间:2024-08-07 15:13:38

|

321人浏览过

|

来源于dev.to

转载

使用 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 的行为和响应长度。

GitHub Actions Deploy Risk Audit
GitHub Actions Deploy Risk Audit

通过评估失败率、未解决的连续失败和上次成功部署以来的时间,审计GitHub Actions运行的部署工作流风险。

下载
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

热门AI工具

更多
LibLibAI
LibLibAI Hot

一款AI视频创作工具,主要用于国内领先的AI创意平台,以海量模型、低门槛操作与“创作-分享-商业化”生态,让小白与专业创作者都能高效实现图文乃至视频创意表达,适合需要提升相关任务效率的用户。

VibeKnow
VibeKnow Hot

一款AI视频创作工具,主要用于全球首个AI知识视频创作平台,文档、文章、网页,一键生成视频,适合需要提升相关任务效率的用户。

Lovart
Lovart Hot

一款面向视觉设计创作的AI设计平台,可通过智能体和画布工作流辅助制作海报、Logo、网页、PPT及其他视觉内容。

DeepSeek

DeepSeek是一款面向对话、写作、编程和推理场景的AI大模型工具。

WorkBuddy

一款AI办公效率工具,主要用于腾讯云推出的AI原生桌面智能体工作台,适合需要提升相关任务效率的用户。

Loomy
Loomy Hot

一款AI工具,主要用于科大讯飞发布的桌面级 AI 助理,比 OpenClaw 更易用、更安全!,适合需要提升相关任务效率的用户。

立刻MV
立刻MV Hot

立刻MV是一款AI文本写作工具,AI 音乐视频(MV)创作工具。

豆包大模型

豆包大模型是一款由字节跳动推出的企业级大语言模型服务平台。

Seko
Seko Hot

一款AI视频创作工具,主要用于商汤科技推出的创编一体的AI短视频创作Agent,适合需要提升相关任务效率的用户。

相关专题

更多
github中文官网入口 github中文版官网网页进入
github中文官网入口 github中文版官网网页进入

github中文官网入口https://docs.github.com/zh/get-started,GitHub 是一种基于云的平台,可在其中存储、共享并与他人一起编写代码。 通过将代码存储在GitHub 上的“存储库”中,你可以: “展示或共享”你的工作。 持续“跟踪和管理”对代码的更改。

8225

2026.01.21

GitHub官网入口版本汇总
GitHub官网入口版本汇总

本专题整合了GitHub入口版本地址汇总,阅读专题下面的文章了解更多详细内容。

738

2026.04.02

什么是低代码
什么是低代码

低代码是一种软件开发方法,使用预构建的组件可快速构建应用程序,无需大量编程。想了解更多低代码的相关内容,可以阅读本专题下面的文章。

2531

2024.05.21

Buffalo框架数据库开发全教程
Buffalo框架数据库开发全教程

本专题围绕Buffalo框架数据库开发,讲解database.yml多环境配置、soda与fizz迁移生成回滚、模型结构体标签、增删改查与条件查询、一对多与多对多关联、数据校验、回调钩子、事务处理及原生SQL执行能力。

60

2026.09.23

Buffalo框架路由与请求处理实操指南
Buffalo框架路由与请求处理实操指南

本专题讲解Buffalo框架路由与请求处理机制,涵盖路由注册与分组、资源路由、Handler编写规范、Context上下文方法、参数绑定、中间件编写挂载、Session与Cookie读写、Flash消息及错误页面定制方法。

20

2026.09.23

Buffalo框架零基础入门教程
Buffalo框架零基础入门教程

本专题整理Buffalo框架入门内容,涵盖Go环境准备、buffalo CLI安装、新项目生成、目录结构说明、dev热加载启动、数据库连接配置与常见报错排查,帮助新手按约定优于配置的思路跑通第一个Buffalo框架应用。

20

2026.09.23

Conan创建软件包配方指南
Conan创建软件包配方指南

本专题介绍通过conanfile.py创建软件包的方法,讲解包名、版本、依赖和构建设置等基础信息,以及source、build、package、package_info等常用方法的作用及编写思路。

20

2026.09.22

Conan二进制包配置指南
Conan二进制包配置指南

本专题介绍Conan根据操作系统、编译器、架构和构建类型生成二进制包的方法,讲解Profile、Settings、Options及Package ID的作用,帮助管理不同平台和编译环境下的包版本。

20

2026.09.22

Conan私有仓库搭建教程
Conan私有仓库搭建教程

本专题系统的讲解Conan私有仓库的搭建流程,涵盖仓库服务部署、存储目录配置、用户认证、权限划分和远程地址添加,并介绍内部C++依赖包的上传、下载及版本维护方法。

20

2026.09.22

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn