| xqd
@@ -48,6 +48,7 @@ class AiController extends Controller
|
|
|
'age' => $request->post('age', ''),
|
|
|
'star' => $request->post('star', ''),
|
|
|
'level' => $request->post('level', ''),
|
|
|
+// 'is_piny' => $request->post('is_piny', 1),
|
|
|
]);
|
|
|
if (!$role) {
|
|
|
return Response::fail('提交失败,请稍后再试!');
|
| xqd
@@ -61,6 +62,7 @@ class AiController extends Controller
|
|
|
'surplus_diamond' => Auth::$user->diamond - $plot,
|
|
|
'nickname' => 'AI绘本生成',
|
|
|
'plot' => $plot,
|
|
|
+ 'is_piny' => $request->post('pinYin', 1),
|
|
|
]);
|
|
|
if (!$task) {
|
|
|
return Response::fail('任务提交失败');
|
| xqd
@@ -93,20 +95,22 @@ class AiController extends Controller
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取字数
|
|
|
+ * 获取字数.
|
|
|
*
|
|
|
- * @param $level
|
|
|
* @return int|mixed
|
|
|
*/
|
|
|
- private function getBuildCountString($level = 1){
|
|
|
- $string = Config::query()->where('key','class_count')->first()->toArray();
|
|
|
- foreach ($string['value'] ?? [] as $value){
|
|
|
- if ($level == $value['lv']){
|
|
|
+ private function getBuildCountString($level = 1)
|
|
|
+ {
|
|
|
+ $string = Config::query()->where('key', 'class_count')->first()->toArray();
|
|
|
+ foreach ($string['value'] ?? [] as $value) {
|
|
|
+ if ($level == $value['lv']) {
|
|
|
return $value['count'];
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return 200;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 生成故事.
|
|
|
*/
|
| xqd
@@ -117,16 +121,16 @@ class AiController extends Controller
|
|
|
if (!$task) {
|
|
|
return Response::fail('暂无任务');
|
|
|
}
|
|
|
- $key = [];
|
|
|
-// $keyword = Keyword::query()->pluck('keyword');
|
|
|
-// foreach ($keyword as $value) {
|
|
|
-// $key[] = $value;
|
|
|
-// }
|
|
|
-// $keyword = implode(',', $key);
|
|
|
- $keyword = Config::query()->where('key','prompt_gushi')->value('value');
|
|
|
+ $key = [];
|
|
|
+ // $keyword = Keyword::query()->pluck('keyword');
|
|
|
+ // foreach ($keyword as $value) {
|
|
|
+ // $key[] = $value;
|
|
|
+ // }
|
|
|
+ // $keyword = implode(',', $key);
|
|
|
+ $keyword = Config::query()->where('key', 'prompt_gushi')->value('value');
|
|
|
$task->state = 1;
|
|
|
$task->save();
|
|
|
- Log::warning('这个是当前的次数:'.$this->getBuildCountString($task->level));
|
|
|
+ Log::warning('这个是当前的次数:' . $this->getBuildCountString($task->level));
|
|
|
$prompt = "一个{$task->role->sex},叫{$task->role->name},{$task->role->age}岁。{$keyword},要求不低于{$this->getBuildCountString($task->role->level)}字。备注:不要加什么特殊符号只需要正常的逗号句号叹号这些。";
|
|
|
$messages[] = ['role' => 'user', 'content' => $prompt];
|
|
|
$data = [
|
| xqd
@@ -164,8 +168,8 @@ class AiController extends Controller
|
|
|
$data = [
|
|
|
'messages' => $messages,
|
|
|
];
|
|
|
- $postData = json_encode($data);
|
|
|
- $complete = $this->host($postData);
|
|
|
+ $postData = json_encode($data);
|
|
|
+ $complete = $this->host($postData);
|
|
|
// $task->state = 2;
|
|
|
$task->title = $complete['result'];
|
|
|
$task->save();
|
| xqd
@@ -190,16 +194,16 @@ class AiController extends Controller
|
|
|
if (!$task) {
|
|
|
return Response::fail('暂无任务');
|
|
|
}
|
|
|
- $keyword = Config::query()->where('key','prompt_keyword')->value('value');
|
|
|
+ $keyword = Config::query()->where('key', 'prompt_keyword')->value('value');
|
|
|
$prompt = $task->init_content . $keyword;
|
|
|
$messages[] = ['role' => 'user', 'content' => $prompt];
|
|
|
$data = [
|
|
|
'messages' => $messages,
|
|
|
];
|
|
|
- $task->state = 3;
|
|
|
+ $task->state = 3;
|
|
|
$task->save();
|
|
|
- $postData = json_encode($data);
|
|
|
- $complete = $this->host($postData);
|
|
|
+ $postData = json_encode($data);
|
|
|
+ $complete = $this->host($postData);
|
|
|
// $task->state = 3;
|
|
|
$task->keyword = $complete['result'];
|
|
|
$task->save();
|
| xqd
@@ -217,7 +221,7 @@ class AiController extends Controller
|
|
|
*/
|
|
|
private function toEnglish($prompt)
|
|
|
{
|
|
|
- $keyword = Config::query()->where('key','prompt_style')->value('value');
|
|
|
+ $keyword = Config::query()->where('key', 'prompt_style')->value('value');
|
|
|
$prompt = $prompt . $keyword;
|
|
|
$promptTo = '我希望你能担任英语翻译、拼写校对和修辞改进的角色。我会将翻译的结果用于如stable diffusion、midjourney等绘画场景生成图片,语言要求尽量优美。我会用任何语言和你交流,你会识别语言,将其翻译为英语并仅回答翻译的最终结果,不要写解释。我的第一句话是:' . $prompt . '。请立刻翻译,不要回复其它内容。';
|
|
|
$messages[] = ['role' => 'user', 'content' => $promptTo];
|
| xqd
@@ -259,15 +263,15 @@ class AiController extends Controller
|
|
|
'keywords' => $keyword,
|
|
|
];
|
|
|
|
|
|
- $result = (new Helper())->opensd($param);
|
|
|
- $result = json_decode($result, true);
|
|
|
- Log::warning('这个是SD回调信息:'.json_encode($result,256));
|
|
|
- if(isset($result['data']['id'])){
|
|
|
+ $result = (new Helper())->opensd($param);
|
|
|
+ $result = json_decode($result, true);
|
|
|
+ Log::warning('这个是SD回调信息:' . json_encode($result, 256));
|
|
|
+ if (isset($result['data']['id'])) {
|
|
|
$task->sd_id = $result['data']['id'];
|
|
|
- }else{
|
|
|
- $task->state = 3;
|
|
|
+ } else {
|
|
|
+ $task->state = 3;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$task->save();
|
|
|
|
|
|
return Response::success($result['data']);
|
| xqd
@@ -296,7 +300,7 @@ class AiController extends Controller
|
|
|
}
|
|
|
if ('fail' == $res['data']['state']) {
|
|
|
$task->state = 3;
|
|
|
- $task->desc = $res['data']['fail_reason'];
|
|
|
+ $task->desc = $res['data']['fail_reason'];
|
|
|
}
|
|
|
$task->save();
|
|
|
if ('success' == $res['data']['state']) {
|
| xqd
@@ -325,7 +329,7 @@ class AiController extends Controller
|
|
|
$file_name = md5(time()) . '.png';
|
|
|
}
|
|
|
$path = public_path() . '/images/' . $file_name;
|
|
|
- $shell = 'wkhtmltoimage https://t18.9026.com/api/ai/Pinyin?id=' . $task->id . ' ' . $path;
|
|
|
+ $shell = 'wkhtmltoimage https://hb.swdz.com/api/ai/Pinyin?id=' . $task->id . ' ' . $path;
|
|
|
exec($shell, $result, $status);
|
|
|
if ($status) {
|
|
|
$this->exit_out('生成图片失败', ['生成图片失败' => [$shell, $result, $status]]);
|
| xqd
@@ -366,7 +370,7 @@ class AiController extends Controller
|
|
|
$file_name = md5(time()) . '.pdf';
|
|
|
}
|
|
|
$path = public_path() . '/pdf/' . $file_name;
|
|
|
- $shell = 'wkhtmltopdf https://t18.9026.com/api/ai/Pinyin?id=' . $task->id . ' ' . $path;
|
|
|
+ $shell = 'wkhtmltopdf https://hb.swdz.com/api/ai/Pinyin?id=' . $task->id . ' ' . $path;
|
|
|
exec($shell, $result, $status);
|
|
|
if ($status) {
|
|
|
$this->exit_out('生成PDF失败', ['生成PDF失败' => [$shell, $result, $status]]);
|
| xqd
@@ -409,7 +413,7 @@ class AiController extends Controller
|
|
|
$task = TaskList::query()->find($id);
|
|
|
$result = $this->extracted($task);
|
|
|
|
|
|
- return view('pdf', ['data' => $result, 'img' => $task->image,'title' => $task->title]);
|
|
|
+ return view('pdf', ['data' => $result, 'img' => $task->image, 'title' => $task->title]);
|
|
|
} catch (\Exception $exception) {
|
|
|
LogHelper::exceptionLog($exception, $this->code);
|
|
|
|
| xqd
@@ -504,17 +508,18 @@ class AiController extends Controller
|
|
|
]);
|
|
|
$res = curl_exec($ch);
|
|
|
curl_close($ch);
|
|
|
-
|
|
|
+ Log::warning('请求头:' .$postData);
|
|
|
+ Log::warning('请求返回值:' .$res);
|
|
|
return json_decode(trim($res), true);
|
|
|
}
|
|
|
|
|
|
- public function extracted($result,$type = 0,$sdImage = ''): string
|
|
|
+ public function extracted($result, $type = 0, $sdImage = ''): string
|
|
|
{
|
|
|
- if ($type == 0){
|
|
|
- $inputString = $result->init_content;
|
|
|
- $sdImage = $result->sd_image;
|
|
|
- }else{
|
|
|
- $inputString = $result;
|
|
|
+ if (0 == $type) {
|
|
|
+ $inputString = $result->init_content;
|
|
|
+ $sdImage = $result->sd_image;
|
|
|
+ } else {
|
|
|
+ $inputString = $result;
|
|
|
}
|
|
|
$inputString = str_replace('“', '', $inputString);
|
|
|
$inputString = str_replace('”', '', $inputString);
|
| xqd
@@ -547,16 +552,24 @@ class AiController extends Controller
|
|
|
$string = $string . $img;
|
|
|
}
|
|
|
if (in_array($key + 1, $arr)) {
|
|
|
- $string = $string . "<span><sup>{$value}</sup>{$splitCharacters[$key]}</span><br style='clear: both'><br style='clear: both'>";
|
|
|
+ if ($result->is_piny){
|
|
|
+ $string = $string . "<span><sup>{$value}</sup>{$splitCharacters[$key]}</span><br style='clear: both'><br style='clear: both'>";
|
|
|
+ }else{
|
|
|
+ $string = $string . "<span>{$splitCharacters[$key]}</span><br style='clear: both'><br style='clear: both'>";
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
$style = '';
|
|
|
// if (in_array($key, $arr) || 0 == $key) {
|
|
|
// $style = 'style="margin-left: 5rem"';
|
|
|
// }
|
|
|
- $string = $string . '<span ' . $style . "><sup>{$value}</sup>{$splitCharacters[$key]}</span>";
|
|
|
+ if ($result->is_piny){
|
|
|
+ $string = $string . '<span ' . $style . "><sup>{$value}</sup>{$splitCharacters[$key]}</span>";
|
|
|
+ }else{
|
|
|
+ $string = $string . '<span ' . $style . ">{$splitCharacters[$key]}</span>";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return $string;
|
|
|
}
|
|
|
}
|