|
|
@@ -26,7 +26,12 @@ class AIGatewayService{
|
|
|
'txttoimg' => [
|
|
|
'api_key' => 'sk-e0JuPjMntkbgi1BoMjrqyyzMKzAxILkQzyGMSy3xiMupuoWY',
|
|
|
'api_url' => 'https://niubi.zeabur.app/v1/images/generations'
|
|
|
- ]
|
|
|
+ ],
|
|
|
+// //文生文-超结损分析
|
|
|
+// 'chaojiesun' => [
|
|
|
+// 'api_key' => 'sk-Bhos1lXTRpZiAAmN06624a219a874eCd91Dc068b902a3e73',
|
|
|
+// 'api_url' => 'https://one.opengptgod.com/v1/chat/completions'
|
|
|
+// ]
|
|
|
];
|
|
|
|
|
|
/**
|
|
|
@@ -53,6 +58,11 @@ class AIGatewayService{
|
|
|
|
|
|
return $this->callApi($this->config['imgtotxt']['api_url'], $this->config['imgtotxt']['api_key'], $data);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 图生文-方法二
|
|
|
+ * @param string $imageUrl 图像 URL,支持公网可访问地址
|
|
|
+ * @param string $prompt 对图像的提问内容或提示文本
|
|
|
+ */
|
|
|
// public function callGptApi($imageUrl, $prompt)
|
|
|
// {
|
|
|
// $data = [
|
|
|
@@ -91,6 +101,25 @@ class AIGatewayService{
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 文生文-超结损分析
|
|
|
+ * @param string $prompt 用户输入的文本提示内容
|
|
|
+ */
|
|
|
+// public function chaojiesunGptApi($prompt)
|
|
|
+// {
|
|
|
+// $data = [
|
|
|
+// 'prompt' => $prompt,
|
|
|
+// 'model' => 'gpt-4',
|
|
|
+// 'session_id' => null,
|
|
|
+// 'context_reset' => true
|
|
|
+// ];
|
|
|
+// return $this->callApi(
|
|
|
+// $this->config['chaojiesun']['api_url'],
|
|
|
+// $this->config['chaojiesun']['api_key'],
|
|
|
+// $data
|
|
|
+// );
|
|
|
+// }
|
|
|
+
|
|
|
/**
|
|
|
* 文生图
|
|
|
* @param string $prompt 提示文本,用于指导图像生成
|
|
|
@@ -127,6 +156,72 @@ class AIGatewayService{
|
|
|
return $this->callApi($this->config['txttoimg']['api_url'], $this->config['txttoimg']['api_key'], $data);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function imgtoimgGptApi($prompt, $new_image_url)
|
|
|
+ {
|
|
|
+ $imgPath = ROOT_PATH . 'public/' . $new_image_url;
|
|
|
+
|
|
|
+ if (!file_exists($imgPath)) {
|
|
|
+ return ['code' => 1, 'msg' => '原图不存在:' . $new_image_url];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 原图 base64 编码
|
|
|
+ $imgData = file_get_contents($imgPath);
|
|
|
+ $base64Img = base64_encode($imgData);
|
|
|
+ $initImage = 'data:image/png;base64,' . $base64Img;
|
|
|
+
|
|
|
+ // 构建 POST 请求参数
|
|
|
+ $postData = json_encode([
|
|
|
+ 'prompt' => $prompt,
|
|
|
+ 'sampler_name' => 'DPM++ 2M SDE Heun',
|
|
|
+ 'seed' => -1,
|
|
|
+ 'steps' => 20,
|
|
|
+ 'cfg_scale' => 7,
|
|
|
+ 'denoising_strength' => 0.6,
|
|
|
+ 'width' => 1024,
|
|
|
+ 'height' => 2048,
|
|
|
+ 'resize_mode' => 0,
|
|
|
+ 'inpaint_full_res' => true,
|
|
|
+ 'inpainting_fill' => 1,
|
|
|
+ 'init_images' => [$initImage],
|
|
|
+ 'override_settings' => [
|
|
|
+ 'sd_model_checkpoint' => 'realisticVisionV51_v51VAE-inpainting.safetensors [f0d4872d24]',
|
|
|
+ 'sd_vae' => 'anything-v4.5.vae.pt'
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $apiUrl = "http://20.0.17.233:45001/sdapi/v1/img2img";
|
|
|
+ $headers = ['Content-Type: application/json'];
|
|
|
+
|
|
|
+ $ch = curl_init();
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $apiUrl);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($ch, CURLOPT_POST, true);
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
|
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, 90);
|
|
|
+ $response = curl_exec($ch);
|
|
|
+ $error = curl_error($ch);
|
|
|
+ curl_close($ch);
|
|
|
+
|
|
|
+ if ($error) {
|
|
|
+ return ['code' => 1, 'msg' => '请求失败:' . $error];
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = json_decode($response, true);
|
|
|
+ if (!isset($data['images'][0])) {
|
|
|
+ return ['code' => 1, 'msg' => 'API未返回图像数据'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'code' => 0,
|
|
|
+ 'msg' => '图像生成成功',
|
|
|
+ 'data' => [
|
|
|
+ 'url' => $data['images'][0]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通用 API 调用方法(支持重试机制)
|
|
|
*
|