mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
Update chatgpt.py
This commit is contained in:
parent
4cdecfbfb3
commit
4dfa75c6df
1 changed files with 35 additions and 14 deletions
|
@ -1,16 +1,37 @@
|
||||||
import os
|
from searxng.utils import searxng_useragent
|
||||||
import openai
|
import requests
|
||||||
|
|
||||||
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
# Engine configuration
|
||||||
engine_id = "text-davinci-002"
|
engine_type = 'online_dictionary'
|
||||||
|
categories = ['general']
|
||||||
|
paging = False
|
||||||
|
language_support = False
|
||||||
|
|
||||||
def generate_response(prompt):
|
# ChatGPT API settings
|
||||||
response = openai.Completion.create(
|
base_url = 'https://api.openai.com/v1/engines/davinci-codex/completions'
|
||||||
engine=engine_id,
|
chatgpt_api_key_var = 'chatgpt_api_key_var'
|
||||||
prompt=prompt,
|
headers = {
|
||||||
max_tokens=150,
|
'Content-Type': 'application/json',
|
||||||
n=1,
|
'Authorization': f'Bearer {chatgpt_api_key_var}'
|
||||||
stop=None,
|
}
|
||||||
temperature=0.7
|
|
||||||
)
|
# Search function
|
||||||
return response.choices[0].text.strip()
|
def request(query, params):
|
||||||
|
prompt = f"Search results summary for the query: {query}"
|
||||||
|
data = {
|
||||||
|
'prompt': prompt,
|
||||||
|
'max_tokens': 60,
|
||||||
|
'n': 1,
|
||||||
|
'stop': None,
|
||||||
|
'temperature': 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(base_url, headers=headers, json=data)
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
def response(resp):
|
||||||
|
results = []
|
||||||
|
chatgpt_response = resp['choices'][0]['text']
|
||||||
|
results.append({'title': 'ChatGPT Summary', 'content': chatgpt_response.strip()})
|
||||||
|
return results
|
||||||
|
|
Loading…
Add table
Reference in a new issue