使用 Lyzr.ai 轉換文字:逐步指南

PHPz
發布: 2024-08-07 08:04:12
原創
991 人瀏覽過

Transform Your Text with Lyzr.ai: A Step-by-Step Guide

寫作是我們日常生活的重要組成部分。無論是起草電子郵件、建立文件或講述故事,我們都力求清晰和準確。然而,使用拼字檢查器糾正錯誤可能具有挑戰性。

人工智慧校對登場,這是一款旨在潤飾文字的絕佳工具。今天,我們將探索使用 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 應用程式。借助這個簡單的代理框架,您可以建立安全可靠的生成式 AI 應用程序,用於各種用途,包括校對和寫作。

參考文獻

如需了解更多信息,請訪問 Lyzr 的網站、預訂演示或加入 Discord 和 Slack 上的社區頻道。

  • Lyzr 網址
  • 預約示範
  • Lyzr 社群頻道:Discord、Slack

人工智慧校對器: GitHub

以上是使用 Lyzr.ai 轉換文字:逐步指南的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!