Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
open_ai_api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haojie
open_ai_api
Commits
36de8a7f
Commit
36de8a7f
authored
Apr 14, 2023
by
haojie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
f9baf31e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
14 deletions
+14
-14
app/Service/TaskService.php
+14
-14
No files found.
app/Service/TaskService.php
View file @
36de8a7f
...
...
@@ -38,23 +38,23 @@ public function validateSubmitData(array $data = [])
$promptNum
=
$data
[
'prompt_num'
]
??
''
;
if
(
empty
(
$type
)
||
empty
(
$prompt
))
{
throw
new
UserException
(
'任务类型不能为空'
);
throw
new
UserException
(
1
,
'任务类型不能为空'
);
}
# 生成指令数量只能在1-10之间
if
(
$promptNum
<
1
||
$promptNum
>
10
)
{
throw
new
UserException
(
'生成指令数量只能在1-10之间'
);
throw
new
UserException
(
1
,
'生成指令数量只能在1-10之间'
);
}
# 判断类型
if
(
$type
==
self
::
TYPE_IMG_TO_IMG
)
{
# 图片转图片
if
(
!
count
(
$promptImg
))
{
throw
new
UserException
(
'图片不能为空'
);
throw
new
UserException
(
1
,
'图片不能为空'
);
}
}
elseif
(
$type
==
self
::
TYPE_TEXT_TO_IMG
)
{
# 文字转图片
}
else
{
throw
new
UserException
(
'任务类型错误'
);
throw
new
UserException
(
1
,
'任务类型错误'
);
}
}
...
...
@@ -206,7 +206,7 @@ public function stableCallback(array $data = [])
$message
=
$data
[
'message'
]
??
''
;
$status
=
$data
[
'status'
]
??
false
;
if
(
empty
(
$task_id
)
||
empty
(
$prompt_id
))
{
throw
new
UserException
(
'缺少字段
'
);
throw
new
UserException
(
1
,
'参数错误
'
);
}
if
(
!
$status
)
{
# 任务失败
...
...
@@ -236,7 +236,7 @@ public function stableCallback(array $data = [])
*/
public
function
setRedis
(
$task_id
,
$data
=
[])
{
$data
[
'callback'
]
=
config
(
'common
.
callback'
);
$data
[
'callback'
]
=
config
(
'common
.
callback'
);
$data
[
'task_id'
]
=
$task_id
;
Redis
::
rpush
(
'gpt_text_prompt'
,
json_encode
(
$data
));
}
...
...
@@ -259,11 +259,11 @@ public function gpt_callback($data = [])
$result_img
=
$credentials
[
'result_img'
]
??
''
;
# 判断必须字段
if
(
empty
(
$type
)
||
empty
(
$prompt
)
||
empty
(
$user_id
)
||
empty
(
$task_id
))
{
throw
new
UserException
(
'gpt_callback--$user_id,$task_id,$prompt,$type参数错误'
);
throw
new
UserException
(
1
,
'gpt_callback--$user_id,$task_id,$prompt,$type参数错误'
);
}
# 判断$data是否为数组
if
(
!
is_array
(
$prompt
))
{
throw
new
UserException
(
'gpt_callback--$prompt参数错误'
);
throw
new
UserException
(
1
,
'gpt_callback--$prompt参数错误'
);
}
# 循环
foreach
(
$prompt
as
$item
)
{
...
...
@@ -274,8 +274,8 @@ public function gpt_callback($data = [])
'prompt_img'
=>
$prompt_img
,
'result_img'
=>
$result_img
,
'type'
=>
$type
,
'callback'
=>
config
(
'common
.
prompt_callback'
),
'policy'
=>
config
(
'common
.
policy_callback'
),
'callback'
=>
config
(
'common
.
prompt_callback'
),
'policy'
=>
config
(
'common
.
policy_callback'
),
];
$prompt_id
=
promptTask
::
query
()
->
create
(
$list
)
->
id
;
$list
[
'prompt_id'
]
=
$prompt_id
;
...
...
@@ -300,7 +300,7 @@ public function prompt_callback($data = [])
$message
=
$credentials
[
'message'
]
??
''
;
# 判断必须字段
if
(
empty
(
$user_id
)
||
empty
(
$task_id
)
||
empty
(
$result_img
)
||
empty
(
$prompt_id
))
{
throw
new
UserException
(
'指令回调缺少参数'
);
throw
new
UserException
(
1
,
'指令回调缺少参数'
);
}
# 如果存在message,则提交失败信息
if
(
$message
)
{
...
...
@@ -321,7 +321,7 @@ public function prompt_callback($data = [])
'task_id'
=>
$task_id
,
'prompt_id'
=>
$prompt_id
,
'result_img'
=>
$result_img
,
'callback'
=>
config
(
'common
.
img_download_callback'
),
'callback'
=>
config
(
'common
.
img_download_callback'
),
];
# redis队列插入任务--转存图片
Redis
::
rpush
(
'discord_img_download'
,
json_encode
(
$list
));
...
...
@@ -341,7 +341,7 @@ public function img_download_callback($data = [])
$result_img
=
$credentials
[
'result_img'
]
??
''
;
# 判断必须字段
if
(
empty
(
$prompt_id
))
{
throw
new
UserException
(
'参数错误'
);
throw
new
UserException
(
1
,
'参数错误'
);
}
# 获取任务
$task
=
PromptTask
::
query
()
->
where
(
'id'
,
$prompt_id
)
->
first
();
...
...
@@ -374,7 +374,7 @@ public function task_callback($user_id, $data = [])
$task_id
=
$credentials
[
'task_id'
];
# 判断必须字段
if
(
empty
(
$task_id
))
{
throw
new
UserException
(
'缺少id'
);
throw
new
UserException
(
1
,
'缺少id'
);
}
# 查询所有
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment