PHP code example of logipro / chatbot-php
1. Go to this page and download the library: Download logipro/chatbot-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
logipro / chatbot-php example snippets
use ChatbotPhp\Chatbot;
$client = Chatbot::client('http://api.example.com');
$client = Chatbot::client();
$context = json_decode($client->contexts()->create([
'context_message' => 'Vous êtes un assistant expert en documentation PHP.'
]), true);
$contextId = $context['data']['contextId'];
$file = json_decode($client->files()->upload([
'file_path' => '/path/to/documentation.pdf',
'purpose' => 'assistants'
]), true);
$fileId = $file['data']['file_id'];
$assistant = json_decode($client->assistants()->create([
'context_id' => $contextId,
'file_ids' => [$fileId]
]), true);
$assistantId = $assistant['data']['assistantId'];
$thread = json_decode($client->threads()->create([
'ast_id' => $assistantId,
'message' => 'Peux-tu m\'aider à documenter cette fonction PHP ?'
]), true);
$conversationId = $thread['data']['conversationId'];
$assistantMessage = $thread['data']['assistantMessage'];
echo $assistantMessage;
$response = json_decode($client->threads()->continue([
'conversation_id' => $conversationId,
'message' => 'Peux-tu m\'expliquer plus en détail ?'
]), true);
$responseMessage = $response['data']['message'];
echo $responseMessage;
$client->contexts()->create(['context_message' => '...']);
$client->contexts()->retrieve($contextId);
$client->contexts()->update(['id' => '...', 'new_message' => '...']);
$client->contexts()->delete($contextId);
$client->files()->upload(['file_path' => '...', 'purpose' => 'assistants']);
$client->files()->list();
$client->files()->retrieve($fileId);
$client->files()->delete($fileId);
$client->assistants()->create(['context_id' => '...', 'file_ids' => [...]]);
$client->assistants()->retrieve($assistantId);
$client->assistants()->update(['assistant_id' => '...', 'file_ids' => [...]]);
$client->assistants()->delete($assistantId);
$client->conversations()->create(['prompt' => '...', 'lm_name' => '...', 'context' => '...']);
$client->conversations()->continue(['prompt' => '...', 'conv_id' => '...', 'lm_name' => '...']);
$client->conversations()->retrieve($conversationId);
$client->conversations()->list($assistantId);
$client->threads()->create(['ast_id' => '...', 'message' => '...']);
$client->threads()->continue(['conversation_id' => '...', 'message' => '...']);
bash
composer bash
git clone https://github.com/logipro-fr/chatbot-php
cd chatbot-php
./install --profile devlocal
DATA_PATH=./data
REMOVE_DATABASE_WHEN_INSTALL=true
BUILD_WHEN_INSTALL=true
DOCKER_DEV=true
OPTIONAL_VOLUME=.:/var/chatbot-php
LOCALDEV_WORKING_DIR=true
URL_API=http://nginx
PULL_POLICY=never