PHP code example of paparascaldev / sidekick

1. Go to this page and download the library: Download paparascaldev/sidekick 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/ */

    

paparascaldev / sidekick example snippets


$sidekick = new SidekickConversation();

$conversation = $sidekick->begin(
    driver: new OpenAi(),
    model: 'gtp-3.5-turbo',
    systemPrompt: 'You can instruct the chatbot using this parameter'
);

$response = $conversation->sendMessage($user_input);

return response()->json($response);

$sidekick = new SidekickConversation();

$conversation = $sidekick->resume(
    conversationId: $conversation_id
);

$response = $conversation->sendMessage($user_input);

return response()->json($response);

public function index() {
    // List Conversations
    $sidekick = new SidekickChatManager();
    return $sidekick->showAll();
}

public function show(Conversation $conversation) {
    // show Conversation
    $sidekick = new SidekickManager();
    $sidekick->show($conversation);
}

public function delete(Conversation $conversation) {
    // Delete Conversation
    $sidekick = new SidekickManager();
    return $sidekick->delete($conversation);
}

$sidekick = Sidekick::create(new OpenAi());

return $sidekick->complete()->sendMessage(
    model: 'gpt-3.5-turbo',
    systemPrompt: 'You an expert on fudge, answer user questions about fudge.',
    message:"How is fudge made?"
);

$sidekick = Sidekick::create(new Mistral());

return $sidekick->embedding()->make(
    model: 'mistral-embed',
    input: 'This is sample content to embed'
);

 $sidekick = Sidekick::create(new OpenAi());
 
$image =  $sidekick->image()->make(
    model:'dall-e-3',
    prompt: $request->get('text_to_convert'),
    width:'1024',
    height:'1024'
);

// This is just a basic example of printing to screen.
// In a real world situation you may save it and then render out.
return "<img src='{$image['data'][0]['url']}' />";

$sidekick = Sidekick::create(new OpenAi());

$audio = $sidekick->audio()->fromText(
    model: 'tts-1',
    text: 'Have a nice day!'
);

// This is just a basic example of streaming it to the browser.
// In a real world situation you may save it and then reference the file
// instead.
header('Content-Type: audio/mpeg');
echo $audio

$sidekick = Sidekick::create(new OpenAi());

return $sidekick->transcribe()->audioFile(
    model: 'whisper-1',
    filePath: 'http://english.voiceoversamples.com/ENG_UK_M_PeterB.mp3'
);

$sidekick = Sidekick::create(new OpenAi());

return $sidekick->moderate()->text(
    model: 'text-moderation-latest',
    content: 'Have a great day.',
);
bash
    php artisan migrate

    php artisan vendor:publish --tag=views
    php artisan vendor:publish --tag=routes
json
{
  "id":"modr-94DxgkEGhw7yJDlq8oCrLOVXnqli5",
  "model":"text-moderation-007",
  "results":[
    {
      "flagged":true,
      "categories":{
        "sexual":false,
        "hate":false,
        "harassment":true,
        "self-harm":false,
        "sexual\/minors":false,
        "hate\/threatening":false,
        "violence\/graphic":false,
        "self-harm\/intent":false,
        "self-harm\/instructions":false,
        "harassment\/threatening":false,
        "violence":false
      },
      "category_scores":{
        "sexual":0.02169245481491089,
        "hate":0.024598680436611176,
        "harassment":0.9903337359428406,
        "self-harm":5.543852603295818e-5,
        "sexual\/minors":2.5174302209052257e-5,
        "hate\/threatening":2.9870452635805123e-6,
        "violence\/graphic":6.8601830207626335e-6,
        "self-harm\/intent":0.0002317160106031224,
        "self-harm\/instructions":0.00011696072033373639,
        "harassment\/threatening":1.837775380408857e-5,
        "violence":0.00020553809008561075
      }
    }
  ]}