diff --git a/www-api/.gitignore b/www-api/.gitignore index c5678662..8d50b0f1 100644 --- a/www-api/.gitignore +++ b/www-api/.gitignore @@ -20,7 +20,7 @@ user_guide_src/build/* user_guide_src/cilexer/build/* user_guide_src/cilexer/dist/* user_guide_src/cilexer/pycilexer.egg-info/* -/vendor/ +#/vendor/ # IDE Files #------------------------- diff --git a/www-api/vendor/orhanerday/open-ai/CHANGELOG.md b/www-api/vendor/orhanerday/open-ai/CHANGELOG.md new file mode 100644 index 00000000..3fb060af --- /dev/null +++ b/www-api/vendor/orhanerday/open-ai/CHANGELOG.md @@ -0,0 +1,162 @@ +# Changelog + +All notable changes to `open-ai` will be documented in this file. + +## 3.5 - 2023-02-10 + +### What's Changed + +- Fix "export-ignore" does not work by @assert6 in https://github.com/orhanerday/open-ai/pull/43 +- Update README.md by @ali-wells in https://github.com/orhanerday/open-ai/pull/45 +- Bump dependabot/fetch-metadata from 1.3.5 to 1.3.6 by @dependabot in https://github.com/orhanerday/open-ai/pull/47 +- Add customURL support. by @orhanerday in https://github.com/orhanerday/open-ai/pull/49 + +### New Contributors + +- @assert6 made their first contribution in https://github.com/orhanerday/open-ai/pull/43 +- @ali-wells made their first contribution in https://github.com/orhanerday/open-ai/pull/45 + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/3.4...3.5 + +## 3.4 - 2023-01-03 + +### What's Changed + +- Add organization support. by @orhanerday in https://github.com/orhanerday/open-ai/pull/40 + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/3.3...3.4 + +## 3.3 - 2022-12-28 + +### What's Changed + +- Feature request: support stream by @orhanerday in https://github.com/orhanerday/open-ai/pull/37 + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/3.2.1...3.3 + +## 3.2.1 - 2022-12-07 + +### What's Changed + +- Update README.md by @orhanerday + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/3.2...3.2.1 + +## 3.2 - 2022-12-06 + +### What's Changed + +- Ability to set a timeout value in seconds by @dsampaolo in https://github.com/orhanerday/open-ai/pull/31 + +### New Contributors + +- @dsampaolo made their first contribution in https://github.com/orhanerday/open-ai/pull/31 + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/3.1...3.2 + +## 3.1 - 2022-11-22 + +### What's Changed + +- Bump dependabot/fetch-metadata from 1.3.4 to 1.3.5 by @dependabot in https://github.com/orhanerday/open-ai/pull/28 +- Fix tests by @adetch in https://github.com/orhanerday/open-ai/pull/29 +- Add current completion endpoint by @adetch in https://github.com/orhanerday/open-ai/pull/30 + +### New Contributors + +- @adetch made their first contribution in https://github.com/orhanerday/open-ai/pull/29 + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/3.0...3.1 + +## 3.0 - 2022-11-04 + +### What's Changed + +- List models by @orhanerday in https://github.com/orhanerday/open-ai/pull/22 +- Implement edit feature by @orhanerday in https://github.com/orhanerday/open-ai/pull/23 +- Add Images feature by @orhanerday in https://github.com/orhanerday/open-ai/pull/24 +- Embeddings feature by @orhanerday in https://github.com/orhanerday/open-ai/pull/25 +- Add retrieve file content by @orhanerday in https://github.com/orhanerday/open-ai/pull/26 +- Add deprecated methods by @orhanerday in https://github.com/orhanerday/open-ai/pull/27 + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/2.3...3.0 + +## 2.3 - 2022-11-04 + +### What's Changed + +- Fix documentation for Url Class by @Muchwat in https://github.com/orhanerday/open-ai/pull/18 +- Bump dependabot/fetch-metadata from 1.3.3 to 1.3.4 by @dependabot in https://github.com/orhanerday/open-ai/pull/19 +- feat: Add image generation api by @SheepFromHeaven in https://github.com/orhanerday/open-ai/pull/21 + +### New Contributors + +- @Muchwat made their first contribution in https://github.com/orhanerday/open-ai/pull/18 +- @SheepFromHeaven made their first contribution in https://github.com/orhanerday/open-ai/pull/21 + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/2.2...2.3 + +## 2.2 - 2022-09-15 + +### What's Changed + +- API for content filter, unit testing fixed and added documentation for content filtering by @bashar94 in https://github.com/orhanerday/open-ai/pull/17 + +### New Contributors + +- @bashar94 made their first contribution in https://github.com/orhanerday/open-ai/pull/17 + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/2.1...2.2 + +## 2.1 - 2022-05-29 + +### What's Changed + +- Adding more capabilities by @orhanerday in https://github.com/orhanerday/open-ai/pull/11 +- Files +- Fine-tuning + +### New Contributors + +- @orhanerday made their first contribution in https://github.com/orhanerday/open-ai/pull/11 + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/2.0...2.1 + +## 2.0 - 2022-05-28 + +### What's Changed + +- Orhanerday/open-ai now supports file uploads +- Bump dependabot/fetch-metadata from 1.1.1 to 1.2.0 by @dependabot in https://github.com/orhanerday/open-ai/pull/3 +- Bump dependabot/fetch-metadata from 1.2.0 to 1.2.1 by @dependabot in https://github.com/orhanerday/open-ai/pull/4 +- Bump dependabot/fetch-metadata from 1.2.1 to 1.3.0 by @dependabot in https://github.com/orhanerday/open-ai/pull/5 +- Bump actions/checkout from 2 to 3 by @dependabot in https://github.com/orhanerday/open-ai/pull/6 +- Bump dependabot/fetch-metadata from 1.3.0 to 1.3.1 by @dependabot in https://github.com/orhanerday/open-ai/pull/7 + +### New Contributors + +- @dependabot made their first contribution in https://github.com/orhanerday/open-ai/pull/3 + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/1.1...2.0 + +## 1.1 - 2022-02-01 + +### **Big new** + +- [orhanerday/open-ai](https://github.com/orhanerday/open-ai) now supports PHP 8 + +## What's Changed + +- Remove duplicate entry from the changelog by @johanvanhelden in https://github.com/orhanerday/open-ai/pull/1 +- Allow PHP8 by @mydnic in https://github.com/orhanerday/open-ai/pull/2 + +## New Contributors + +- @johanvanhelden made their first contribution in https://github.com/orhanerday/open-ai/pull/1 +- @mydnic made their first contribution in https://github.com/orhanerday/open-ai/pull/2 + +**Full Changelog**: https://github.com/orhanerday/open-ai/compare/1.0.0...1.1 + +## 1.0.0 - 2021-12-22 + +- initial release diff --git a/www-api/vendor/orhanerday/open-ai/LICENSE.md b/www-api/vendor/orhanerday/open-ai/LICENSE.md new file mode 100644 index 00000000..d71d6bda --- /dev/null +++ b/www-api/vendor/orhanerday/open-ai/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) orhanerday + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/www-api/vendor/orhanerday/open-ai/README.md b/www-api/vendor/orhanerday/open-ai/README.md new file mode 100644 index 00000000..d2c7f792 --- /dev/null +++ b/www-api/vendor/orhanerday/open-ai/README.md @@ -0,0 +1,899 @@ +# OpenAI API Client in PHP + +
+ +
+ +> ### ChatGPT API is currently supported, [click here](#chat-as-known-as-chatgpt-api) for the implementation introductions. + +
+ +*A message from creator,
Thank you for visiting the __@orhanerday/open-ai__ repository! If you find this repository helpful or useful, we encourage you to **star** it +on GitHub. Starring a repository is a way to show your support for the project. It also helps to increase the visibility +of the project and to let the community know that it is valuable. Thanks again for your support and we hope you find the +repository useful!

Orhan* + +
+ +
+ + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/orhanerday/open-ai.svg?style=flat-square)](https://packagist.org/packages/orhanerday/open-ai) +[![Total Downloads](https://img.shields.io/packagist/dt/orhanerday/open-ai.svg?style=flat-square)](https://packagist.org/packages/orhanerday/open-ai) + +
+ +
+ +orhanerday-open-ai-logo + +
+ +
+ +# Featured in + + +[![Jetbrains Blog](https://user-images.githubusercontent.com/22305274/222431781-86591161-ccd5-4889-bd80-97a0fd0fdf0d.png)](https://blog.jetbrains.com/phpstorm/2022/12/php-annotated-december-2022/#:~:text=orhanerday/open%2Dai%20%E2%80%93%20A%20PHP%20SDK%20for%20accessing%20the%20OpenAI%20GPT%2D3%20API) + +[![Laravel News](https://user-images.githubusercontent.com/22305274/222430084-be097d59-e6bc-408d-8adb-7b751d5a05b2.png)](https://laravel-news.com/openai-sdk-for-php) + +[![日思录](https://user-images.githubusercontent.com/22305274/222431699-f3a8a146-e27c-4fe3-8c93-1d762559752f.png)](http://tubring.cn/articles/59) + + + +# Comparison With Other Packages + +| Project Name | Required PHP Version | Description | Type (Official / Community) | Support | +|------------------------|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------| +| **orhanerday/open-ai** | **PHP 7.4+** | **Most downloaded, forked, contributed, huge community supported, and used PHP SDK for OpenAI GPT-3 and DALL-E. It also supports chatGPT-like streaming.** | Community | Available, ([Community driven Discord Server](https://discord.gg/xpGUD528XJ) or personal mail [orhan@duck.com](mailto:orhan@duck.com)) | +| openai-** */c****t | PHP 8.1+ | OpenAI PHP API client. | Community | - | + + +
+ +## About this package + +Fully open-source and secure community-maintained, PHP SDK for accessing the OpenAI GPT-3 API. + +> #### For more information, you can read laravel news [blog post](https://laravel-news.com/openai-sdk-for-php). +> #### Free support is available. [Join our discord server](#join-our-discord-server) +> #### To get started with this package, you'll first want to be familiar with the [OpenAI API documentation](https://beta.openai.com/docs/introduction) and [examples](https://beta.openai.com/examples). Also you can get help from our discord channel that called [#api-support](https://discord.gg/R9CpVUdqQR) + +## News + +- orhanerday/open-ai added to community libraries php [section](https://beta.openai.com/docs/libraries/php). +- orhanerday/open-ai featured + on [PHPStorm blog post](https://blog.jetbrains.com/phpstorm/2022/12/php-annotated-december-2022/#:~:text=orhanerday/open%2Dai%20%E2%80%93%20A%20PHP%20SDK%20for%20accessing%20the%20OpenAI%20GPT%2D3%20API), + thanks JetBrains! + +> Requires PHP 7.4+ + +## Join our discord server + +![Discord Banner 2](https://discordapp.com/api/guilds/1047074572488417330/widget.png?style=banner2) + +[Click here to join the Discord server](https://discord.gg/xpGUD528XJ) + +## Support this project + +As you may know, OpenAI PHP is an open-source project wrapping tool for OpenAI. We rely on the support of our community +to continue developing and maintaining the project, and one way that you can help is by making a donation. + +Donations allow us to cover expenses such as hosting costs(for testing), development tools, and other resources that are +necessary to keep the project running smoothly. Every contribution, no matter how small, helps us to continue improving +OpenAI PHP for everyone. + +If you have benefited from using OpenAI PHP and would like to support its continued development, we would greatly +appreciate a donation of any amount. You can make a donation through; + +* [Buy me a coffee](https://www.buymeacoffee.com/orhane) +* [Patreon](https://patreon.com/orhann) +* [Click here for the Coinbase QR](#btc) **Bitcoin** > 34w2DftWGkDqDbYMixkmdWWMLmaP9uTRz7 +* [Click here for the Coinbase QR](#doge) **Dogecoin** > DHiqcZox9M8kYDn7BkesnN6Z2kJ7dYG9Lc +* [Click here for the Coinbase QR](#eth) **Ethereum** > 0x135E2D5d7AC40c6850f844BA589D68e91a268Ceb + +Thank you for considering a donation to Orhanerday/OpenAI PHP SDK. Your support is greatly appreciated and helps to +ensure that the project can continue to grow and improve. + +*Sincerely,* + +**Orhan Erday** / Creator. + +# Documentation +Please visit https://orhanerday.gitbook.io/openai-php-api-1/ + +# Endpoint Support + +- Chat + - [x] [ChatGPT API](#chat-as-known-as-chatgpt-api) +- Models + - [x] [List models](https://beta.openai.com/docs/api-reference/models/list) + - [x] [Retrieve model](https://beta.openai.com/docs/api-reference/models/retrieve) +- Completions + - [x] [Create completion](https://beta.openai.com/docs/api-reference/completions/create) +- Edits + - [x] [Create edits](https://beta.openai.com/docs/api-reference/edits/create) +- Images + - [x] [Create image](https://beta.openai.com/docs/api-reference/images/create) + - [x] [Create image edit](https://beta.openai.com/docs/api-reference/images/create-edit) + - [x] [Create image variation](https://beta.openai.com/docs/api-reference/images/create-variation) +- Embeddings + - [x] [Create embeddings](https://beta.openai.com/docs/api-reference/embeddings/create) +- Audio + - [x] [Create transcription](https://platform.openai.com/docs/api-reference/audio/create) + - [x] [Create translation](https://platform.openai.com/docs/api-reference/audio/create) +- Files + - [x] [List files](https://beta.openai.com/docs/api-reference/files/list) + - [x] [Upload file](https://beta.openai.com/docs/api-reference/files/upload) + - [x] [Delete file](https://beta.openai.com/docs/api-reference/files/delete) + - [x] [Retrieve file](https://beta.openai.com/docs/api-reference/files/retrieve) + - [x] [Retrieve file content](https://beta.openai.com/docs/api-reference/files/retrieve-content) +- Fine-tunes + - [x] [Create fine-tune (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/create) + - [x] [List fine-tunes (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/list) + - [x] [Retrieve fine-tune (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/retrieve) + - [x] [Cancel fine-tune (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/cancel) + - [x] [List fine-tune events (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/events) + - [x] [Delete fine-tune model (beta)](https://beta.openai.com/docs/api-reference/fine-tunes/delete-model) +- Moderation + - [x] [Create moderation](https://beta.openai.com/docs/api-reference/moderations/create) +- ~~Engines~~ *(deprecated)* + - ~~[List engines](https://beta.openai.com/docs/api-reference/engines/list)~~ + - ~~[Retrieve engine](https://beta.openai.com/docs/api-reference/engines/retrieve)~~ + +## Installation + +You can install the package via composer: + +```bash +composer require orhanerday/open-ai +``` + +## Quick Start ⚡ + +Before you get starting, you should set OPENAI_API_KEY as ENV key, and set OpenAI key as env value with the following +commands; + +_Powershell_ + +```powershell +$Env:OPENAI_API_KEY = "sk-gjtv....." +``` + +_Cmd_ + +```cmd +set OPENAI_API_KEY=sk-gjtv..... +``` + +_Linux or macOS_ + +```shell +export OPENAI_API_KEY=sk-gjtv..... +``` + +> Getting issues while setting up env? Please read +> the [article](https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety) or you can check +> my [StackOverflow answer](https://stackoverflow.com/a/73904271/15196622) for the Windows® ENV setup. + +Create your `index.php` file and paste the following code part into the file. + +```php +chat([ + 'model' => 'gpt-3.5-turbo', + 'messages' => [ + [ + "role" => "system", + "content" => "You are a helpful assistant." + ], + [ + "role" => "user", + "content" => "Who won the world series in 2020?" + ], + [ + "role" => "assistant", + "content" => "The Los Angeles Dodgers won the World Series in 2020." + ], + [ + "role" => "user", + "content" => "Where was it played?" + ], + ], + 'temperature' => 1.0, + 'max_tokens' => 4000, + 'frequency_penalty' => 0, + 'presence_penalty' => 0, +]); + + +var_dump($chat); +echo "
"; +echo "
"; +echo "
"; +// decode response +$d = json_decode($chat); +// Get Content +echo($d->choices[0]->message->content); +``` + +_Run the server with the following command_ + +```shell +php -S localhost:8000 -t . +``` + +## Usage + +### Load your key from an environment variable. + +> According to the following code `$open_ai` is the base variable for all open-ai operations. + +```php +use Orhanerday\OpenAi\OpenAi; + +$open_ai = new OpenAi(env('OPEN_AI_API_KEY')); +``` + +## Requesting organization + +For users who belong to multiple organizations, you can pass a header to specify which organization is used for an API +request. +Usage from these API requests will count against the specified organization's subscription quota. + +````php +$open_ai_key = getenv('OPENAI_API_KEY'); +$open_ai = new OpenAi($open_ai_key); +$open_ai->setORG("org-IKN2E1nI3kFYU8ywaqgFRKqi"); +```` + +## Base URL + +You can specify Origin URL with `setBaseURL()` method; + +````php +$open_ai_key = getenv('OPENAI_API_KEY'); +$open_ai = new OpenAi($open_ai_key,$originURL); +$open_ai->setBaseURL("https://ai.example.com/"); +```` + +## Use Proxy + +You can use some proxy servers for your requests api; + +````php +$open_ai->setProxy("http://127.0.0.1:1086"); +```` + +## Set header + + ```php +$open_ai->setHeader(["Connection"=>"keep-alive"]); +``` + +## Get cURL request info + +> ### !!! WARNING:Your API key will expose if you add this method to your code, therefore remove the method before deployment. Be careful ! +You can get cURL info after the request. + +````php +$open_ai = new OpenAi($open_ai_key); +echo $open_ai->listModels(); // you should execute the request FIRST! +var_dump($open_ai->getCURLInfo()); // You can call the request +```` + +## Chat (as known as ChatGPT API) + +Given a chat conversation, the model will return a chat completion response. + + ```php +$complete = $open_ai->chat([ + 'model' => 'gpt-3.5-turbo', + 'messages' => [ + [ + "role" => "system", + "content" => "You are a helpful assistant." + ], + [ + "role" => "user", + "content" => "Who won the world series in 2020?" + ], + [ + "role" => "assistant", + "content" => "The Los Angeles Dodgers won the World Series in 2020." + ], + [ + "role" => "user", + "content" => "Where was it played?" + ], + ], + 'temperature' => 1.0, + 'max_tokens' => 4000, + 'frequency_penalty' => 0, + 'presence_penalty' => 0, +]); +``` + +## Accessing the Element + +```php +choices[0]->message->content); +``` + +> ### Related: [ChatGPT Clone Project](#chatgpt-clone-project) + +## Completions + +Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of +alternative tokens at each position. + + ```php +$complete = $open_ai->completion([ + 'model' => 'text-davinci-002', + 'prompt' => 'Hello', + 'temperature' => 0.9, + 'max_tokens' => 150, + 'frequency_penalty' => 0, + 'presence_penalty' => 0.6, +]); +``` + +### Stream Example + +This feature might sound familiar from [ChatGPT](https://chat.openai.com/chat). + +
+ +#### ChatGPT Clone Project + +Video of demo: + +https://user-images.githubusercontent.com/22305274/219878695-c76a58c0-5081-402c-a1b5-2b1fd971735a.mp4 + +ChatGPT clone is a simple web application powered by the OpenAI library and built with PHP. It allows users to chat with +an AI language model that responds in real-time. Chat history is saved using cookies, and the project requires the use +of an API key and enabled SQLite3. + +Url of The ChatGPT-Clone Repo https://github.com/orhanerday/ChatGPT + +
+ +Whether to stream back partial progress. If set, tokens will be sent as +data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format) +as they become available, with the stream terminated by a data: [DONE] message. + + ````php +$open_ai = new OpenAi(env('OPEN_AI_API_KEY')); + +$opts = [ + 'prompt' => "Hello", + 'temperature' => 0.9, + "max_tokens" => 150, + "frequency_penalty" => 0, + "presence_penalty" => 0.6, + "stream" => true, +]; + +header('Content-type: text/event-stream'); +header('Cache-Control: no-cache'); + +$open_ai->completion($opts, function ($curl_info, $data) { + echo $data . "

"; + echo PHP_EOL; + ob_flush(); + flush(); + return strlen($data); +}); + +```` + +Add this part inside `` of the HTML + + ````php + +
Hello
+ +```` + +You should see a response like the in video; + +https://user-images.githubusercontent.com/22305274/209847128-f72c9345-dd34-46f0-bbc5-daf1d7b6121f.mp4 + +## Edits + +Creates a new edit for the provided input, instruction, and parameters + + ```php + $result = $open_ai->createEdit([ + "model" => "text-davinci-edit-001", + "input" => "What day of the wek is it?", + "instruction" => "Fix the spelling mistakes", + ]); +``` + +## Images (DALL·E) + +> All DALL·E Examples available in this [repo](https://github.com/orhanerday/DALLE-Examples). + +Given a prompt, the model will return one or more generated images as urls or base64 encoded. + +### Create image + +Creates an image given a prompt. + + ```php +$complete = $open_ai->image([ + "prompt" => "A cat drinking milk", + "n" => 1, + "size" => "256x256", + "response_format" => "url", +]); +``` + +### Create image edit + +Creates an edited or extended image given an original image and a prompt. +> You need HTML upload for image edit or variation? Please +> check [DALL·E Examples](https://github.com/orhanerday/DALLE-Examples) + +````php +$otter = curl_file_create(__DIR__ . './files/otter.png'); +$mask = curl_file_create(__DIR__ . './files/mask.jpg'); + +$result = $open_ai->imageEdit([ + "image" => $otter, + "mask" => $mask, + "prompt" => "A cute baby sea otter wearing a beret", + "n" => 2, + "size" => "1024x1024", +]); +```` + +### Create image variation + +Creates a variation of a given image. + +````php +$otter = curl_file_create(__DIR__ . './files/otter.png'); + +$result = $open_ai->createImageVariation([ + "image" => $otter, + "n" => 2, + "size" => "256x256", +]); +```` + +## Searches + +**_(Deprecated)_** +> This endpoint is deprecated and will be removed on December 3rd, 2022 +> OpenAI developed new methods with better +> performance. [Learn more.](https://help.openai.com/en/articles/6272952-search-transition-guide) + +Given a query and a set of documents or labels, the model ranks each document based on its semantic similarity to the +provided query. + +```php +$search = $open_ai->search([ + 'engine' => 'ada', + 'documents' => ['White House', 'hospital', 'school'], + 'query' => 'the president', +]); +``` + +## Embeddings + +Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. + +Related guide: [Embeddings](https://beta.openai.com/docs/guides/embeddings) + +### Create embeddings + +```php +$result = $open_ai->embeddings([ + "model" => "text-similarity-babbage-001", + "input" => "The food was delicious and the waiter..." +]); +``` + +## Answers + +**_(Deprecated)_** + +> This endpoint is deprecated and will be removed on December 3rd, 2022 +> We’ve developed new methods with better +> performance. [Learn more](https://help.openai.com/en/articles/6233728-answers-transition-guide). + +Given a question, a set of documents, and some examples, the API generates an answer to the question based on the +information in the set of documents. This is useful for question-answering applications on sources of truth, like +company documentation or a knowledge base. + + ```php +$answer = $open_ai->answer([ + 'documents' => ['Puppy A is happy.', 'Puppy B is sad.'], + 'question' => 'which puppy is happy?', + 'search_model' => 'ada', + 'model' => 'curie', + 'examples_context' => 'In 2017, U.S. life expectancy was 78.6 years.', + 'examples' => [['What is human life expectancy in the United States?', '78 years.']], + 'max_tokens' => 5, + 'stop' => ["\n", '<|endoftext|>'], +]); +``` + +## Classifications + +**_(Deprecated)_** +> This endpoint is deprecated and will be removed on December 3rd, 2022 +> OpenAI developed new methods with better +> performance. [Learn more.](https://help.openai.com/en/articles/6272941-classifications-transition-guide) + +Given a query and a set of labeled examples, the model will predict the most likely label for the query. Useful as a +drop-in replacement for any ML classification or text-to-label task. + + ```php +$classification = $open_ai->classification([ + 'examples' => [ + ['A happy moment', 'Positive'], + ['I am sad.', 'Negative'], + ['I am feeling awesome', 'Positive'], + ], + 'labels' => ['Positive', 'Negative', 'Neutral'], + 'query' => 'It is a raining day =>(', + 'search_model' => 'ada', + 'model' => 'curie', +]); +``` + +## Content Moderations + +Given a input text, outputs if the model classifies it as violating OpenAI's content policy. + +```php +$flags = $open_ai->moderation([ + 'input' => 'I want to kill them.' +]); +``` + +Know more about Content Moderations here: [OpenAI Moderations](https://beta.openai.com/docs/api-reference/moderations) + +## List engines + +**_(Deprecated)_** + +> The Engines endpoints are deprecated. +> Please use their replacement, [Models](#list-models), instead. [Learn more](TODO?). + +Lists the currently available engines, and provides basic information about each one such as the owner and availability. + + ```php +$engines = $open_ai->engines(); +``` + +## Audio + +### Create Transcription + +Transcribes audio into the input language. + +```php +$c_file = curl_file_create(__DIR__ . '/files/en-marvel-endgame.m4a'); + +$result = $open_ai->transcribe([ + "model" => "whisper-1", + "file" => $c_file, +]); +``` +#### Response + +```json +{ + "text": "I'm going to use the stones again. Hey, we'd be going in short-handed, you know. Look, he's still got the stones, so... So let's get them. Use them to bring everyone back. Just like that? Yeah, just like that. Even if there's a small chance that we can undo this, I mean, we owe it to everyone who's not in this room to try. If we do this, how do we know it's going to end any differently than it did before? Because before you didn't have me. Hey, little girl, everybody in this room is about that superhero life. And if you don't mind my asking, where the hell have you been all this time? There are a lot of other planets in the universe. But unfortunately, they didn't have you guys. I like this one. Let's go get this son of a bitch." +} +``` + +### Create Translation + +Translates audio into English. + +_I use Turkish voice for translation thanks to famous science YouTuber [Barış Özcan](https://youtu.be/r2dQgdktUJg?t=90)_ + +```php +$c_file = curl_file_create(__DIR__ . '/files/tr-baris-ozcan-youtuber.m4a'); + +$result = $open_ai->translate([ + "model" => "whisper-1", + "file" => $c_file, +]); +``` +#### Response + +```json +{ + "text": "GPT-3. Last month, the biggest leap in the world of artificial intelligence in recent years happened silently. Maybe the biggest leap of all time. GPT-3's beta version was released by OpenAI. When you hear such a sentence, you may think, what kind of leap is this? But be sure, this is the most advanced language model with the most advanced language model with the most advanced language ability. It can answer these artificial intelligence questions, it can translate and even write poetry. Those who have gained access to the API or API of GPT-3 have already started to make very interesting experiments. Let's look at a few examples together. Let's start with an example of aphorism. This site produces beautiful words that you can tweet. Start to actually do things with your words instead of just thinking about them." +} +``` + + #### Need HTML upload for audio? Check [this](#upload-file-with-html-form) section and change api references. Example : + +```php +... + echo $open_ai->translate( + [ + "purpose" => "answers", + "file" => $c_file, + ] + ); +... +// OR +... + echo $open_ai->transcribe( + [ + "purpose" => "answers", + "file" => $c_file, + ] + ); +... +``` + +## Files + +Files are used to upload documents that can be used across features like Answers, Search, and Classifications + +### List files + +Returns a list of files that belong to the user's organization. + +```php +$files = $open_ai->listFiles(); +``` + +### Upload file + +Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the +files uploaded by one organization can be up to 1 GB. Please contact OpenAI if you need to increase the storage limit. + +```php +$c_file = curl_file_create(__DIR__ . 'files/sample_file_1.jsonl'); +$result = $open_ai->uploadFile([ + "purpose" => "answers", + "file" => $c_file, +]); +``` + +### Upload file with HTML Form + +```php +
+ Select file to upload: + + +
+uploadFile( + [ + "purpose" => "answers", + "file" => $c_file, + ] + ); + echo ","; + echo $open_ai->listFiles(); + echo "]"; + +} + +``` + +### Delete file + + ```php +$result = $open_ai->deleteFile('file-xxxxxxxx'); +``` + +### Retrieve file + + ```php +$file = $open_ai->retrieveFile('file-xxxxxxxx'); +``` + +### Retrieve file content + + ```php +$file = $open_ai->retrieveFileContent('file-xxxxxxxx'); +``` + +## Fine-tunes + +Manage fine-tuning jobs to tailor a model to your specific training data. + +### Create fine-tune + + ```php +$result = $open_ai->createFineTune([ + "training_file" => "file-U3KoAAtGsjUKSPXwEUDdtw86", +]); +``` + +### List fine-tune + + ```php +$fine_tunes = $open_ai->listFineTunes(); +``` + +### Retrieve fine-tune + + ```php +$fine_tune = $open_ai->retrieveFineTune('ft-AF1WoRqd3aJAHsqc9NY7iL8F'); +``` + +### Cancel fine-tune + + ```php +$result = $open_ai->cancelFineTune('ft-AF1WoRqd3aJAHsqc9NY7iL8F'); +``` + +### List fine-tune events + + ```php +$fine_tune_events = $open_ai->listFineTuneEvents('ft-AF1WoRqd3aJAHsqc9NY7iL8F'); +``` + +### Delete fine-tune model + + ```php +$result = $open_ai->deleteFineTune('curie:ft-acmeco-2021-03-03-21-44-20'); +``` + +## Retrieve engine + +**_(Deprecated)_** + +Retrieves an engine instance, providing basic information about the engine such as the owner and availability. + + ```php +$engine = $open_ai->engine('davinci'); +``` + +## Models + +List and describe the various models available in the API. + +### List models + +Lists the currently available models, and provides basic information about each one such as the owner and availability. + + ```php +$result = $open_ai->listModels(); +``` + +### Retrieve model + +Retrieves a model instance, providing basic information about the model such as the owner and permissioning. + + ```php +$result = $open_ai->retrieveModel("text-ada-001"); +``` + +## Printing results *i.e.* `$search` + + ```php +echo $search; +``` + +## Testing + +To run all tests: + +```bash +composer test +``` + +To run only those tests that work for most user (exclude those that require a missing folder or that hit deprecated +endpoints no longer available to most users): + +```bash +./vendor/bin/pest --group=working +``` + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. + +## Contributing + +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. + +## Security Vulnerabilities + +Please report security vulnerabilities to [orhanerday@gmail.com](mailto:orhanerday@gmail.com) + +## Credits + +- [Orhan Erday](https://github.com/orhanerday) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. + +## Donation + +Buy Me A Coffee + +#### btc + +![image](https://user-images.githubusercontent.com/22305274/209946578-fc7db433-699c-491f-9f8b-1c962f0b9ea2.png) + +#### eth + +![image](https://user-images.githubusercontent.com/22305274/209946539-24f247d9-68a1-4f46-a18b-62790d943c99.png) + +#### doge + +![image](https://user-images.githubusercontent.com/22305274/209946556-164798d0-e404-4b6c-8669-d63e78f24228.png) diff --git a/www-api/vendor/orhanerday/open-ai/composer.json b/www-api/vendor/orhanerday/open-ai/composer.json new file mode 100644 index 00000000..53d029b8 --- /dev/null +++ b/www-api/vendor/orhanerday/open-ai/composer.json @@ -0,0 +1,50 @@ +{ + "name": "orhanerday/open-ai", + "description": "OpenAI GPT-3 Api Client in PHP", + "keywords": [ + "orhanerday", + "open-ai" + ], + "homepage": "https://github.com/orhanerday/open-ai", + "license": "MIT", + "authors": [ + { + "name": "Orhan Erday", + "email": "orhanerday@gmail.com", + "role": "Developer" + } + ], + "require": { + "php": ">=7.4", + "ext-curl": "*", + "ext-json": "*" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.0", + "pestphp/pest": "^1.20", + "spatie/ray": "^1.28" + }, + "autoload": { + "psr-4": { + "Orhanerday\\OpenAi\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Orhanerday\\OpenAi\\Tests\\": "tests" + } + }, + "scripts": { + "test": "vendor/bin/pest", + "test-coverage": "vendor/bin/pest --coverage", + "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes" + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/www-api/vendor/orhanerday/open-ai/files/en-marvel-endgame.m4a b/www-api/vendor/orhanerday/open-ai/files/en-marvel-endgame.m4a new file mode 100644 index 00000000..6db2074e Binary files /dev/null and b/www-api/vendor/orhanerday/open-ai/files/en-marvel-endgame.m4a differ diff --git a/www-api/vendor/orhanerday/open-ai/files/sample_file_1.jsonl b/www-api/vendor/orhanerday/open-ai/files/sample_file_1.jsonl new file mode 100644 index 00000000..6d26a2d3 --- /dev/null +++ b/www-api/vendor/orhanerday/open-ai/files/sample_file_1.jsonl @@ -0,0 +1,2 @@ +{"text": "puppy A is happy", "metadata": "emotional state of puppy A"} +{"text": "puppy B is sad", "metadata": "emotional state of puppy B"} \ No newline at end of file diff --git a/www-api/vendor/orhanerday/open-ai/files/tr-baris-ozcan-youtuber.m4a b/www-api/vendor/orhanerday/open-ai/files/tr-baris-ozcan-youtuber.m4a new file mode 100644 index 00000000..e87f5415 Binary files /dev/null and b/www-api/vendor/orhanerday/open-ai/files/tr-baris-ozcan-youtuber.m4a differ diff --git a/www-api/vendor/orhanerday/open-ai/openai-elephpant.svg b/www-api/vendor/orhanerday/open-ai/openai-elephpant.svg new file mode 100644 index 00000000..2e932955 --- /dev/null +++ b/www-api/vendor/orhanerday/open-ai/openai-elephpant.svg @@ -0,0 +1 @@ + diff --git a/www-api/vendor/orhanerday/open-ai/src/OpenAi.php b/www-api/vendor/orhanerday/open-ai/src/OpenAi.php new file mode 100644 index 00000000..ffc7a998 --- /dev/null +++ b/www-api/vendor/orhanerday/open-ai/src/OpenAi.php @@ -0,0 +1,563 @@ +contentTypes = [ + "application/json" => "Content-Type: application/json", + "multipart/form-data" => "Content-Type: multipart/form-data", + ]; + + $this->headers = [ + $this->contentTypes["application/json"], + "Authorization: Bearer $OPENAI_API_KEY", + ]; + } + + /** + * @return array + * Remove this method from your code before deploying + */ + public function getCURLInfo() + { + return $this->curlInfo; + } + + /** + * @return bool|string + */ + public function listModels() + { + $url = Url::fineTuneModel(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'GET'); + } + + /** + * @param $model + * @return bool|string + */ + public function retrieveModel($model) + { + $model = "/$model"; + $url = Url::fineTuneModel().$model; + $this->baseUrl($url); + + return $this->sendRequest($url, 'GET'); + } + + /** + * @param $opts + * @return bool|string + * @deprecated + */ + public function complete($opts) + { + $engine = $opts['engine'] ?? $this->engine; + $url = Url::completionURL($engine); + unset($opts['engine']); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @param null $stream + * @return bool|string + * @throws Exception + */ + public function completion($opts, $stream = null) + { + if (array_key_exists('stream', $opts) && $opts['stream']) { + if ($stream == null) { + throw new Exception( + 'Please provide a stream function. Check https://github.com/orhanerday/open-ai#stream-example for an example.' + ); + } + + $this->stream_method = $stream; + } + + $opts['model'] = $opts['model'] ?? $this->model; + $url = Url::completionsURL(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @return bool|string + */ + public function createEdit($opts) + { + $url = Url::editsUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @return bool|string + */ + public function image($opts) + { + $url = Url::imageUrl()."/generations"; + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @return bool|string + */ + public function imageEdit($opts) + { + $url = Url::imageUrl()."/edits"; + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @return bool|string + */ + public function createImageVariation($opts) + { + $url = Url::imageUrl()."/variations"; + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @return bool|string + * @deprecated + */ + public function search($opts) + { + $engine = $opts['engine'] ?? $this->engine; + $url = Url::searchURL($engine); + unset($opts['engine']); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @return bool|string + * @deprecated + */ + public function answer($opts) + { + $url = Url::answersUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @return bool|string + * @deprecated + */ + public function classification($opts) + { + $url = Url::classificationsUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @return bool|string + */ + public function moderation($opts) + { + $url = Url::moderationUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @param null $stream + * @return bool|string + * @throws Exception + */ + public function chat($opts, $stream = null) + { + if ($stream != null && array_key_exists('stream', $opts)) { + if (!$opts['stream']) { + throw new Exception( + 'Please provide a stream function. Check https://github.com/orhanerday/open-ai#stream-example for an example.' + ); + } + + $this->stream_method = $stream; + } + + $opts['model'] = $opts['model'] ?? $this->chatModel; + $url = Url::chatUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @return bool|string + */ + public function transcribe($opts) + { + $url = Url::transcriptionsUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @return bool|string + */ + public function translate($opts) + { + $url = Url::translationsUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param $opts + * @return bool|string + */ + public function uploadFile($opts) + { + $url = Url::filesUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @return bool|string + */ + public function listFiles() + { + $url = Url::filesUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'GET'); + } + + /** + * @param $file_id + * @return bool|string + */ + public function retrieveFile($file_id) + { + $file_id = "/$file_id"; + $url = Url::filesUrl().$file_id; + $this->baseUrl($url); + + return $this->sendRequest($url, 'GET'); + } + + /** + * @param $file_id + * @return bool|string + */ + public function retrieveFileContent($file_id) + { + $file_id = "/$file_id/content"; + $url = Url::filesUrl().$file_id; + $this->baseUrl($url); + + return $this->sendRequest($url, 'GET'); + } + + /** + * @param $file_id + * @return bool|string + */ + public function deleteFile($file_id) + { + $file_id = "/$file_id"; + $url = Url::filesUrl().$file_id; + $this->baseUrl($url); + + return $this->sendRequest($url, 'DELETE'); + } + + /** + * @param $opts + * @return bool|string + */ + public function createFineTune($opts) + { + $url = Url::fineTuneUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @return bool|string + */ + public function listFineTunes() + { + $url = Url::fineTuneUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'GET'); + } + + /** + * @param $fine_tune_id + * @return bool|string + */ + public function retrieveFineTune($fine_tune_id) + { + $fine_tune_id = "/$fine_tune_id"; + $url = Url::fineTuneUrl().$fine_tune_id; + $this->baseUrl($url); + + return $this->sendRequest($url, 'GET'); + } + + /** + * @param $fine_tune_id + * @return bool|string + */ + public function cancelFineTune($fine_tune_id) + { + $fine_tune_id = "/$fine_tune_id/cancel"; + $url = Url::fineTuneUrl().$fine_tune_id; + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST'); + } + + /** + * @param $fine_tune_id + * @return bool|string + */ + public function listFineTuneEvents($fine_tune_id) + { + $fine_tune_id = "/$fine_tune_id/events"; + $url = Url::fineTuneUrl().$fine_tune_id; + $this->baseUrl($url); + + return $this->sendRequest($url, 'GET'); + } + + /** + * @param $fine_tune_id + * @return bool|string + */ + public function deleteFineTune($fine_tune_id) + { + $fine_tune_id = "/$fine_tune_id"; + $url = Url::fineTuneModel().$fine_tune_id; + $this->baseUrl($url); + + return $this->sendRequest($url, 'DELETE'); + } + + /** + * @param + * @return bool|string + * @deprecated + */ + public function engines() + { + $url = Url::enginesUrl(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'GET'); + } + + /** + * @param $engine + * @return bool|string + * @deprecated + */ + public function engine($engine) + { + $url = Url::engineUrl($engine); + $this->baseUrl($url); + + return $this->sendRequest($url, 'GET'); + } + + /** + * @param $opts + * @return bool|string + */ + public function embeddings($opts) + { + $url = Url::embeddings(); + $this->baseUrl($url); + + return $this->sendRequest($url, 'POST', $opts); + } + + /** + * @param int $timeout + */ + public function setTimeout(int $timeout) + { + $this->timeout = $timeout; + } + + /** + * @param string $proxy + */ + public function setProxy(string $proxy) + { + if ($proxy && strpos($proxy, '://') === false) { + $proxy = 'https://'.$proxy; + } + $this->proxy = $proxy; + } + + /** + * @param string $customUrl + * @deprecated + */ + + /** + * @param string $customUrl + * @return void + */ + public function setCustomURL(string $customUrl) + { + if ($customUrl != "") { + $this->customUrl = $customUrl; + } + } + + /** + * @param string $customUrl + * @return void + */ + public function setBaseURL(string $customUrl) + { + if ($customUrl != '') { + $this->customUrl = $customUrl; + } + } + + /** + * @param array $header + * @return void + */ + public function setHeader(array $header) + { + if ($header) { + foreach ($header as $key => $value) { + $this->headers[$key] = $value; + } + } + } + + /** + * @param string $org + */ + public function setORG(string $org) + { + if ($org != "") { + $this->headers[] = "OpenAI-Organization: $org"; + } + } + + /** + * @param string $url + * @param string $method + * @param array $opts + * @return bool|string + */ + private function sendRequest(string $url, string $method, array $opts = []) + { + $post_fields = json_encode($opts); + + if (array_key_exists('file', $opts) || array_key_exists('image', $opts)) { + $this->headers[0] = $this->contentTypes["multipart/form-data"]; + $post_fields = $opts; + } else { + $this->headers[0] = $this->contentTypes["application/json"]; + } + $curl_info = [ + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => $this->timeout, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => $method, + CURLOPT_POSTFIELDS => $post_fields, + CURLOPT_HTTPHEADER => $this->headers, + ]; + + if ($opts == []) { + unset($curl_info[CURLOPT_POSTFIELDS]); + } + + if (!empty($this->proxy)) { + $curl_info[CURLOPT_PROXY] = $this->proxy; + } + + if (array_key_exists('stream', $opts) && $opts['stream']) { + $curl_info[CURLOPT_WRITEFUNCTION] = $this->stream_method; + } + + $curl = curl_init(); + + curl_setopt_array($curl, $curl_info); + $response = curl_exec($curl); + + $info = curl_getinfo($curl); + $this->curlInfo = $info; + + curl_close($curl); + + return $response; + } + + /** + * @param string $url + */ + private function baseUrl(string &$url) + { + if ($this->customUrl != "") { + $url = str_replace(Url::ORIGIN, $this->customUrl, $url); + } + } +} diff --git a/www-api/vendor/orhanerday/open-ai/src/Url.php b/www-api/vendor/orhanerday/open-ai/src/Url.php new file mode 100644 index 00000000..7716a37e --- /dev/null +++ b/www-api/vendor/orhanerday/open-ai/src/Url.php @@ -0,0 +1,163 @@ +