XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Add video provider

46310836
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +10 -8
Modified g4f/Provider/needs_auth/Video.py +7 -4
@@ -27,8 +27,9 @@ class Video(AsyncGeneratorProvider):
27 27 "https://sora.chatgpt.com/explore",
28 28 #"https://aistudio.google.com/generate-video"
29 29 ]
30 api_url = "http:/bore.pub:40346/backend-api/v2/create"
31 search_url = "http://bore.pub:40346/search/video+{prompt}"
30 pub_url = "http://bore.pub:40346"
31 api_url = f"{pub_url}/backend-api/v2/create"
32 search_url = f"{pub_url}/search/video+"
32 33 drive_url = "https://www.googleapis.com/drive/v3/"
33 34
34 35 needs_auth = True
@@ -47,6 +48,8 @@ class Video(AsyncGeneratorProvider):
47 48 **kwargs
48 49 ) -> AsyncResult:
49 50 prompt = format_media_prompt(messages, prompt)
51 if not prompt:
52 raise ValueError("Prompt cannot be empty.")
50 53 global browser, stop_browser
51 54 try:
52 55 if browser is None:
@@ -54,11 +57,11 @@ class Video(AsyncGeneratorProvider):
54 57 except Exception as e:
55 58 debug.error(f"Error getting nodriver:", e)
56 59 async with ClientSession() as session:
57 async with session.get(cls.search_url.format(prompt=quote_plus(prompt)), timeout=ClientTimeout(total=10)) as response:
60 async with session.get(cls.search_url + quote_plus(prompt), timeout=ClientTimeout(total=10)) as response:
58 61 if response.status == 200:
59 62 if response.headers.get("content-type", "text/plain").startswith("text/pain"):
60 63 data = (await response.text()).split("\n")
61 yield VideoResponse(data, prompt)
64 yield VideoResponse([f"{cls.pub_url}{url}" if url.startswith("/") else url for url in data], prompt)
62 65 return
63 66 yield VideoResponse(str(response.url), prompt)
64 67 return
Modified g4f/gui/server/backend_api.py +3 -4
@@ -260,8 +260,7 @@ class Backend_Api(Api):
260 260 buffer.get_list(),
261 261 buffer.get("cookies"),
262 262 buffer.get("headers"),
263 None,
264 request.args.get("prompt")
263 alt=buffer.alt
265 264 )))
266 265 elif isinstance(buffer, AudioResponse):
267 266 return buffer.data
@@ -294,7 +293,7 @@ class Backend_Api(Api):
294 293 f.write(response)
295 294 else:
296 295 response = cast_str(iter_run_tools(ChatCompletion.create, **parameters))
297 if isinstance(response, str):
296 if isinstance(response, str) and "\n" not in response:
298 297 if response.startswith("/media/"):
299 298 media_dir = get_media_dir()
300 299 filename = os.path.basename(response.split("?")[0])
@@ -303,7 +302,7 @@ class Backend_Api(Api):
303 302 finally:
304 303 if not cache_id:
305 304 os.remove(os.path.join(media_dir, filename))
306 elif "\n" not in response and response.startswith("https://") or response.startswith("http://"):
305 elif response.startswith("https://") or response.startswith("http://"):
307 306 return redirect(response)
308 307 if do_filter:
309 308 is_true_filter = do_filter.lower() in ["true", "1"]