Skip to content

Commit 7fba7a3

Browse files
committed
Init OpenAI Symfony Bundle
0 parents  commit 7fba7a3

File tree

18 files changed

+458
-0
lines changed

18 files changed

+458
-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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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]
12+
php: [8.1, 8.2]
13+
symfony: [5.4.*, 6.2.*]
14+
dependency-version: [prefer-lowest, prefer-stable]
15+
16+
name: Tests P${{ matrix.php }} - SF${{ matrix.symfony }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
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 }}-SF${{ matrix.symfony }}-${{ matrix.dependency-version }}-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: Require Symfony Version
36+
run: >
37+
composer require
38+
"symfony/config:${{ matrix.symfony }}"
39+
"symfony/dependency-injection:${{ matrix.symfony }}"
40+
"symfony/http-kernel:${{ matrix.symfony }}"
41+
--no-interaction --no-update
42+
- name: Install Composer dependencies
43+
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
44+
45+
- name: Integration Tests
46+
run: php ./vendor/bin/simple-phpunit

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.phpunit.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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
## v0.3.4 (2023-03-04)
8+
### Added
9+
- 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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
**OpenAI PHP** for Symfony is a supercharged community PHP API client that allows you to interact with the [Open AI API](https://beta.openai.com/docs/api-reference/introduction).
2+
3+
> **Note:** This repository contains the integration code of the **OpenAI PHP** for Symfony. 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.
4+
5+
## Get Started
6+
7+
> **Requires [PHP 8.1+](https://php.net/releases/)**
8+
9+
First, install OpenAI via the [Composer](https://getcomposer.org/) package manager:
10+
11+
```bash
12+
composer require openai-php/symfony
13+
```
14+
15+
Next, register the bundle in your `config/bundles.php`:
16+
17+
```php
18+
return [
19+
// ...
20+
OpenAI\Symfony\OpenAIBundle::class => ['all' => true],
21+
]
22+
```
23+
24+
This will create a `.env` configuration file in your project, which you can modify to your needs
25+
using environment variables:
26+
27+
```env
28+
OPENAI_API_KEY=sk-...
29+
```
30+
31+
Finally, you may use the `openai` service to access the OpenAI API:
32+
33+
```php
34+
$result = $container->get('openai')->completions()->create([
35+
'model' => 'text-davinci-003',
36+
'prompt' => 'PHP is',
37+
]);
38+
39+
echo $result['choices'][0]['text']; // an open-source, widely-used, server-side scripting language.
40+
```
41+
42+
## Usage
43+
44+
For usage examples, take a look at the [openai-php/client](https://github.com/openai-php/client) repository.
45+
46+
---
47+
48+
OpenAI PHP for Symfony is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.

0 commit comments

Comments
 (0)