Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ from selenium.webdriver.common.keys import Keys
|
|
11 |
import groq
|
12 |
import os
|
13 |
import time
|
|
|
14 |
|
15 |
options = webdriver.ChromeOptions()
|
16 |
options.add_argument('--headless')
|
@@ -20,6 +21,31 @@ wd = webdriver.Chrome(options=options)
|
|
20 |
api_key = os.getenv('groq')
|
21 |
client = groq.Client(api_key=api_key)
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# Use Llama 3 70B powered by Groq for answering
|
24 |
def update(prompt, ort):
|
25 |
try:
|
@@ -39,16 +65,21 @@ def selenium(message):
|
|
39 |
#url = 'https://www.spiegel.de'
|
40 |
url = f"https://duckduckgo.com/?q=impressum {message}"
|
41 |
#<ol class="AmbQnf">
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
45 |
#return element.text
|
46 |
try:
|
47 |
completion = client.chat.completions.create(
|
48 |
model="llama3-8b-8192",
|
49 |
messages=[
|
50 |
{"role": "system", "content": "You are a helpful assistant."},
|
51 |
-
{"role": "user", "content": f"return json object with keys name and email. \n name = {message}\n value for email can be found here: {
|
52 |
],
|
53 |
)
|
54 |
return completion.choices[0].message.content
|
|
|
11 |
import groq
|
12 |
import os
|
13 |
import time
|
14 |
+
import requests
|
15 |
|
16 |
options = webdriver.ChromeOptions()
|
17 |
options.add_argument('--headless')
|
|
|
21 |
api_key = os.getenv('groq')
|
22 |
client = groq.Client(api_key=api_key)
|
23 |
|
24 |
+
|
25 |
+
def impressum_suche(message):
|
26 |
+
"""
|
27 |
+
Führt eine Anfrage an DuckDuckGo durch, um nach einem Impressum in Verbindung mit einer Nachricht zu suchen.
|
28 |
+
|
29 |
+
Args:
|
30 |
+
message: Der Suchbegriff, der zusammen mit "Impressum" verwendet wird.
|
31 |
+
|
32 |
+
Returns:
|
33 |
+
Den Inhalt der Antwort als Text, oder None im Fehlerfall.
|
34 |
+
"""
|
35 |
+
url = f"https://duckduckgo.com/?q=impressum {message}"
|
36 |
+
try:
|
37 |
+
response = requests.get(url)
|
38 |
+
response.raise_for_status() # Wirft eine Ausnahme für ungültige Statuscodes
|
39 |
+
return response.text
|
40 |
+
except requests.exceptions.RequestException as e:
|
41 |
+
print(f"Fehler beim Abrufen der URL: {e}")
|
42 |
+
return None
|
43 |
+
|
44 |
+
# Beispielaufruf:
|
45 |
+
if __name__ == "__main__":
|
46 |
+
suchbegriff = "Beispielunternehmen"
|
47 |
+
ergebnis = impressum_suche(suchbegriff)
|
48 |
+
|
49 |
# Use Llama 3 70B powered by Groq for answering
|
50 |
def update(prompt, ort):
|
51 |
try:
|
|
|
65 |
#url = 'https://www.spiegel.de'
|
66 |
url = f"https://duckduckgo.com/?q=impressum {message}"
|
67 |
#<ol class="AmbQnf">
|
68 |
+
|
69 |
+
response = requests.get(url)
|
70 |
+
response.raise_for_status() # Wirft eine Ausnahme für ungültige Statuscodes
|
71 |
+
return response.text
|
72 |
+
|
73 |
+
#wd.get(url)
|
74 |
+
#time.sleep(3)
|
75 |
+
#element = wd.find_element(By.TAG_NAME, "body")
|
76 |
#return element.text
|
77 |
try:
|
78 |
completion = client.chat.completions.create(
|
79 |
model="llama3-8b-8192",
|
80 |
messages=[
|
81 |
{"role": "system", "content": "You are a helpful assistant."},
|
82 |
+
{"role": "user", "content": f"return json object with keys name and email. \n name = {message}\n value for email can be found here: {response.text} \n return json object only, no additional text or comments \n"}
|
83 |
],
|
84 |
)
|
85 |
return completion.choices[0].message.content
|