mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
Create chatgpt.py
This commit is contained in:
parent
0c5266e2d4
commit
57b1405cbe
1 changed files with 28 additions and 0 deletions
28
searx/engines/chatgpt.py
Normal file
28
searx/engines/chatgpt.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import os
|
||||||
|
from flask import Flask, jsonify, request
|
||||||
|
import openai
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# retrieve ChatGPT API key from system variable
|
||||||
|
API_KEY = os.environ.get("CHATGPT_API_KEY")
|
||||||
|
|
||||||
|
# initialize OpenAI API client
|
||||||
|
openai.api_key = API_KEY
|
||||||
|
engine_id = "text-davinci-002"
|
||||||
|
|
||||||
|
@app.route('/chatgpt', methods=['GET'])
|
||||||
|
def chatgpt():
|
||||||
|
query = request.args.get('query')
|
||||||
|
response = openai.Completion.create(
|
||||||
|
engine=engine_id,
|
||||||
|
prompt=query,
|
||||||
|
max_tokens=150,
|
||||||
|
n=1,
|
||||||
|
stop="\n"
|
||||||
|
)
|
||||||
|
chatgpt_response = response.choices[0].text
|
||||||
|
return chatgpt_response
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run()
|
Loading…
Add table
Reference in a new issue