mgokg commited on
Commit
512941f
·
verified ·
1 Parent(s): cc3cf8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -4
app.py CHANGED
@@ -5,7 +5,15 @@ from urllib.parse import urljoin
5
 
6
  def parse_links(prompt):
7
  #anfrage ='fill in the missing contact information. do not reference the json object. do not use html tags inside the json object. it must be valid json. do not return explanaitons or any other text. thanks for your efforts:)'
8
-
 
 
 
 
 
 
 
 
9
  try:
10
  url = "http://specialist-it.de:3001/api/search"
11
 
@@ -20,7 +28,7 @@ def parse_links(prompt):
20
  },
21
  "optimizationMode": "balanced",
22
  "focusMode": "webSearch",
23
- "query": f"{prompt}. outputformat=json",
24
  "history": [
25
  ["human", "Hi, how are you?"],
26
  ["assistant", "I am doing well, how can I help you today?"]
@@ -38,8 +46,19 @@ def parse_links(prompt):
38
  #data = response.json()
39
  # Extract the message
40
  #ergebnis = data.get('message')
41
- #return ergebnis
42
- return response.json().get('message')
 
 
 
 
 
 
 
 
 
 
 
43
  # Rückgabe als Dictionary, um es mit gr.JSON kompatibel zu machen
44
  #return {"body_text": body_text}
45
 
 
5
 
6
  def parse_links(prompt):
7
  #anfrage ='fill in the missing contact information. do not reference the json object. do not use html tags inside the json object. it must be valid json. do not return explanaitons or any other text. thanks for your efforts:)'
8
+ anfrage ="""
9
+ fill in the missing contact information. do not reference the json object. do not use html tags inside the json object. it must be valid json. do not return explanaitons or any other text. thanks for your efforts:)
10
+ {
11
+ "Name": f"{prompt}",
12
+ "Email": "",
13
+ "Website": "",
14
+ "Phone": ""
15
+ }
16
+ """
17
  try:
18
  url = "http://specialist-it.de:3001/api/search"
19
 
 
28
  },
29
  "optimizationMode": "balanced",
30
  "focusMode": "webSearch",
31
+ "query": f"{anfrage}. outputformat=json",
32
  "history": [
33
  ["human", "Hi, how are you?"],
34
  ["assistant", "I am doing well, how can I help you today?"]
 
46
  #data = response.json()
47
  # Extract the message
48
  #ergebnis = data.get('message')
49
+ ergebnis = response.json().get('message')
50
+
51
+ # Split the response to get the JSON part only
52
+ json_part = ergebnis.split('}\n')[0] + '}'
53
+ # Load the JSON part to validate it's correctly formatted
54
+ try:
55
+ data = json.loads(json_part)
56
+ print(json.dumps(data, indent=2))
57
+ return json.dumps(data, indent=2)
58
+ except json.JSONDecodeError as e:
59
+ print(f"Invalid JSON: {e}"
60
+
61
+ #return response.json().get('message')
62
  # Rückgabe als Dictionary, um es mit gr.JSON kompatibel zu machen
63
  #return {"body_text": body_text}
64