twimbit-ai commited on
Commit
ae3b3e8
·
verified ·
1 Parent(s): 52954bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -34
app.py CHANGED
@@ -10,52 +10,31 @@ from dotenv import load_dotenv
10
  load_dotenv()
11
  # Replace with your key
12
  client = OpenAI()
13
- you_key = os.getenv("YOU_API_KEY")
14
  username = os.getenv("USERNAME")
15
  password = os.getenv('PASSWORD')
16
 
17
- def get_ai_snippets_for_query(query):
18
- headers = {"X-API-Key": you_key}
19
- params = {"query": query}
20
- return requests.get(
21
- f"https://api.ydc-index.io/search?query={query}",
22
- params=params,
23
- headers=headers,
24
- ).json().get('hits')
25
-
26
-
27
- def get_web_search_you(query):
28
- docs = get_ai_snippets_for_query(query)
29
- markdown = ""
30
- for doc in docs:
31
- for key, value in doc.items():
32
- if key == 'snippets':
33
- markdown += f"{key}:\n"
34
- for snippet in value:
35
- markdown += f"- {snippet}\n"
36
- else:
37
- markdown += f"{key}: {value}\n"
38
- markdown += "\n"
39
- return markdown
40
-
41
 
42
  def predict(message, history, _n_web_search, _strategy):
43
  # docs = get_web_search_you(message)
44
 
45
- docs = get_docs_from_web(message, history[-1:], _n_web_search, _strategy)
46
  partial_message = ''
47
  information = ''
48
- for doc in docs:
49
- if isinstance(doc, dict):
50
- information = doc.get('data')
51
- else:
52
- partial_message = partial_message + doc
53
- yield partial_message
 
 
 
 
54
  system_prompt = """
55
  You are an advanced chatbot.
56
  Today's date - {date}
57
 
58
- When answering a question, adhere to the following revised rules:
 
59
  - The "Information for reference" data is provided in the chunks with each chunk having its own source as url.
60
  - Generate human-like text in response to input, reflecting your status as a sophisticated language model.
61
  - Abstain from offering any health or medical advice and ensure all responses maintain this guideline strictly.
@@ -106,6 +85,10 @@ n_web_search = gr.Slider(1, 10, value=3, step=1, label="Web searches",
106
  strategy = gr.Radio(["Deep", "Normal", "Normal Fast"], label="Strategy", value="Normal",
107
  info="Select web search analysis type. Please keep in mind that deep analysis will take more time than normal analysis.")
108
 
109
- app = gr.ChatInterface(predict, additional_inputs=[n_web_search, strategy])
 
 
 
 
110
  app.queue(default_concurrency_limit=5)
111
  app.launch(debug=True, share=False, auth=(username, password), auth_message='Twimbit project ABM')
 
10
  load_dotenv()
11
  # Replace with your key
12
  client = OpenAI()
 
13
  username = os.getenv("USERNAME")
14
  password = os.getenv('PASSWORD')
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  def predict(message, history, _n_web_search, _strategy):
18
  # docs = get_web_search_you(message)
19
 
 
20
  partial_message = ''
21
  information = ''
22
+
23
+ if _web_search_enabled == 'On':
24
+ docs = get_docs_from_web(message, history[-1:], _n_web_search, _strategy)
25
+ for doc in docs:
26
+ if isinstance(doc, dict):
27
+ information = doc.get('data')
28
+ else:
29
+ partial_message = partial_message + doc
30
+ yield partial_message
31
+
32
  system_prompt = """
33
  You are an advanced chatbot.
34
  Today's date - {date}
35
 
36
+ When answering a question, adhere to the following revised rules:
37
+ - Use the "Information for reference" data to answer the question. If no answer found in "Information for reference" data then try to give answer.
38
  - The "Information for reference" data is provided in the chunks with each chunk having its own source as url.
39
  - Generate human-like text in response to input, reflecting your status as a sophisticated language model.
40
  - Abstain from offering any health or medical advice and ensure all responses maintain this guideline strictly.
 
85
  strategy = gr.Radio(["Deep", "Normal", "Normal Fast"], label="Strategy", value="Normal",
86
  info="Select web search analysis type. Please keep in mind that deep analysis will take more time than normal analysis.")
87
 
88
+ web_search_enabled = gr.Radio(["On", "Off"], label="Web Search", value="Off",
89
+ info="Select web search option on and off.")
90
+
91
+ app = gr.ChatInterface(predict, additional_inputs=[n_web_search, strategy, web_search_enabled])
92
+
93
  app.queue(default_concurrency_limit=5)
94
  app.launch(debug=True, share=False, auth=(username, password), auth_message='Twimbit project ABM')