В настоящее время я пытаюсь протестировать большой текст с помощью модели 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
Как мне реорганизовать приведенный ниже код, чтобы я мог генерировать последовательный и плавный документ в ChatGPT? ⇐ Php
Кемеровские программисты php общаются здесь
1727673309
Anonymous
В настоящее время я пытаюсь протестировать большой текст с помощью модели OPENAI gpt-4. Я пытаюсь реорганизовать приведенный ниже код, чтобы модель могла генерировать последовательный, читаемый и плавный документ. Код ниже возвращает 5000 слов, к сожалению, он возвращает разные варианты. на основе темы. Я ожидаю, что он напишет один полный документ объемом 5000 слов. Любая помощь будет высоко оценена.
Проверьте сгенерированный документ: https://docs.google.com/document/d/16zzm4w4uegng6BbNdErtaqItwGtLpHH0uEt0qLW59aE/ 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,
]);
}
Подробнее здесь: [url]https://stackoverflow.com/questions/76002754/how-do-i-refactor-the-below-code-to-allow-me-generate-coherent-and-flowing-docum[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия