-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmr_api_example.php
More file actions
44 lines (35 loc) · 1.1 KB
/
mr_api_example.php
File metadata and controls
44 lines (35 loc) · 1.1 KB
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
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client(['base_uri' => 'http://localhost:8012', 'timeout' => 300]);
// Extract the first argument that is not --trace for instructions
$instructions = null;
if (count($argv) > 1) {
foreach (array_slice($argv, 1) as $arg) {
if ($arg !== '--trace') {
$instructions = $arg;
break;
}
}
}
if ($instructions === null) {
die("Error: No instructions provided. Usage: php mr_api_example.php \"Your instructions here\" [--trace]\n");
}
try {
$response = $client->post("/task/Assistant", [
'query' => ['api_key' => getenv('MINDROOT_API_KEY') ],
'json' => ['instructions' => $instructions ]
]);
$result = json_decode($response->getBody(), true);
if ($result['status'] == 'error') {
echo "Error: " . $result['message'];
} else {
print_r($result['results']);
if (in_array('--trace', $argv)) {
echo "\n\n";
print_r($result['full_results']);
}
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}