42 lines
856 B
Python
42 lines
856 B
Python
import openai
|
|
from flask import Flask
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
app = Flask(__name__)
|
|
|
|
load_dotenv()
|
|
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
@app.route('/')
|
|
def generate_summarizer(
|
|
max_tokens,
|
|
temperature,
|
|
top_p,
|
|
frequency_penalty,
|
|
prompt,
|
|
person_type,
|
|
):
|
|
res = openai.ChatCompletion.create(
|
|
model="gpt-3.5-turbo",
|
|
max_tokens=100,
|
|
temperature=0.7,
|
|
top_p=0.5,
|
|
frequency_penalty=0.5,
|
|
messages=
|
|
[
|
|
{
|
|
"role": "system",
|
|
"content": "You are a helpful assistant for text summarization.",
|
|
},
|
|
{
|
|
"role": "user",
|
|
"content": f"Summarize this for a {person_type}: {prompt}",
|
|
},
|
|
],
|
|
)
|
|
return res["choices"][0]["message"]["content"]
|
|
|
|
if __name__ == '__main__':
|
|
app.run()
|