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
94019363
Commit
94019363
authored
Apr 14, 2023
by
haojie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
2a936aba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
18 deletions
+40
-18
app/Service/TaskService.php
+38
-18
routes/api.php
+2
-0
No files found.
app/Service/TaskService.php
View file @
94019363
...
...
@@ -70,6 +70,13 @@ public function submit(int $user_id = 0, array $data = [])
$data
[
'prompt'
]
=
str_replace
(
'\n'
,
''
,
$data
[
'prompt'
]);
$task
=
$this
->
createTask
(
$user_id
,
$data
);
$promptTask
=
$this
->
createPromptTask
(
$user_id
,
$task
->
id
,
$data
);
$list
=
[
'type'
=>
(
string
)(
$data
[
'type'
]
??
''
),
'prompt'
=>
(
string
)(
$data
[
'prompt'
]
??
''
),
'prompt_img'
=>
json_encode
(
$data
[
'prompt_img'
]
??
[]),
'user_id'
=>
$user_id
,
'prompt_num'
=>
self
::
GPT_prompt_num
,
];
$list
[
'prompt_id'
]
=
$promptTask
->
id
;
# 插入redis,这是自动化的任务
Redis
::
rpush
(
'midjourney_prompt'
,
json_encode
(
$list
));
...
...
@@ -152,6 +159,30 @@ public function apiSubmit(int $userId = 0, array $data = [])
];
}
/**
* stable 提交任务=-------
*/
public
function
stableSubmit
(
int
$userId
=
0
,
array
$data
=
[])
{
$this
->
validateSubmitData
(
$data
);
$data
[
'prompt'
]
=
str_replace
(
'\n'
,
''
,
$data
[
'prompt'
]);
$task
=
$this
->
createTask
(
$userId
,
$data
);
$promptTask
=
$this
->
createPromptTask
(
$userId
,
$task
->
id
,
$data
);
$sendData
=
[
'prompt'
=>
$task
->
prompt
,
'prompt_img'
=>
$task
->
prompt_img
,
'prompt_id'
=>
$promptTask
->
id
,
'task_id'
=>
$task
->
id
,
'type'
=>
$task
->
type
,
];
# 提交redis
Redis
::
rpush
(
'stable_task'
,
json_encode
(
$sendData
));
return
[
'task_id'
=>
$task
->
id
,
'prompt_num'
=>
$task
->
prompt_num
];
}
/**
* redis队列插入--这是gpt生成指令的任务
...
...
@@ -339,24 +370,13 @@ public function create_split_img_task(int $user_id = 0, $data = [])
$prompt
->
update
([
'cut_id'
=>
$cut_id
,
]);
if
((
int
)
$type
===
self
::
TASK_TYPE_AUTO
)
{
# 添加redis任务
$list
=
[
'prompt_id'
=>
$prompt_id
,
'result_img'
=>
$prompt
->
result_img
,
'cut_id'
=>
$cut_id
,
'callback'
=>
config
(
'common.split_img_callback'
),
];
Redis
::
rpush
(
'discord_img_split'
,
json_encode
(
$list
));
}
else
{
$downloadData
=
[
'url'
=>
$prompt
->
result_img
,
'name'
=>
Str
::
uuid
()
->
toString
(),
'index'
=>
$cut_id
,
'prompt_id'
=>
$prompt_id
,
];
dispatch
(
new
DownloadImageJob
(
$downloadData
));
}
$downloadData
=
[
'url'
=>
$prompt
->
result_img
,
'name'
=>
Str
::
uuid
()
->
toString
(),
'index'
=>
$cut_id
,
'prompt_id'
=>
$prompt_id
,
];
dispatch
(
new
DownloadImageJob
(
$downloadData
));
return
[
'prompt_id'
=>
$prompt_id
,
];
...
...
routes/api.php
View file @
94019363
...
...
@@ -49,6 +49,8 @@
Route
::
post
(
'submit'
,
'TaskController@SubmitTask'
);
// Api 提交任务
Route
::
post
(
'api-submit'
,
'TaskController@apiSubmit'
);
// stable 提交任务
Route
::
post
(
'stable-submit'
,
'TaskController@stableSubmit'
);
# 轮询请求任务回调
Route
::
get
(
'task/callback'
,
'TaskController@task_callback'
);
# 创建切割图片任务
...
...
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