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
57b1405cbe
commit
4cdecfbfb3
1 changed files with 6 additions and 18 deletions
|
@ -1,28 +1,16 @@
|
||||||
import os
|
import os
|
||||||
from flask import Flask, jsonify, request
|
|
||||||
import openai
|
import openai
|
||||||
|
|
||||||
app = Flask(__name__)
|
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
||||||
|
|
||||||
# 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"
|
engine_id = "text-davinci-002"
|
||||||
|
|
||||||
@app.route('/chatgpt', methods=['GET'])
|
def generate_response(prompt):
|
||||||
def chatgpt():
|
|
||||||
query = request.args.get('query')
|
|
||||||
response = openai.Completion.create(
|
response = openai.Completion.create(
|
||||||
engine=engine_id,
|
engine=engine_id,
|
||||||
prompt=query,
|
prompt=prompt,
|
||||||
max_tokens=150,
|
max_tokens=150,
|
||||||
n=1,
|
n=1,
|
||||||
stop="\n"
|
stop=None,
|
||||||
|
temperature=0.7
|
||||||
)
|
)
|
||||||
chatgpt_response = response.choices[0].text
|
return response.choices[0].text.strip()
|
||||||
return chatgpt_response
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app.run()
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue