Skip to content

Commit 763ff05

Browse files
committed
feat: first version
0 parents  commit 763ff05

19 files changed

+552
-0
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
insert_final_newline = true
10+
indent_style = space
11+
indent_size = 4
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false
16+
17+
[*.yml]
18+
indent_size = 2

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/art export-ignore
2+
/docs export-ignore
3+
/tests export-ignore
4+
/scripts export-ignore
5+
/.github export-ignore
6+
/.php_cs export-ignore
7+
.editorconfig export-ignore
8+
.gitattributes export-ignore
9+
.gitignore export-ignore
10+
phpstan.neon.dist export-ignore
11+
phpunit.xml.dist export-ignore
12+
CHANGELOG.md export-ignore
13+
CONTRIBUTING.md export-ignore
14+
README.md export-ignore

.github/FUNDING.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# These are supported funding model platforms
2+
3+
github: nunomaduro
4+
patreon: nunomaduro
5+
custom: https://www.paypal.com/paypalme/enunomaduro

.github/workflows/formats.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Formats
2+
3+
on: ['push', 'pull_request']
4+
5+
jobs:
6+
ci:
7+
runs-on: ${{ matrix.os }}
8+
9+
strategy:
10+
fail-fast: true
11+
matrix:
12+
os: [ubuntu-latest]
13+
php: [8.2]
14+
dependency-version: [prefer-lowest, prefer-stable]
15+
16+
name: Formats P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
17+
18+
steps:
19+
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
23+
- name: Cache dependencies
24+
uses: actions/cache@v1
25+
with:
26+
path: ~/.composer/cache/files
27+
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
28+
29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: ${{ matrix.php }}
33+
extensions: dom, mbstring, zip
34+
tools: prestissimo
35+
coverage: pcov
36+
37+
- name: Install Composer dependencies
38+
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
39+
40+
- name: Coding Style Checks
41+
run: composer test:lint
42+
43+
- name: Type Checks
44+
run: composer test:types

.github/workflows/tests.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Tests
2+
3+
on: ['push', 'pull_request']
4+
5+
jobs:
6+
ci:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
os: [ubuntu-latest, macos-latest, windows-latest]
12+
php: [8.1, 8.2]
13+
dependency-version: [prefer-lowest, prefer-stable]
14+
15+
name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
16+
17+
steps:
18+
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
22+
- name: Cache dependencies
23+
uses: actions/cache@v1
24+
with:
25+
path: ~/.composer/cache/files
26+
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
27+
28+
- name: Setup PHP
29+
uses: shivammathur/setup-php@v2
30+
with:
31+
php-version: ${{ matrix.php }}
32+
extensions: dom, mbstring, zip
33+
coverage: none
34+
35+
- name: Install Composer dependencies
36+
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
37+
38+
- name: Integration Tests
39+
run: php ./vendor/bin/pest

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.phpunit.result.cache
2+
/.php-cs-fixer.cache
3+
/.php-cs-fixer.php
4+
/composer.lock
5+
/phpunit.xml
6+
/vendor/
7+
*.swp
8+
*.swo

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
## [0.2]
8+
- Adds first version

CONTRIBUTING.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# CONTRIBUTING
2+
3+
Contributions are welcome, and are accepted via pull requests.
4+
Please review these guidelines before submitting any pull requests.
5+
6+
## Process
7+
8+
1. Fork the project
9+
1. Create a new branch
10+
1. Code, test, commit and push
11+
1. Open a pull request detailing your changes. Make sure to follow the [template](.github/PULL_REQUEST_TEMPLATE.md)
12+
13+
## Guidelines
14+
15+
* Please ensure the coding style running `composer lint`.
16+
* Send a coherent commit history, making sure each individual commit in your pull request is meaningful.
17+
* You may need to [rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) to avoid merge conflicts.
18+
* Please remember that we follow [SemVer](http://semver.org/).
19+
20+
## Setup
21+
22+
Clone your fork, then install the dev dependencies:
23+
```bash
24+
composer install
25+
```
26+
## Lint
27+
28+
Lint your code:
29+
```bash
30+
composer lint
31+
```
32+
## Tests
33+
34+
Run all tests:
35+
```bash
36+
composer test
37+
```
38+
39+
Check types:
40+
```bash
41+
composer test:types
42+
```
43+
44+
Unit tests:
45+
```bash
46+
composer test:unit
47+
```

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Nuno Maduro <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<p align="center">
2+
<img src="https://raw.githubusercontent.com/openai-php/laravel/main/art/example.png" width="600" alt="OpenAI PHP">
3+
<p align="center">
4+
<a href="https://github.com/openai-php/laravel/actions"><img alt="GitHub Workflow Status (master)" src="https://img.shields.io/github/workflow/status/openai-php/laravel/Tests/main"></a>
5+
<a href="https://packagist.org/packages/openai-php/laravel"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/openai-php/laravel"></a>
6+
<a href="https://packagist.org/packages/openai-php/laravel"><img alt="Latest Version" src="https://img.shields.io/packagist/v/openai-php/laravel"></a>
7+
<a href="https://packagist.org/packages/openai-php/laravel"><img alt="License" src="https://img.shields.io/github/license/openai-php/laravel"></a>
8+
</p>
9+
</p>
10+
11+
------
12+
**OpenAI PHP** for Laravel is a supercharged PHP API client that allows you to interact with the [Open AI API](https://beta.openai.com/docs/api-reference/introduction).
13+
14+
> **Note:** This repository contains the integration code of the **OpenAI PHP** for Laravel. If you want to use the **OpenAI PHP** client in a framework-agnostic way, take a look at the [openai-php/client](https://github.com/openai-php/client) repository.
15+
16+
## Get Started
17+
18+
> **Requires [PHP 8.1+](https://php.net/releases/)**
19+
20+
First, install OpenAI via the [Composer](https://getcomposer.org/) package manager:
21+
22+
```bash
23+
composer require openai-php/laravel
24+
```
25+
26+
Next, publish the configuration file:
27+
28+
```bash
29+
php artisan vendor:publish --provider="OpenAI\Laravel\ServiceProvider"
30+
```
31+
32+
This will create a `config/openai.php` configuration file in your project, which you can modify to your needs
33+
using environment variables:
34+
35+
```env
36+
OPENAI_API_KEY=sk-...
37+
```
38+
39+
Finally, you may use the `OpenAI` facade to access the OpenAI API:
40+
41+
```php
42+
$client = OpenAI::completions()->create([
43+
'model' => 'text-davinci-003',
44+
'prompt' => 'PHP is',
45+
]);
46+
47+
echo $result['choices'][0]['text']; // an open-source, widely-used, server-side scripting language.
48+
```
49+
50+
## Usage
51+
52+
For usage examples, take a look at the [openai-php/client](https://github.com/openai-php/client) repository.
53+
54+
---
55+
56+
OpenAI PHP for Laravel is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.

composer.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "openai-php/laravel",
3+
"description": "OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API",
4+
"keywords": ["laravel","php", "openai", "sdk", "codex", "GPT-3", "DALL-E", "api", "client", "natural", "language", "processing"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Nuno Maduro",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": "^8.1.0",
14+
"laravel/framework": "^9.45.1",
15+
"openai-php/client": "^0.2.1"
16+
},
17+
"require-dev": {
18+
"laravel/pint": "^1.3",
19+
"pestphp/pest": "^2.0.0",
20+
"pestphp/pest-plugin-mock": "^2.0.0",
21+
"phpstan/phpstan": "^1.9.4",
22+
"symfony/var-dumper": "^6.2.2"
23+
},
24+
"autoload": {
25+
"psr-4": {
26+
"OpenAI\\Laravel\\": "src/"
27+
}
28+
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"Tests\\": "tests/"
32+
}
33+
},
34+
"minimum-stability": "dev",
35+
"prefer-stable": true,
36+
"config": {
37+
"sort-packages": true,
38+
"preferred-install": "dist",
39+
"allow-plugins": {
40+
"pestphp/pest-plugin": true
41+
}
42+
},
43+
"scripts": {
44+
"lint": "pint -v",
45+
"refactor": "rector --debug",
46+
"test:lint": "pint --test -v",
47+
"test:types": "phpstan analyse --ansi",
48+
"test:unit": "pest --colors=always",
49+
"test": [
50+
"@test:lint",
51+
"@test:types",
52+
"@test:unit"
53+
]
54+
}
55+
}

config/openai.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| OpenAI API Key and Organization
8+
|--------------------------------------------------------------------------
9+
|
10+
| Here you may specify your OpenAI API Key and organization. This will be
11+
| used to authenticate with the OpenAI API - you can find your API key
12+
| and organization on your OpenAI dashboard, at https://openai.com.
13+
|
14+
| Supported: "algolia", "meilisearch", "database", "collection", "null"
15+
|
16+
*/
17+
18+
'api_key' => env('OPENAI_API_KEY'),
19+
'organization' => env('OPENAI_ORGANIZATION'),
20+
21+
];

phpstan.neon.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
level: max
3+
paths:
4+
- src
5+
6+
reportUnmatchedIgnoredErrors: true

phpunit.xml.dist

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
backupGlobals="false"
4+
beStrictAboutTestsThatDoNotTestAnything="true"
5+
beStrictAboutOutputDuringTests="true"
6+
bootstrap="vendor/autoload.php"
7+
cacheResult="false"
8+
colors="true"
9+
failOnRisky="true"
10+
failOnWarning="true"
11+
processIsolation="false"
12+
stopOnError="false"
13+
stopOnFailure="false"
14+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
15+
cacheDirectory=".phpunit.cache"
16+
backupStaticProperties="false"
17+
displayDetailsOnIncompleteTests="true"
18+
displayDetailsOnSkippedTests="true"
19+
displayDetailsOnTestsThatTriggerDeprecations="true"
20+
displayDetailsOnTestsThatTriggerErrors="true"
21+
displayDetailsOnTestsThatTriggerNotices="true"
22+
displayDetailsOnTestsThatTriggerWarnings="true"
23+
>
24+
<testsuites>
25+
<testsuite name="Default Test Suite">
26+
<directory suffix=".php">./tests</directory>
27+
</testsuite>
28+
</testsuites>
29+
<coverage>
30+
<include>
31+
<directory suffix=".php">./src</directory>
32+
</include>
33+
</coverage>
34+
</phpunit>

0 commit comments

Comments
 (0)