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

Maven 使用指南 中文WORD版
Maven 使用指南 中文WORD版

本文档主要讲述的是Maven 使用指南;Apache Maven,是一个软件(特别是Java软件)项目管理及自动构建工具,由Apache软件基金会所提供。基于项目对象模型(缩写:POM)概念,Maven利用一个中央信息片断能管理一个项目的构建、报告和文档等步骤。希望本文档会给有需要的朋友带来帮助;感兴趣的朋友可以过来看看

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

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

豆包大模型
豆包大模型

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

通义千问
通义千问

阿里巴巴推出的全能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 上的“存储库”中,你可以: “展示或共享”你的工作。 持续“跟踪和管理”对代码的更改。

997

2026.01.21

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

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

285

2024.05.21

java入门学习合集
java入门学习合集

本专题整合了java入门学习指南、初学者项目实战、入门到精通等等内容,阅读专题下面的文章了解更多详细学习方法。

1

2026.01.29

java配置环境变量教程合集
java配置环境变量教程合集

本专题整合了java配置环境变量设置、步骤、安装jdk、避免冲突等等相关内容,阅读专题下面的文章了解更多详细操作。

1

2026.01.29

java成品学习网站推荐大全
java成品学习网站推荐大全

本专题整合了java成品网站、在线成品网站源码、源码入口等等相关内容,阅读专题下面的文章了解更多详细推荐内容。

0

2026.01.29

Java字符串处理使用教程合集
Java字符串处理使用教程合集

本专题整合了Java字符串截取、处理、使用、实战等等教程内容,阅读专题下面的文章了解详细操作教程。

0

2026.01.29

Java空对象相关教程合集
Java空对象相关教程合集

本专题整合了Java空对象相关教程,阅读专题下面的文章了解更多详细内容。

3

2026.01.29

clawdbot ai使用教程 保姆级clawdbot部署安装手册
clawdbot ai使用教程 保姆级clawdbot部署安装手册

Clawdbot是一个“有灵魂”的AI助手,可以帮用户清空收件箱、发送电子邮件、管理日历、办理航班值机等等,并且可以接入用户常用的任何聊天APP,所有的操作均可通过WhatsApp、Telegram等平台完成,用户只需通过对话,就能操控设备自动执行各类任务。

24

2026.01.29

clawdbot龙虾机器人官网入口 clawdbot ai官方网站地址
clawdbot龙虾机器人官网入口 clawdbot ai官方网站地址

clawdbot龙虾机器人官网入口:https://clawd.bot/,clawdbot ai是一个“有灵魂”的AI助手,可以帮用户清空收件箱、发送电子邮件、管理日历、办理航班值机等等,并且可以接入用户常用的任何聊天APP,所有的操作均可通过WhatsApp、Telegram等平台完成,用户只需通过对话,就能操控设备自动执行各类任务。

16

2026.01.29

热门下载

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

精品课程

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

共4课时 | 22.4万人学习

Django 教程
Django 教程

共28课时 | 3.6万人学习

SciPy 教程
SciPy 教程

共10课时 | 1.3万人学习

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

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