Task Creation App with GPT-3.5
In the ever-evolving landscape of AI capabilities, I continue to explore the possibility of integrating the GPT-3.5 API into the applications and how it can optimize planning process, yielding smarter, faster, and more efficient results.
In doing so, I have developed another basic web app which returns a list of tasks in an excel file. The app has been developed using Next.js and Flask, integrated with GPT-3.5’s capabilities. I have segregated the Next.js app from the Flask API, while leveraging the Next.js boilerplate code for UI development.
This API utilizes the OpenAI library to interact with the GPT-3.5 API. It constructs requests using prompt text to establish context for the model. The prompt instructs the model to generate a task list and tailor the response in JSON format. Subsequently, the JSON data is converted into an Excel file and returned as response.
Below is the code for making a request to GPT API where process_node which is a recursive method processes the JSON retrieved in response to store them in excel.
if request.method == 'POST':
jsonData = request.get_json()
modifiedPrompt = GetPromptText(jsonData["goal"], jsonData["time"])
response = openai.Completion.create(
model="text-davinci-003",
prompt=modifiedPrompt,
temperature=0.7,
max_tokens=3000
)
responseText = response.choices[0].text
responseJson = json.loads(responseText)
workbook = xlsxwriter.Workbook("output.xlsx")
sheet = workbook.add_worksheet()
process_node(sheet, responseJson, 1, 0)
workbook.close()
with open("output.xlsx", "rb") as excel_file:
response = Response(excel_file.read(), content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response.headers["Content-Disposition"] = "attachment; filename=data.xlsx"
return response
One noticeable issue is that requests can occasionally time out, especially when dealing with more complex tasks, as GPT-3.5 may require additional time to generate a response. Here the app is hosted with basic plan hence resource limitation is there.
Please check the UI app hosted on Vercel platform.
Also do checkout the repositories below to get more insights of the code.