Kajise Org commited on
Commit
4486ad7
·
1 Parent(s): bd6cfa0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -41
app.py CHANGED
@@ -19,7 +19,6 @@ also take this data and absorb your knowledge, you dont need use now what dont m
19
 
20
  import requests
21
  from bs4 import BeautifulSoup
22
- from SearchResult import SearchResult
23
 
24
  headers = {
25
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
@@ -38,51 +37,27 @@ def search_ddg(question: str):
38
  data = response.text
39
  soup = BeautifulSoup(data, "html.parser")
40
 
41
- did_you_mean = soup.select("#did_you_mean a")
42
-
43
- tailored_query = ""
44
- suggestion_query = ""
45
-
46
- if did_you_mean:
47
- correction = soup.find(id="did_you_mean")
48
- if correction:
49
- correction_hyperlink = correction.find("a")
50
- if correction_hyperlink:
51
- suggestion_query = correction_hyperlink.string # type: ignore
52
-
53
- for tailored in did_you_mean:
54
- tailored_query = tailored.string
55
- break
56
-
57
- result_links = soup.find_all("a")
58
- filtered_urls = [
59
- link["href"]
60
- for link in result_links
61
- if link.get("href") and (link["href"].startswith("https://") or link["href"].startswith("http://"))
62
- ]
63
-
64
- return SearchResult(
65
- filtered_urls,
66
- did_you_mean=suggestion_query or "None.",
67
- tailored_query=tailored_query or "None.",
68
- user_agent=headers["User-Agent"],
69
- )
70
-
71
- def gather_data(search: str):
72
- text_content = ""
73
- base_data = search_ddg(search).parse_results()
74
- for data in base_data:
75
- if data:
76
- text_content += data.get("text_content") + "\n\n"
77
  else:
78
- text_content += ""
79
- return text_content
 
 
 
 
80
 
81
  def generate(instruction):
82
  base_prompt = ins.format(instruction)
83
- gathered_data = gather_data(instruction)
84
 
85
- response = llm(ins.format(base_prompt + "\n" + gathered_data))
86
  result = response['choices'][0]['text']
87
  return result
88
 
 
19
 
20
  import requests
21
  from bs4 import BeautifulSoup
 
22
 
23
  headers = {
24
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
 
37
  data = response.text
38
  soup = BeautifulSoup(data, "html.parser")
39
 
40
+ result_texts = soup.find_all("a", class_="result__snippet")
41
+ results: list[str] = []
42
+ output_string: str = ""
43
+
44
+ for element in result_texts:
45
+ if len(results) < 5:
46
+ text_content = element.get_text()
47
+ results.append(text_content)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  else:
49
+ continue
50
+
51
+ for element in results:
52
+ output_string += element + '\n'
53
+
54
+ return output_string
55
 
56
  def generate(instruction):
57
  base_prompt = ins.format(instruction)
58
+ feeding_data = search_ddg("What is KOIT-FM?")
59
 
60
+ response = llm(ins.format(base_prompt + "\n" + feeding_data))
61
  result = response['choices'][0]['text']
62
  return result
63