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

XFEstudio/gpt4free

Update Phind.py

79c90517
H Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +11 -4
Modified g4f/Provider/Phind.py +11 -4
@@ -41,39 +41,46 @@ class Phind(BaseProvider):
41 41 prompt = quote(format_prompt(messages))
42 42 driver.get(f"{cls.url}/search?q={prompt}&source=searchbox")
43 43
44 # Need to change settinge
44 45 if model.startswith("gpt-4") or creative_mode:
45 46 wait = WebDriverWait(driver, timeout)
46 # Open dropdown
47 # Open settings dropdown
47 48 wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "button.text-dark.dropdown-toggle")))
48 49 driver.find_element(By.CSS_SELECTOR, "button.text-dark.dropdown-toggle").click()
49 # Enable GPT-4
50 # Wait for dropdown toggle
50 51 wait.until(EC.visibility_of_element_located((By.XPATH, "//button[text()='GPT-4']")))
52 # Enable GPT-4
51 53 if model.startswith("gpt-4"):
52 54 driver.find_element(By.XPATH, "//button[text()='GPT-4']").click()
53 55 # Enable creative mode
54 56 if creative_mode or creative_mode == None:
55 57 driver.find_element(By.ID, "Creative Mode").click()
56 # Submit question
58 # Submit changes
57 59 driver.find_element(By.CSS_SELECTOR, ".search-bar-input-group button[type='submit']").click()
60 # Wait for page reload
58 61 wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".search-container")))
59 62
60 63 try:
61 # Fetch hook
64 # Add fetch hook
62 65 script = """
63 66 window._fetch = window.fetch;
64 67 window.fetch = (url, options) => {
68 // Call parent fetch method
65 69 const result = window._fetch(url, options);
66 70 if (url != "/api/infer/answer") return result;
71 // Load response reader
67 72 result.then((response) => {
68 73 if (!response.body.locked) {
69 74 window.reader = response.body.getReader();
70 75 }
71 76 });
77 // Return dummy response
72 78 return new Promise((resolve, reject) => {
73 79 resolve(new Response(new ReadableStream()))
74 80 });
75 81 }
76 82 """
83 # Read response from reader
77 84 driver.execute_script(script)
78 85 script = """
79 86 if(window.reader) {