{"id":21831598,"url":"https://github.com/capevace/laravel-gpt","last_synced_at":"2025-04-14T07:11:52.712Z","repository":{"id":64709274,"uuid":"577640164","full_name":"Capevace/laravel-gpt","owner":"Capevace","description":"A Laravel package for interacting with OpenAI's GPT-3 API with full type annotations.","archived":false,"fork":false,"pushed_at":"2023-10-09T15:04:55.000Z","size":251,"stargazers_count":13,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T00:12:27.577Z","etag":null,"topics":["ai","gpt","gpt-3","laravel","laravel-package","openai","php","php-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Capevace.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-13T07:34:25.000Z","updated_at":"2024-04-16T18:22:56.000Z","dependencies_parsed_at":"2023-02-01T03:15:48.211Z","dependency_job_id":null,"html_url":"https://github.com/Capevace/laravel-gpt","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Capevace%2Flaravel-gpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Capevace%2Flaravel-gpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Capevace%2Flaravel-gpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Capevace%2Flaravel-gpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Capevace","download_url":"https://codeload.github.com/Capevace/laravel-gpt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837287,"owners_count":21169374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","gpt","gpt-3","laravel","laravel-package","openai","php","php-library"],"created_at":"2024-11-27T19:12:05.982Z","updated_at":"2025-04-14T07:11:52.684Z","avatar_url":"https://github.com/Capevace.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\t\u003ca href=\"https://github.com/capevace/laravel-gpt\"\u003e\n\t\t\u003cimg src=\"https://user-images.githubusercontent.com/10093858/207289815-1656ca5a-9473-4c32-a099-35f20ff0f60c.png\" width=\"200\"\u003e\n\t\u003c/a\u003e\n\t\u003ch1\u003elaravel-gpt\u003c/h1\u003e\n\t\u003cp\u003e\n\t\tThis package provides a \u003cstrong\u003etype-safe\u003c/strong\u003e interface for making requests to the \u003ca href=\"https://beta.openai.com/docs/api-reference/introduction\"\u003eGPT-3 API\u003c/a\u003e.\n\t\u003c/p\u003e\n\t\u003cp\u003e\n\t\t\u003ca href=\"https://packagist.org/packages/capevace/laravel-gpt\"\u003e\n            \u003cimg src=\"https://img.shields.io/packagist/v/capevace/laravel-gpt.svg?style=flat-square\" alt=\"Latest Version on Packagist\" /\u003e\n        \u003c/a\u003e\n        \u003ca href=\"https://github.com/capevace/laravel-gpt/actions?query=workflow%3Arun-tests+branch%3Amain\"\u003e\n            \u003cimg src=\"https://img.shields.io/github/workflow/status/capevace/laravel-gpt/run-tests?label=tests\" alt=\"GitHub Tests Action Status\" /\u003e\n        \u003c/a\u003e\n        \u003ca href=\"https://packagist.org/packages/capevace/laravel-gpt\"\u003e\n            \u003cimg src=\"https://img.shields.io/packagist/dt/capevace/laravel-gpt.svg?style=flat-square\" alt=\"Total Downloads\" /\u003e\n        \u003c/a\u003e\n\t\u003c/p\u003e\n\u003c/div\u003e\n\n```php\nuse Capevace\\GPT\\Facades\\GPT;\n\n$response = GPT::generate(\n    'Name a thing that is blue.',\n    model: 'text-davinci-003',\n    maxTokens: 400,\n    frequencyPenalty: 1.0,\n);\n\necho $response-\u003efirst(); // \"The sky\"\n```\n\n\u003cbr /\u003e\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require capevace/laravel-gpt\n```\n\n\u003cbr /\u003e\n\n## Configuration\n\nYou will need an API key for the OpenAI GPT-3 API. Once you have obtained an API key, you can configure it in your .env file by adding the following line:\n\n```bash\nOPENAI_API_KEY=your-api-key-here\n```\n\nYou could also publish the config file directly, **but this really probably isn't necessary**:\n\n```bash\nphp artisan vendor:publish --tag=\"laravel-gpt-config\"\n```\n\n\u003cbr /\u003e\n\n## Usage\n\nThe `Capevace\\GPT\\GPTService` class provides methods for making requests to the GPT-3 API. You can inject it into controllers or use the Facade to access the container.\n\n```php\n# Access via injection\n\nuse Capevace\\GPT\\GPTService;\n\nclass MyController extends Controller {\n    protected GPTService $gpt;\n\n    public function __construct(GPTService $gpt) {\n        $this-\u003egpt = $gpt;\n    }\n\n    public function index() {\n        $this-\u003egpt-\u003egenerate(\n            // ..\n        );\n    }\n\n}\n\n# Access via Facade\n\nuse Capevace\\GPT\\Facades\\GPT;\n\nGPT::generate(/* .. */);\n```\n\n\u003cbr /\u003e\n\n### GPT::generate(_\\\u003cprompt\\\u003e_, _[...options]_)\n\nThe `generate` method returns a `GPTResponse` object that contains the response from the GPT-3 API. If no text is returned (empty string), the method will throw an error.\n\n`generate` takes the following arguments:\n\n-   `prompt` (required): the prompt to send to the GPT-3 API\n-   `model`: the GPT-3 model to use (defaults to text-davinci-003)\n-   `temperature`: a value between 0 and 1 that determines how \"creative\" the response will be (defaults to 0.83)\n-   `maxTokens`: the maximum number of tokens (i.e., words) to return in the response (defaults to 1200)\n-   `stop`: a string that, when encountered in the response, will cause the response to end (defaults to null)\n-   `frequencyPenalty`: a value between 0 and 1 that determines how much the model will penalize frequent words (defaults to 0.11)\n-   `presencePenalty`: a value between 0 and 1 that determines how much the model will penalize words that don't appear in the prompt (defaults to 0.03)\n\n#### Example\n\n```php\nuse Capevace\\GPT\\Facades\\GPT;\n\n$response = GPT::generate(\n    'Generate a list of things that are blue.',\n    model: 'text-davinci-003',\n    maxTokens: 400,\n    frequencyPenalty: 1.0,\n);\n```\n\n\u003cbr /\u003e\n\n### Handling responses\n\nThe `generate` method returns a `GPTResponse` object that contains the response from the GPT-3 API.\n\nIt has two methods:\n\n-   `$response-\u003efirst()` (_string_): returns the first text suggested by GPT-3\n-   `$response-\u003eall()` (_array_): returns a list of all the text choices suggested by GPT-3\n\n#### Example\n\n```php\nuse Capevace\\GPT\\Facades\\GPT;\n\n$response = GPT::generate(\n    'Name a thing that is blue.',\n    model: 'text-davinci-003',\n    maxTokens: 400,\n    frequencyPenalty: 1.0,\n);\n\n$firstChoice = $response-\u003efirst(); // \"the sky\"\n\n$allChoices = $response-\u003eall(); // [\"the sky\", \"the ocean\" ...]\n```\n\n\u003cbr /\u003e\n\n### Error handling\n\nIf an error occurs while making a request to the GPT-3 API, the `generate()` method will throw a `Capevace\\GPT\\Support\\GPTException` exception.\n\n`laravel-gpt` will also throw an error, if a response does not contain any text (empty string).\n\n#### Example\n\n```php\nuse Capevace\\GPT\\Facades\\GPT;\nuse Capevace\\GPT\\Support\\GPTException;\nuse Exception;\n\ntry {\n    $response = GPT::generate('Do nothing.');\n} catch (GPTException $e) {\n    // Exception will be thrown, as the response text is \"\"\n} catch (Exception $e) {\n    // Catch connectivity errors etc.\n}\n```\n\n\u003cbr /\u003e\n\n---\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapevace%2Flaravel-gpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcapevace%2Flaravel-gpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapevace%2Flaravel-gpt/lists"}