From df93959f9a634ed2fea39303b1635a8978420ba8 Mon Sep 17 00:00:00 2001 From: Toni Date: Mon, 4 Dec 2023 17:22:47 +0100 Subject: [PATCH] add tests --- composer.json | 7 ++++--- tests/OllamaTest.php | 49 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 4c4be96..8a5ce6d 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,9 @@ ], "require": { "php": "^8.1", - "spatie/laravel-package-tools": "^1.14.0", - "illuminate/contracts": "^10.0" + "guzzlehttp/guzzle": "^7.8", + "illuminate/contracts": "^10.0", + "spatie/laravel-package-tools": "^1.14.0" }, "require-dev": { "laravel/pint": "^1.0", @@ -77,4 +78,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} \ No newline at end of file +} diff --git a/tests/OllamaTest.php b/tests/OllamaTest.php index ccc19b2..456f627 100644 --- a/tests/OllamaTest.php +++ b/tests/OllamaTest.php @@ -1,5 +1,48 @@ expect(['dd', 'dump', 'ray']) - ->each->not->toBeUsed(); +use Cloudstudio\Ollama\Ollama; +use Cloudstudio\Ollama\Services\ModelService; + +beforeEach(function () { + $this->ollama = new Ollama(new ModelService()); +}); + +it('will not use debugging functions', function () { + expect(['dd', 'dump', 'ray'])->each->not->toBeUsed(); +}); + +it('sets properties correctly and returns instance', function ($method, $value) { + expect($this->ollama->$method($value))->toBeInstanceOf(Ollama::class); +})->with([ + 'agent' => ['agent', 'Act as Bill Gates'], + 'prompt' => ['prompt', 'Who are you?'], + 'model' => ['model', 'llama2'], + 'format' => ['format', 'json'], + 'options' => ['options', ['temperature' => 0.7]], + 'stream' => ['stream', true], + 'raw' => ['raw', true], +]); + +it('correctly processes ask method with real API call', function () { + $response = $this->ollama->agent('You are a weather expert...') + ->prompt('Why is the sky blue? answer only in 4 words') + ->model('llama2') + ->options(['temperature' => 0.8]) + ->stream(false) + ->ask(); + + expect($response)->toBeArray(); +}); + +it('lists available local models', function () { + $models = $this->ollama->models(); + expect($models)->toBeArray(); +}); + +it('shows information about the selected model', function () { + $models = $this->ollama->models(); + $model = $models['models'][0]; + $this->ollama->model($model['name']); + $info = $this->ollama->show(); + expect($info)->toBeArray(); +});