lupoz
lupoz
FFilament
Created by lupoz on 10/24/2024 in #❓┊help
Count chars field not working
Thanks!
4 replies
FFilament
Created by lupoz on 12/8/2023 in #❓┊help
How can I call a API route in a form?
I tried: Filament:
TextInput::make('name')

->required()
->afterStateUpdated(fn ($state, callable $ChatGPT) => [
$ChatGPT('full_description', $ChatGPT($state)),
]),

MarkdownEditor::make('full_description')
TextInput::make('name')

->required()
->afterStateUpdated(fn ($state, callable $ChatGPT) => [
$ChatGPT('full_description', $ChatGPT($state)),
]),

MarkdownEditor::make('full_description')
Route:
Route::post('/chat', ChatGPT::class)->name('ChatGPT');
Route::post('/chat', ChatGPT::class)->name('ChatGPT');
Controller:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Throwable;

class ChatGPT extends Controller
{
/**
* @param Request $request
* @return string
*/
public function __invoke(Request $request): string
{

try {
/** @var array $response */
$response = Http::withHeaders([
"Content-Type" => "application/json",
"Authorization" => "Bearer " . env('CHAT_GPT_KEY')
])->post('https://api.openai.com/v1/chat/completions', [
"model" => $request->post('model'),
"messages" => [
[
"role" => "user",
"content" => $request->post('content')
]
],
"temperature" => 0,
"max_tokens" => 2048
])->body();
return $response['choices'][0]['message']['content'];
} catch (Throwable $e) {
return "Error: $e";
}
}
}
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Throwable;

class ChatGPT extends Controller
{
/**
* @param Request $request
* @return string
*/
public function __invoke(Request $request): string
{

try {
/** @var array $response */
$response = Http::withHeaders([
"Content-Type" => "application/json",
"Authorization" => "Bearer " . env('CHAT_GPT_KEY')
])->post('https://api.openai.com/v1/chat/completions', [
"model" => $request->post('model'),
"messages" => [
[
"role" => "user",
"content" => $request->post('content')
]
],
"temperature" => 0,
"max_tokens" => 2048
])->body();
return $response['choices'][0]['message']['content'];
} catch (Throwable $e) {
return "Error: $e";
}
}
}
Error: An attempt was made to evaluate a closure for [Filament\Forms\Components\TextInput], but [$ChatGPT] was unresolvable.
3 replies
FFilament
Created by lupoz on 12/7/2023 in #❓┊help
live method trim himself
solved thanks!
8 replies
FFilament
Created by lupoz on 12/7/2023 in #❓┊help
live method trim himself
with lazy() works but it is not in real time
8 replies
FFilament
Created by lupoz on 12/7/2023 in #❓┊help
live method trim himself
same problem
8 replies
FFilament
Created by lupoz on 12/7/2023 in #❓┊help
live method trim himself
No description
8 replies