0

0

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

WBOY

WBOY

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

|

301人浏览过

|

来源于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 的行为和响应长度。

PaperFake
PaperFake

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

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

WorkBuddy
WorkBuddy

腾讯云推出的AI原生桌面智能体工作台

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

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

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

4287

2026.01.21

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

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

300

2024.05.21

TypeScript类型系统进阶与大型前端项目实践
TypeScript类型系统进阶与大型前端项目实践

本专题围绕 TypeScript 在大型前端项目中的应用展开,深入讲解类型系统设计与工程化开发方法。内容包括泛型与高级类型、类型推断机制、声明文件编写、模块化结构设计以及代码规范管理。通过真实项目案例分析,帮助开发者构建类型安全、结构清晰、易维护的前端工程体系,提高团队协作效率与代码质量。

25

2026.03.13

Python异步编程与Asyncio高并发应用实践
Python异步编程与Asyncio高并发应用实践

本专题围绕 Python 异步编程模型展开,深入讲解 Asyncio 框架的核心原理与应用实践。内容包括事件循环机制、协程任务调度、异步 IO 处理以及并发任务管理策略。通过构建高并发网络请求与异步数据处理案例,帮助开发者掌握 Python 在高并发场景中的高效开发方法,并提升系统资源利用率与整体运行性能。

44

2026.03.12

C# ASP.NET Core微服务架构与API网关实践
C# ASP.NET Core微服务架构与API网关实践

本专题围绕 C# 在现代后端架构中的微服务实践展开,系统讲解基于 ASP.NET Core 构建可扩展服务体系的核心方法。内容涵盖服务拆分策略、RESTful API 设计、服务间通信、API 网关统一入口管理以及服务治理机制。通过真实项目案例,帮助开发者掌握构建高可用微服务系统的关键技术,提高系统的可扩展性与维护效率。

177

2026.03.11

Go高并发任务调度与Goroutine池化实践
Go高并发任务调度与Goroutine池化实践

本专题围绕 Go 语言在高并发任务处理场景中的实践展开,系统讲解 Goroutine 调度模型、Channel 通信机制以及并发控制策略。内容包括任务队列设计、Goroutine 池化管理、资源限制控制以及并发任务的性能优化方法。通过实际案例演示,帮助开发者构建稳定高效的 Go 并发任务处理系统,提高系统在高负载环境下的处理能力与稳定性。

50

2026.03.10

Kotlin Android模块化架构与组件化开发实践
Kotlin Android模块化架构与组件化开发实践

本专题围绕 Kotlin 在 Android 应用开发中的架构实践展开,重点讲解模块化设计与组件化开发的实现思路。内容包括项目模块拆分策略、公共组件封装、依赖管理优化、路由通信机制以及大型项目的工程化管理方法。通过真实项目案例分析,帮助开发者构建结构清晰、易扩展且维护成本低的 Android 应用架构体系,提升团队协作效率与项目迭代速度。

92

2026.03.09

JavaScript浏览器渲染机制与前端性能优化实践
JavaScript浏览器渲染机制与前端性能优化实践

本专题围绕 JavaScript 在浏览器中的执行与渲染机制展开,系统讲解 DOM 构建、CSSOM 解析、重排与重绘原理,以及关键渲染路径优化方法。内容涵盖事件循环机制、异步任务调度、资源加载优化、代码拆分与懒加载等性能优化策略。通过真实前端项目案例,帮助开发者理解浏览器底层工作原理,并掌握提升网页加载速度与交互体验的实用技巧。

102

2026.03.06

Rust内存安全机制与所有权模型深度实践
Rust内存安全机制与所有权模型深度实践

本专题围绕 Rust 语言核心特性展开,深入讲解所有权机制、借用规则、生命周期管理以及智能指针等关键概念。通过系统级开发案例,分析内存安全保障原理与零成本抽象优势,并结合并发场景讲解 Send 与 Sync 特性实现机制。帮助开发者真正理解 Rust 的设计哲学,掌握在高性能与安全性并重场景中的工程实践能力。

227

2026.03.05

热门下载

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

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
最新Python教程 从入门到精通
最新Python教程 从入门到精通

共4课时 | 22.5万人学习

Django 教程
Django 教程

共28课时 | 5万人学习

SciPy 教程
SciPy 教程

共10课时 | 1.9万人学习

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

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