Api for generating writing task 2 questions and add postman collection.
This commit is contained in:
43
app.py
43
app.py
@@ -2,7 +2,7 @@ from flask import Flask, request
|
||||
from flask_jwt_extended import JWTManager, jwt_required
|
||||
from functools import reduce
|
||||
from helper.token_counter import count_tokens
|
||||
from helper.process_response import make_openai_call
|
||||
from helper.openai_interface import make_openai_call
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
@@ -14,6 +14,11 @@ app = Flask(__name__)
|
||||
app.config['JWT_SECRET_KEY'] = os.getenv("JWT_SECRET_KEY")
|
||||
jwt = JWTManager(app)
|
||||
|
||||
GRADING_TEMPERATURE = 0.1
|
||||
GEN_QUESTION_TEMPERATURE = 0.7
|
||||
WRITING_TASK_2_POST_FIELDS = ['overall', 'comment', 'task_response']
|
||||
WRITING_TASK_2_GET_FIELDS = ['question']
|
||||
|
||||
@app.route('/writing_task2', methods=['POST'])
|
||||
@jwt_required()
|
||||
def grade_writing_task():
|
||||
@@ -58,7 +63,41 @@ def grade_writing_task():
|
||||
]
|
||||
token_count = reduce(lambda count, item: count + count_tokens(item)['n_tokens'],
|
||||
map(lambda x: x["content"], filter(lambda x: "content" in x, messages)), 0)
|
||||
response = make_openai_call(messages, token_count)
|
||||
response = make_openai_call(messages, token_count, WRITING_TASK_2_POST_FIELDS, GRADING_TEMPERATURE)
|
||||
return response
|
||||
|
||||
@app.route('/writing_task2', methods=['GET'])
|
||||
@jwt_required()
|
||||
def get_writing_task_question():
|
||||
messages = [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are a IELTS program that generates questions for the exams.",
|
||||
},
|
||||
{
|
||||
"role": "system",
|
||||
"content": "The question you have to generate is of type Writing Task 2 and is the following.",
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "It is mandatory for you to provide your response with the question "
|
||||
"in the following json format: {'question': 'question'}",
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Example output: { 'question': 'We are becoming increasingly dependent on computers. "
|
||||
"They are used in businesses, hospitals, crime detection and even to fly planes. What things will "
|
||||
"they be used for in the future? Is this dependence on computers a good thing or should we he more "
|
||||
"auspicious of their benefits?'}",
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Generate a question for IELTS exam Writing Task 2.",
|
||||
},
|
||||
]
|
||||
token_count = reduce(lambda count, item: count + count_tokens(item)['n_tokens'],
|
||||
map(lambda x: x["content"], filter(lambda x: "content" in x, messages)), 0)
|
||||
response = make_openai_call(messages, token_count, WRITING_TASK_2_GET_FIELDS, GEN_QUESTION_TEMPERATURE)
|
||||
return response
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user