-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientTest.php
71 lines (57 loc) · 1.92 KB
/
ClientTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
require __DIR__ . '/../vendor/autoload.php';
use Ay4t\RestClient\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Exception\RequestException;
use PHPUnit\Framework\TestCase;
use Ay4t\RestClient\Abstracts\AbstractClient;
use Ay4t\RestClient\Config\Config;
use Ay4t\RestClient\Traits\RequestTrait;
class ClientTest extends TestCase
{
private $client;
private $mockHandler;
private $handlerStack;
/* api endpoint Ollama LLM */
private $base_url_test = 'http://127.0.0.1:8080';
/**
* __construct
* @return parent::__construct()
*/
public function init()
{
$this->mockHandler = new MockHandler();
$this->handlerStack = HandlerStack::create($this->mockHandler);
$config = new Config('api_key_panjang_sampai_10_karakter', 'secret_key_panjang_sampai_10_karakter', $this->base_url_test);
$this->client = new Client($config);
}
public function testCmdSuccessPostRequest()
{
$this->init();
// Test
$result = $this->client->cmd('POST', 'v1/chat/completions', [
'model' => 'llama3.2:latest',
'messages' => [
[
'role' => 'user',
'content' => 'hi, why is sea water salty?',
], [
'role' => 'system',
'content' => 'You are a helpful assistant.',
]
],
'stream' => false,
]);
// $llm_response = $result->choices[0]->message->content;
// $llm_response = $result;
print_r($result);
$llm_response = $result['choices'][0]['message']['content'];
print_r($llm_response);
$this->assertTrue(!empty($llm_response));
}
}