mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
Update webapp.py
This commit is contained in:
parent
43e6525e86
commit
5e8a58da4b
1 changed files with 29 additions and 0 deletions
|
@ -684,6 +684,35 @@ def search():
|
||||||
try:
|
try:
|
||||||
search_query, raw_text_query, _, _ = get_search_query_from_webapp(request.preferences, request.form)
|
search_query, raw_text_query, _, _ = get_search_query_from_webapp(request.preferences, request.form)
|
||||||
# search = Search(search_query) # without plugins
|
# search = Search(search_query) # without plugins
|
||||||
|
if "什么是" in search_query.query or "怎样" in search_query.query or "给我" in search_query.query or "如何" in search_query.query or "谁是" in search_query.query or "查询" in search_query.query or "告诉我" in search_query.query or "查一下" in search_query.query or "找一个" in search_query.query or "什么样" in search_query.query or "哪个" in search_query.query or "哪些" in search_query.query or len(search_query.query>25):
|
||||||
|
if len(search_query.query>10):
|
||||||
|
prompt = search_query.query + "\n对以上问题生成一个Google搜索词:\n"
|
||||||
|
gpt = ""
|
||||||
|
gpt_url = "https://api.openai.com/v1/engines/text-davinci-003/completions"
|
||||||
|
gpt_headers = {
|
||||||
|
"Authorization": "Bearer "+os.environ['GPTKEY'],
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"OpenAI-Organization": os.environ['GPTORG']
|
||||||
|
}
|
||||||
|
gpt_data = {
|
||||||
|
"prompt": prompt,
|
||||||
|
"max_tokens": 1000,
|
||||||
|
"temperature": 0.7,
|
||||||
|
"top_p": 1,
|
||||||
|
"frequency_penalty": 0,
|
||||||
|
"presence_penalty": 0,
|
||||||
|
"best_of": 1,
|
||||||
|
"echo": False,
|
||||||
|
"logprobs": 0,
|
||||||
|
"stream": False
|
||||||
|
}
|
||||||
|
gpt_response = requests.post(gpt_url, headers=gpt_headers, data=json.dumps(gpt_data))
|
||||||
|
gpt_json = gpt_response.json()
|
||||||
|
if 'choices' in gpt_json:
|
||||||
|
gpt = gpt_json['choices'][0]['text']
|
||||||
|
gpt = gpt.replace("\n","").replace("\"","").replace("\'","")
|
||||||
|
if gpt!="":
|
||||||
|
search_query.query = gpt
|
||||||
search = SearchWithPlugins(search_query, request.user_plugins, request) # pylint: disable=redefined-outer-name
|
search = SearchWithPlugins(search_query, request.user_plugins, request) # pylint: disable=redefined-outer-name
|
||||||
|
|
||||||
result_container = search.search()
|
result_container = search.search()
|
||||||
|
|
Loading…
Add table
Reference in a new issue