Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni authored and Toni committed Dec 4, 2023
1 parent 7346603 commit df93959
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -77,4 +78,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
49 changes: 46 additions & 3 deletions tests/OllamaTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
<?php

it('will not use debugging functions')
->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();
});

0 comments on commit df93959

Please sign in to comment.