Skip to content

Commit

Permalink
Add textLength setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumas-Cola committed Nov 2, 2024
1 parent d00c227 commit 2169447
Show file tree
Hide file tree
Showing 13 changed files with 800 additions and 769 deletions.
20 changes: 17 additions & 3 deletions app/Http/Controllers/AiTeacherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,8 @@

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests\AiTeacherRequest;
use Illuminate\Support\Facades\Validator;
use TeaRiot\YandexGpt\Cloud;
use TeaRiot\YandexGpt\Methods\Completion;

Expand All @@ -25,12 26,13 @@ public function index()
return view('ai-teacher');
}

public function send(Request $request)
public function send(AiTeacherRequest $request)
{
$messages = $request->get('messages');

if (! empty($messages) and is_array($messages)) {
$completion = new Completion();
$completion = new Completion;
$completion->setMaxTokens(2000);

$context = [
[
Expand All @@ -46,6 48,17 @@ public function send(Request $request)
'text' => $message['text'],
];
} else {
$validator = Validator::make($message, [
'text' => 'required|max:2000',
]);

if ($validator->fails()) {
return response()->json([
'code' => 413,
'message' => 'Payload Too Large',
], 413);
}

$context[] = [
'role' => $completion::USER,
'text' => $message['text'],
Expand All @@ -55,6 68,7 @@ public function send(Request $request)

$completion->setModelUri($this->folderId, 'yandexgpt-lite/latest')
->setTextMaxCount(21)
->setTextLength(20000)
->addText($context);

$result = $this->yandexGpt->request($completion);
Expand Down
28 changes: 28 additions & 0 deletions app/Http/Requests/AiTeacherRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 1,28 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AiTeacherRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'messages' => 'required|array',
];
}
}
Loading

0 comments on commit 2169447

Please sign in to comment.