Skip to content

A lightweight PHP script utilizing cURL to interact with the OpenAI API, enabling developers to integrate GPT-powered conversational agents without dependencies.

Notifications You must be signed in to change notification settings

Blockgeni3-Rab/php-openai-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

PHP-OpenAI-API

A lightweight PHP script utilizing cURL to interact with the OpenAI API, enabling developers to integrate GPT-powered conversational agents without dependencies.

Prerequisites

  • PHP 7.0 or higher
  • cURL enabled in PHP

Getting Started

1. Clone the Repository

Use Git to clone the repository directly to your local machine.

git clone https://github.com/rossxdev/PHP-OpenAI-API.git

2. Download the Code

Navigate to the repository and use the "Code" button to download a zip file of the project, which you can then extract to your local machine.

3. Copy and Paste

Simply navigate to the PHP file in the GitHub repository, view the raw code, and copy/paste it into a new file in your own development environment.

Choose the method that best suits your workflow and proceed to configure your API key and modify your prompts as needed.

Setup

  1. Configure API Key

    Replace "your-api-key-here" in the PHP script with your actual API key obtained from OpenAI.

    $api_key = "your-api-key-here";

Usage

  1. Modify the Prompt

    Replace 'your-prompt-here' in the PHP script with the prompt you want to use.

    ['role' => 'user', 'content' => 'your-prompt-here']
  2. Execute the Script

    Run the PHP script using a server or local development environment.

    php your-script-name.php

Response Handling

The script returns the model's response as a string. For custom handling, modify the following section in the script:

echo $decoded_response['choices'][0]['message']['content'];

Contributing

Feel free to fork the project and submit your contributions via a pull request.

License

This project is open-source and available under the MIT License.

Disclaimer

This script utilizes the OpenAI API and may incur costs. Ensure to review the pricing details on OpenAI's Pricing Page.

About

A lightweight PHP script utilizing cURL to interact with the OpenAI API, enabling developers to integrate GPT-powered conversational agents without dependencies.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages