mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-19 03:25:32 +00:00
Update Phind.py
This commit is contained in:
parent
e0541c513f
commit
79c9051743
@ -41,39 +41,46 @@ class Phind(BaseProvider):
|
|||||||
prompt = quote(format_prompt(messages))
|
prompt = quote(format_prompt(messages))
|
||||||
driver.get(f"{cls.url}/search?q={prompt}&source=searchbox")
|
driver.get(f"{cls.url}/search?q={prompt}&source=searchbox")
|
||||||
|
|
||||||
|
# Need to change settinge
|
||||||
if model.startswith("gpt-4") or creative_mode:
|
if model.startswith("gpt-4") or creative_mode:
|
||||||
wait = WebDriverWait(driver, timeout)
|
wait = WebDriverWait(driver, timeout)
|
||||||
# Open dropdown
|
# Open settings dropdown
|
||||||
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "button.text-dark.dropdown-toggle")))
|
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "button.text-dark.dropdown-toggle")))
|
||||||
driver.find_element(By.CSS_SELECTOR, "button.text-dark.dropdown-toggle").click()
|
driver.find_element(By.CSS_SELECTOR, "button.text-dark.dropdown-toggle").click()
|
||||||
# Enable GPT-4
|
# Wait for dropdown toggle
|
||||||
wait.until(EC.visibility_of_element_located((By.XPATH, "//button[text()='GPT-4']")))
|
wait.until(EC.visibility_of_element_located((By.XPATH, "//button[text()='GPT-4']")))
|
||||||
|
# Enable GPT-4
|
||||||
if model.startswith("gpt-4"):
|
if model.startswith("gpt-4"):
|
||||||
driver.find_element(By.XPATH, "//button[text()='GPT-4']").click()
|
driver.find_element(By.XPATH, "//button[text()='GPT-4']").click()
|
||||||
# Enable creative mode
|
# Enable creative mode
|
||||||
if creative_mode or creative_mode == None:
|
if creative_mode or creative_mode == None:
|
||||||
driver.find_element(By.ID, "Creative Mode").click()
|
driver.find_element(By.ID, "Creative Mode").click()
|
||||||
# Submit question
|
# Submit changes
|
||||||
driver.find_element(By.CSS_SELECTOR, ".search-bar-input-group button[type='submit']").click()
|
driver.find_element(By.CSS_SELECTOR, ".search-bar-input-group button[type='submit']").click()
|
||||||
|
# Wait for page reload
|
||||||
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".search-container")))
|
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".search-container")))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Fetch hook
|
# Add fetch hook
|
||||||
script = """
|
script = """
|
||||||
window._fetch = window.fetch;
|
window._fetch = window.fetch;
|
||||||
window.fetch = (url, options) => {
|
window.fetch = (url, options) => {
|
||||||
|
// Call parent fetch method
|
||||||
const result = window._fetch(url, options);
|
const result = window._fetch(url, options);
|
||||||
if (url != "/api/infer/answer") return result;
|
if (url != "/api/infer/answer") return result;
|
||||||
|
// Load response reader
|
||||||
result.then((response) => {
|
result.then((response) => {
|
||||||
if (!response.body.locked) {
|
if (!response.body.locked) {
|
||||||
window.reader = response.body.getReader();
|
window.reader = response.body.getReader();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// Return dummy response
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
resolve(new Response(new ReadableStream()))
|
resolve(new Response(new ReadableStream()))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
# Read response from reader
|
||||||
driver.execute_script(script)
|
driver.execute_script(script)
|
||||||
script = """
|
script = """
|
||||||
if(window.reader) {
|
if(window.reader) {
|
||||||
|
Loading…
Reference in New Issue
Block a user