ramprasadm1986 / yii2-chatgpt
A Yii2 component for interacting with the OpenAI ChatGPT API, including Agri Advisor GPT for agricultural advisory.
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.4
- yiisoft/yii2: ~2.0.0
- yiisoft/yii2-httpclient: ~2.0.0
This package is auto-updated.
Last update: 2024-11-12 11:19:23 UTC
README
A Yii2 component to interact with the OpenAI ChatGPT API.
Installation
Install via Composer:
composer require ramprasadm1986/yii2-chatgpt ## ChatGPT Configure `chatGPT` in `config/web.php`: ```php 'components' => [ 'chatGPT' => [ 'class' => 'ramprasadm1986\chatgpt\ChatGPT', 'apiKey' => 'YOUR_OPENAI_API_KEY', ], ], ### Usage Example ```php $response = $response = Yii::$app->chatgpt->askGPT('What is the weather like today?', 'general knowledge', 'gpt-3.5-turbo'); echo $response; ## AgriAdvisorGPT In addition to standard ChatGPT interactions, this package provides `AgriAdvisorGPT` for agriculture-specific questions. It uses a custom system prompt to provide specialized advice. Configure `AgriAdvisorGPT` in `config/web.php`: ```php 'components' => [ 'agriAdvisorGPT' => [ 'class' => 'ramprasadm1986\chatgpt\AgriAdvisorGPT', 'apiKey' => 'YOUR_OPENAI_API_KEY', ], ], ### Usage in Yii2 Project You can now use the `agriAdvisorGPT` component to get tailored advice for agricultural topics. Examples: **General Advice**: ```php $response = Yii::$app->agriAdvisorGPT->askAgriAdvisor('What are the best practices for pest management in organic farming?'); echo $response; $response = Yii::$app->agriAdvisorGPT->askCropAdvisor('corn', 'How often should I irrigate corn during summer?'); echo $response;