-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c77200c
Showing
29 changed files
with
832 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/examples export-ignore | ||
/tests export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/phpstan.neon.dist export-ignore | ||
/phpunit.xml.dist export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: Continuous Integration | ||
on: [push] | ||
|
||
jobs: | ||
linter: | ||
name: Code Style | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.1 | ||
coverage: xdebug | ||
- name: Get Composer Cache Directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
- name: Cache dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
- name: Install Dependencies | ||
run: composer install --no-progress | ||
- name: Run php-cs-fixture | ||
run: vendor/bin/php-cs-fixer fix -v --dry-run | ||
|
||
phpstan: | ||
name: Static analysis | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.1 | ||
coverage: xdebug | ||
- name: Get Composer Cache Directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
- name: Cache dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
- name: Install Dependencies | ||
run: composer install --no-progress | ||
- name: Run phpstan | ||
run: vendor/bin/phpstan | ||
|
||
phpunit: | ||
name: Unit Tests | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: ['8.1', '8.2', '8.3'] | ||
flags: ['', '--prefer-lowest', '--prefer-stable'] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: xdebug | ||
- name: Get Composer Cache Directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
- name: Cache dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ runner.os }}-composer- | ||
- name: Install Dependencies | ||
run: composer update --prefer-dist --no-interaction --optimize-autoloader --prefer-stable --no-progress $COMPOSER_FLAGS | ||
env: | ||
COMPOSER_FLAGS: ${{ matrix.flags }} | ||
- name: Run PHPUnit | ||
run: vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor/ | ||
.php-cs-fixer.cache | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in(__DIR__) | ||
->exclude('vendor') | ||
; | ||
|
||
$config = new PhpCsFixer\Config(); | ||
$config | ||
->setRiskyAllowed(true) | ||
->setRules([ | ||
'@PSR2' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'declare_strict_types' => true, | ||
'function_declaration' => ['closure_function_spacing' => 'none'], | ||
'single_import_per_statement' => false, | ||
]) | ||
->setFinder($finder) | ||
; | ||
|
||
return $config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
define printSection | ||
@printf "\033[36m\n==================================================\n\033[0m" | ||
@printf "\033[36m $1 \033[0m" | ||
@printf "\033[36m\n==================================================\n\033[0m" | ||
endef | ||
|
||
.PHONY: cs | ||
cs: | ||
$(call printSection,CODE STYLE) | ||
vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --diff | ||
|
||
.PHONY: cs-fix | ||
cs-fix: | ||
vendor/bin/php-cs-fixer fix | ||
|
||
.PHONY: cs-ci | ||
cs-ci: | ||
$(call printSection,CODE STYLE) | ||
vendor/bin/php-cs-fixer fix --ansi --dry-run --using-cache=no --verbose | ||
|
||
.PHONY: phpstan | ||
phpstan: | ||
$(call printSection,PHPSTAN) | ||
vendor/bin/phpstan analyse -c phpstan.neon --ansi --no-progress --no-interaction | ||
|
||
.PHONY: phpunit | ||
phpunit: | ||
$(call printSection,PHPUNIT) | ||
vendor/bin/phpunit | ||
|
||
.PHONY: phpunit-coverage | ||
phpunit-coverage: | ||
$(call printSection,PHPUNIT COVERAGE) | ||
vendor/bin/phpunit --coverage-text | ||
|
||
.PHONY: clean-vendor | ||
clean-vendor: | ||
$(call printSection,CLEAN-VENDOR) | ||
rm -f composer.lock | ||
rm -rf vendor | ||
|
||
.PHONY: composer-install | ||
composer-install: vendor/composer/installed.json | ||
|
||
vendor/composer/installed.json: | ||
$(call printSection,COMPOSER INSTALL) | ||
composer --no-interaction install --ansi --no-progress --prefer-dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Ollama PHP Client | ||
================= | ||
|
||
This is a PHP client for the Ollama API. | ||
|
||
## Getting Started | ||
|
||
``` | ||
$ composer require jdecool/ollama-client | ||
``` | ||
|
||
## Usage | ||
|
||
```php | ||
use JDecool\OllamaClient\ClientBuilder; | ||
|
||
$builder = new ClientBuilder(); | ||
$client = $builder->create(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "jdecool/ollama-client", | ||
"description": "Ollama PHP API client", | ||
"license": "MIT", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "Jérémy DECOOL", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=8.1", | ||
"psr/log": "^3.0", | ||
"symfony/http-client": "^5.4 || ^6.0 || ^7.0" | ||
}, | ||
"require-dev": { | ||
"ergebnis/composer-normalize": "^2.41", | ||
"friendsofphp/php-cs-fixer": "^3.47", | ||
"nyholm/psr7": "^1.8", | ||
"php-http/guzzle7-adapter": "^1.0", | ||
"php-http/mock-client": "^1.6", | ||
"phpstan/phpstan": "^1.10", | ||
"phpunit/phpunit": "^10.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"JDecool\\OllamaClient\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"JDecool\\OllamaClient\\Tests\\": "tests/" | ||
} | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"ergebnis/composer-normalize": true, | ||
"php-http/discovery": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM tinyllama | ||
SYSTEM "You are mario from super mario bros." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
require __DIR__.'/../vendor/autoload.php'; | ||
|
||
use JDecool\OllamaClient\ClientBuilder; | ||
use JDecool\OllamaClient\Model\Message; | ||
use JDecool\OllamaClient\Model\Request\ChatRequest; | ||
|
||
$builder = new ClientBuilder(); | ||
$client = $builder->create(); | ||
|
||
$request = new ChatRequest('tinyllama', [ | ||
new Message('user', 'Why is the sky blue?'), | ||
]); | ||
|
||
// sync | ||
var_dump($client->chat($request)); | ||
|
||
// async | ||
foreach ($client->chatStream($request) as $chunk) { | ||
var_dump($chunk); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php declare(strict_types=1); | ||
|
||
require __DIR__.'/../vendor/autoload.php'; | ||
|
||
use JDecool\OllamaClient\ClientBuilder; | ||
use JDecool\OllamaClient\Model\Request\CreateRequest; | ||
|
||
$builder = new ClientBuilder(); | ||
|
||
$client = $builder->create(); | ||
|
||
$modelFile = <<<MODEL | ||
FROM tinyllama | ||
SYSTEM "You are mario from super mario bros." | ||
MODEL; | ||
|
||
// stream | ||
$request = new CreateRequest('foo', $modelFile); | ||
foreach ($client->createStream($request) as $chunk) { | ||
var_dump($chunk); | ||
} | ||
|
||
// sync | ||
$request = CreateRequest::fromFile('foo', __DIR__.'/Modelfile'); | ||
$client->create($request); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php declare(strict_types=1); | ||
|
||
require __DIR__.'/../vendor/autoload.php'; | ||
|
||
use JDecool\OllamaClient\ClientBuilder; | ||
use JDecool\OllamaClient\Model\Request\PullRequest; | ||
|
||
$builder = new ClientBuilder(); | ||
|
||
$client = $builder->create(); | ||
|
||
$request = new PullRequest('tinyllama'); | ||
|
||
// sync | ||
$client->pullStream($request); | ||
|
||
// stream | ||
foreach ($client->pullStream($request) as $chunk) { | ||
var_dump($chunk); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
parameters: | ||
level: max | ||
paths: | ||
- examples | ||
- src | ||
- tests | ||
|
||
checkMissingIterableValueType: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php"> | ||
<testsuites> | ||
<testsuite name="Ollama Client"> | ||
<directory>tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory>./src/</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
Oops, something went wrong.