-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft(SK): Livewire scaffolding - coming soon
- Loading branch information
1 parent
bc3807b
commit 1aac40b
Showing
24 changed files
with
957 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Sidekick; | ||
|
||
use Livewire\Component; | ||
use PapaRascalDev\Sidekick\Drivers\OpenAi; | ||
|
||
class AudioGeneration extends Component | ||
{ | ||
public $errors = null; | ||
|
||
public $prompt = ''; | ||
public $audio = null; | ||
public $savedFile = null; | ||
|
||
public $model = 'tts-1'; | ||
|
||
public function submit() | ||
{ | ||
$response = sidekick(new OpenAi)->audio()->fromText( | ||
model: 'tts-1', | ||
text: $this->prompt); | ||
|
||
$response_json = json_decode($response, true); | ||
|
||
if(isset($response_json['error'])) { | ||
$this->errors = $response_json['error']['message']; | ||
} else { | ||
$this->audio = base64_encode($response); | ||
$this->savedFile = sidekick(new OpenAi)->utilities()->store($response, 'audio/mpeg'); | ||
} | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.audio-generation') | ||
->layout('Components.layouts.app', [ | ||
'title' => 'Audio Generation', | ||
'conversations' => sidekickConversation()->database()->all('id', 'model') | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Sidekick; | ||
|
||
use Livewire\Component; | ||
|
||
class Chat extends Component | ||
{ | ||
|
||
public $prompt = ''; | ||
public $config = ''; | ||
|
||
|
||
public function submit() | ||
{ | ||
|
||
$config = json_decode($this->config, true); | ||
|
||
if(!$config) | ||
{ | ||
$config = [ | ||
"engine" => "\PapaRascalDev\Sidekick\Drivers\OpenAi", | ||
"model" => "gpt-3.5-turbo" | ||
]; | ||
} | ||
|
||
// This is the system prompt the user wants the AI to use | ||
$systemPrompt = $this->prompt; | ||
|
||
|
||
$conversation = sidekickConversation()->begin( | ||
driver: new $config['engine'](), | ||
model: $config['model'], | ||
systemPrompt: $systemPrompt | ||
); | ||
|
||
return redirect()->to('/sidekick/chat/' . $conversation->id); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.chat')->layout('Components.layouts.app', [ | ||
'title' => 'Chat', | ||
'conversations' => sidekickConversation()->database()->all('id', 'model') | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Sidekick; | ||
|
||
use Livewire\Component; | ||
use Livewire\Attributes\On; | ||
use Illuminate\Support\Collection; | ||
|
||
class ChatRoom extends Component | ||
{ | ||
public $conversationId; | ||
public $config; | ||
public Collection $messages; | ||
public $newMessage; | ||
public $isStreaming = false; | ||
public $streamingResponse = ''; | ||
|
||
public function mount($id = null) | ||
{ | ||
$this->messages = collect(); | ||
if ($id) { | ||
$this->loadConversation($id); | ||
} | ||
} | ||
|
||
public function loadConversation($id) | ||
{ | ||
$conversation = sidekickConversation()->resume($id); | ||
$this->conversationId = $conversation->model->id; | ||
$this->config = [ | ||
'engine' => $conversation->model->class, | ||
'model' => $conversation->model->model, | ||
]; | ||
$this->messages = collect($conversation->model->messages)->map(function ($message) { | ||
return (object) $message; | ||
}); | ||
} | ||
|
||
public function sendMessage() | ||
{ | ||
$this->messages->push((object) [ | ||
'role' => 'user', | ||
'content' => $this->newMessage | ||
]); | ||
|
||
if ($this->isStreaming) { | ||
$this->streamingResponse = ''; | ||
$this->dispatch('startStreaming'); | ||
} else { | ||
$response = sidekickConversation() | ||
->resume($this->conversationId) | ||
->sendMessage($this->newMessage, false); | ||
|
||
$this->messages->push((object) [ | ||
'role' => 'assistant', | ||
'content' => $response | ||
]); | ||
} | ||
|
||
$this->newMessage = ''; | ||
$this->dispatch('messageAdded'); | ||
} | ||
|
||
#[On('streamChunk')] | ||
public function handleStreamChunk($chunk) | ||
{ | ||
$this->streamingResponse .= $chunk; | ||
} | ||
|
||
#[On('endStreaming')] | ||
public function endStreaming() | ||
{ | ||
$this->messages->push((object) [ | ||
'role' => 'assistant', | ||
'content' => $this->streamingResponse | ||
]); | ||
$this->streamingResponse = ''; | ||
} | ||
|
||
public function delete($id) | ||
{ | ||
sidekickConversation()->delete($id); | ||
return redirect()->to('/sidekick/chat'); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.chat-room')->layout('Components.layouts.app', [ | ||
'title' => 'Chat', | ||
'conversations' => sidekickConversation()->database()->all('id', 'model') | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Sidekick; | ||
|
||
use Livewire\Component; | ||
use PapaRascalDev\Sidekick\Drivers\OpenAi; | ||
|
||
class Completion extends Component | ||
{ | ||
public $errors = null; | ||
|
||
public $prompt = ''; | ||
public $response = null; | ||
|
||
public function submit() | ||
{ | ||
|
||
$this->response = sidekick(new OpenAi)->complete( | ||
model: 'gpt-3.5-turbo', | ||
systemPrompt: 'You are a knowledge base, please answer there questions', | ||
message: $this->prompt | ||
); | ||
|
||
|
||
$this->prompt = ''; | ||
|
||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.completion')->layout('Components.layouts.app', [ | ||
'title' => 'Completion', | ||
'conversations' => sidekickConversation()->database()->all('id', 'model') | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Sidekick; | ||
|
||
use Livewire\Component; | ||
use PapaRascalDev\Sidekick\Drivers\OpenAi; | ||
|
||
class Embeddding extends Component | ||
{ | ||
|
||
public $errors = null; | ||
|
||
public $prompt = ''; | ||
public $response = null; | ||
|
||
public function submit() | ||
{ | ||
|
||
$this->response = sidekick(new OpenAi)->embedding()->make( | ||
model:'text-embedding-3-large', | ||
input: $this->prompt, | ||
); | ||
|
||
|
||
$this->prompt = ''; | ||
|
||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.embeddding')->layout('Components.layouts.app', [ | ||
'title' => 'Embedding', | ||
'conversations' => sidekickConversation()->database()->all('id', 'model') | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Sidekick; | ||
|
||
use Livewire\Component; | ||
use PapaRascalDev\Sidekick\Drivers\OpenAi; | ||
|
||
class ImageGeneration extends Component | ||
{ | ||
|
||
public $prompt = ''; | ||
public $image = null; | ||
public $savedFile = null; | ||
|
||
public $errors = null; | ||
|
||
public $model = 'dall-e-3'; | ||
|
||
public function submit() | ||
{ | ||
$response = sidekick(new OpenAi)->image()->make( | ||
model:$this->model, | ||
prompt: $this->prompt, | ||
width:'1024', | ||
height:'1024' | ||
); | ||
|
||
$this->prompt = ''; | ||
|
||
if(isset($response['data'][0]['url'])) { | ||
$this->image = $response['data'][0]['url']; | ||
$this->savedFile = sidekick(new OpenAi)->utilities()->store($response['data'][0]['url'], 'image/png'); | ||
} else { | ||
$this->errors = $response['error']['message']; | ||
} | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.image-generation') | ||
->layout('Components.layouts.app', [ | ||
'title' => 'Image Generation', | ||
'conversations' => sidekickConversation()->database()->all('id', 'model') | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Sidekick; | ||
|
||
use Livewire\Component; | ||
|
||
class Index extends Component | ||
{ | ||
public function render() | ||
{ | ||
return view('livewire.index')->layout('Components.layouts.app', [ | ||
'title' => '', | ||
'conversations' => sidekickConversation()->database()->all('id', 'model') | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Sidekick; | ||
|
||
use Livewire\Component; | ||
use PapaRascalDev\Sidekick\Drivers\OpenAi; | ||
|
||
class Moderation extends Component | ||
{ | ||
public $response = null; | ||
public $prompt = ''; | ||
|
||
public function submit() | ||
{ | ||
$this->response = sidekick(new OpenAi)->moderate()->text( | ||
model:'text-moderation-latest', | ||
content: $this->prompt | ||
); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.moderation')->layout('Components.layouts.app', [ | ||
'title' => 'Moderation', | ||
'conversations' => sidekickConversation()->database()->all('id', 'model') | ||
]); | ||
} | ||
} |
Oops, something went wrong.