Update chatgpt.py

This commit is contained in:
RecentRichRail 2023-03-28 12:25:36 -04:00 committed by GitHub
parent 4cdecfbfb3
commit 4dfa75c6df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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