ホームページ  >  記事  >  バックエンド開発  >  Lyzr.ai でテキストを変換する: ステップバイステップ ガイド

Lyzr.ai でテキストを変換する: ステップバイステップ ガイド

PHPz
PHPzオリジナル
2024-08-07 08:04:12997ブラウズ

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

書くことは私たちの日常生活に不可欠な部分です。メールの下書き、文書の作成、ストーリーの伝え方のいずれにおいても、私たちは明確さと正確さを目指します。ただし、スペル チェッカーでエラーを修正するのは困難な場合があります。

テキストを磨き上げるために設計された素晴らしいツールである AI 校正を始めましょう。今日は、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 という名前のエージェントを作成します。 2 つのタスクが作成されます。1 つはテキストの言い換えで、もう 1 つは注釈の入力です。どちらのタスクも 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 の Web サイトにアクセスするか、デモを予約するか、Discord や Slack のコミュニティ チャンネルに参加してください。

  • Lyzr ウェブサイト
  • デモを予約する
  • Lyzr コミュニティ チャンネル: Discord、Slack

AI 校正者: GitHub

以上がLyzr.ai でテキストを変換する: ステップバイステップ ガイドの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。