Skip to content

maurobonfietti/chat-open-ai-cli

Repository files navigation

ChatGPT from the CLI

🤖 Ask questions to ChatGPT from the CLI.

alt text


GETTING STARTED:

Requires PHP 8.1+

Clone repository with git and install dependencies:

In your terminal execute:

git clone https://github.com/maurobonfietti/chat-open-ai-cli
cd chat-open-ai-cli
cp .env.example .env
composer install

Configure your OpenAI API KEY:

Edit your .env file:

OPEN_AI_SECRET_API_KEY='Your-Open-AI-Secret-Api-Key-Goes-Here'

Get your API KEY from OpenAI:

Create an account on OpenAI to get your API KEY.

Screenshot from OpenAI Platform:

Screenshot: Get your API KEY from OPEN AI Platform.


USAGE:

Chat to OpenAI from CLI with this command:

php console chat

OPTIONS:

To use OpenAI GPT-4 API:

php console chat --gpt4

Allow multiline with this command:

php console chat --multiline

Get help and more info:

php console chat --help

Check command version:

php console --version

I'm using the alias: chat equivalent to: php console chat.

DEMO:

📹 🎥 See the video on Youtube: I ask the OpenAI API questions from the CLI.

Chat0.3.2.mp4

DEPENDENCIES:

  • openai-php/client: Supercharged community PHP API client that allows you to interact with the Open AI API.
  • symfony/console: The Console component eases the creation of beautiful and testable command line interfaces.
  • vlucas/phpdotenv: Loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically.

CONFIGURE YOUR OPEN AI ACCOUNT:

When you create your account on OpenAI, you can get some free credits (like 18 USD on credits -at the time of writing this-). You can set your prefered payment method (Credit Card for instance).

Screenshot from OpenAI Platform:

Screenshot: Payment Method: Credit Card.


Also, you can set and configure the usage limits (Hard Limit and Soft Limit).

Screenshot from OpenAI Platform:

alt text


Screenshot from OpenAI Platform:

alt text


HELPFUL EXTERNAL LINKS:

https://openai.com/api/pricing/

https://platform.openai.com/tokenizer

https://platform.openai.com/account/usage

https://platform.openai.com/docs/quickstart/adjust-your-settings

https://platform.openai.com/docs/models/finding-the-right-model

LICENSE:

📄 The MIT License (MIT). Please see License File for more information.

WOULD YOU LIKE TO SUPPORT THIS PROJECT?

❤️ You can support this project inviting me a coffee ☕ 😋 or giving a star to this repo ⭐ 😊.

ko-fi

THAT'S IT!

🥳 Now go and ask interesting questions to ChatGPT from the CLI 💻 🤖.

Releases

No releases published

Packages

No packages published

Languages