Как мне реорганизовать приведенный ниже код, чтобы я мог генерировать последовательный и плавный документ в ChatGPT?Php

Кемеровские программисты php общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Как мне реорганизовать приведенный ниже код, чтобы я мог генерировать последовательный и плавный документ в ChatGPT?

Сообщение Anonymous »

В настоящее время я пытаюсь протестировать большой текст с помощью модели OPENAI gpt-4. Я пытаюсь реорганизовать приведенный ниже код, чтобы модель могла генерировать последовательный, читаемый и плавный документ. Код ниже возвращает 5000 слов, к сожалению, он возвращает разные варианты. на основе темы. Я ожидаю, что он напишет один полный документ объемом 5000 слов. Любая помощь будет высоко оценена.
Проверьте сгенерированный документ: https://docs.google.com/document/d/16zz ... t0qLW59aE/ edit?usp=sharing
Код:
public function writePropmt(Request $request)
{
$this->authCheck();
$this->validate($request, [
'content' => 'required',
'maxWords' => 'required|integer|min:1',
]);

ini_set('max_execution_time', 1800); // Set the maximum execution time to 10 minutes

$content = $request->input('content');
$maxWords = intval($request->input('maxWords'));
$maxWordsPerRequest = 2000; // Set the maximum words to generate in each request
$result = '';

if (!empty($this->super_settings['openai_api_key']) && $content) {
if ($this->isDemo() || $this->super_settings['openai_api_key'] == 'demo') {
$result = '';
} else {
// Set OpenAI API Key
$client = OpenAI::client($this->super_settings['openai_api_key']);

try {
$response = $client->chat()->create([
'model' => 'gpt-4',
'messages' => [
[
'role' => 'user',
'content' => $content,
],
],
'max_tokens' => $maxWordsPerRequest,
]);

if (!empty($response->choices)) {
foreach ($response->choices as $data) {
$result .= $data->message->content;
}
}

while (strlen($result) < $maxWords && strlen($result) + $maxWordsPerRequest chat()->create([
'model' => 'gpt-4',
'messages' => [
[
'role' => 'user',
'content' => '',
],
],
'max_tokens' => $maxWordsPerRequest,
'prompt' => $result,
]);

if (!empty($response->choices)) {
foreach ($response->choices as $data) {
$result .= $data->message->content;
}
}
}

$result = substr($result, 0, $maxWords); // Limit the result to the requested number of words
} catch (\Exception $e) {
if ($this->user->is_super_admin) {
$result = 'Error: ' . $e->getMessage();
} else {
$result = __('Sorry, I am not able to write anything for you.');
}
}
}
}

if (empty($result)) {
$result = __('Sorry, I am not able to write anything for you.');
}

// Convert result markdown to html
$result = Str::markdown($result);

return response()->json([
'success' => true,
'result' => $result,
]);
}


Подробнее здесь: https://stackoverflow.com/questions/760 ... wing-docum
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Php»