Giter Site home page Giter Site logo

aish's Introduction

GPT Command Executor

このプロジェクトは、OpenAIの**GPT-4o-mini**を使用してユーザーのクエリに基づいたシェルコマンドを提案し、選択・実行するためのPythonスクリプトです。

概要

このスクリプトは、ユーザーからのクエリを受け取り、OpenAIのAPIを使用して適切なシェルコマンドを生成します。生成されたコマンドはfzfを使って選択され、ユーザーの確認のもと実行されます。

必要な前提条件

  • Python 3.10
  • OpenAI APIキー
  • fzf (コマンドラインツール)

インストール手順

  1. このリポジトリをクローンします。

    git clone https://github.com/clearclown/aish.git
    cd aish
  2. 必要なPythonライブラリをインストールします。

    pip install openai python-dotenv
  3. .envファイルを作成し、OpenAI APIキーを設定します。

    cp .env.example .env
  4. fzfをインストールします。

    sudo apt-get install fzf -y

使用方法

  1. gptコマンドを実行します。

    python gpt.py "<クエリ>"

    例:

    python gpt.py "システムのアップデート方法"
  2. 提案されたコマンドがfzfに表示されます。適切なコマンドを選択します。

  3. 選択したコマンドを実行するかどうか確認されます。YESと入力して実行します。

ファイル構成の説明

  • gpt.py:
    • メインのスクリプト。クエリを受け取り、OpenAIのAPIを使用して応答を取得し、fzfでコマンドを選択・実行します。
  • prompt.py:
    • プロンプト生成のための関数を含みます。クエリと現在の状況に基づいてOpenAIに送信するプロンプトを生成します。
  • .env:
    • 環境変数を設定するファイル。OpenAI APIキーを含めます。

エラーハンドリングについて

  • gpt.py内のget_gpt_response関数およびexecute_command関数では、例外処理を行いエラーメッセージを返します。
  • fzfでのコマンド選択がキャンセルされた場合、適切なメッセージを表示します。

環境変数の設定

.envファイルにOpenAI APIキーを設定します。以下の形式でキーを入力してください。

OPENAI_API_KEY=your_api_key_here

aish's People

Contributors

clearclown avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.