laraveladmin/laravel-open-ai

laravel project based on orhanerday/open-ai

v1.0.3 2023-04-12 02:38 UTC

This package is not auto-updated.

Last update: 2024-11-06 10:04:37 UTC


README



Use extension packs


Publish config file:

php artisan vendor:publish --provider="LaravelAdmin\LaravelOpenAi\ServiceProvider"

About this package config in ".env"

OPENAI_API_KEY=
OPENAI_BASE_URI=
OPENAI_ORGANIZATION=
OPENAI_PROXY=
<?php
use LaravelAdmin\LaravelOpenAi\Facades\OpenAI;
$chat = OpenAI::chat([
   'model' => 'gpt-3.5-turbo',
   'messages' => [
       [
           "role" => "system",
           "content" => "You are a helpful assistant."
       ],
       [
           "role" => "user",
           "content" => "Who won the world series in 2020?"
       ],
       [
           "role" => "assistant",
           "content" => "The Los Angeles Dodgers won the World Series in 2020."
       ],
       [
           "role" => "user",
           "content" => "Where was it played?"
       ],
   ],
   'temperature' => 1.0,
   'max_tokens' => 4000,
   'frequency_penalty' => 0,
   'presence_penalty' => 0,
]);


var_dump($chat);
echo "<br>";
echo "<br>";
echo "<br>";
// decode response
$d = json_decode($chat);
// Get Content
echo($d->choices[0]->message->content);

Use more documentation reference

https://packagist.org/packages/orhanerday/open-ai