Spaces:
Runtime error
Runtime error
File size: 4,751 Bytes
cad9fb2 e08b530 cad9fb2 e08b530 cad9fb2 e08b530 cad9fb2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
import ast
import openai
from text_annotator import generate_annotated_text
def gpt_summary_generator(user_text):
'''
:param user_text:
:return:
'''
task_description_fs = "Summarize the text in 500 characters in Korean."
user_prompt = f"{user_text}"
messages = [{"role": "system", "content": task_description_fs}, {"role": "user", "content": user_prompt}]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k",
messages=messages,
temperature=0.06,
max_tokens=8362,
top_p=0,
frequency_penalty=0,
presence_penalty=0
)
gpt_summary = response['choices'][0]['message']['content']
return gpt_summary
def gpt_keyword_highlighter(user_text):
'''
:param user_text: str
:return: annotated_text: str
'''
# get keywords from user_text
task_description = "You are a Python function that extracts 5 keywords from {input_text} considering {overall_text_contents}. The output should be formatted as ['keyword1', 'keyword2', ...]. Return only the function's output, with no additional explanations."
user_prompt = r"{input_text}=" + f"{user_text}"
messages = [{"role": "system", "content": task_description}, {"role": "user", "content": user_prompt}]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
temperature=0,
max_tokens=2006,
top_p=0,
frequency_penalty=0,
presence_penalty=0
)
extracted_keywords = response['choices'][0]['message']['content']
## literal_eval ํจ์๋ฅผ ์ฌ์ฉํ์ฌ string์ list๋ก ๋ณํ
extracted_keywords = ast.literal_eval(extracted_keywords)
## highlighted_text ํ์ฒ๋ฆฌ ํจ์ ์ถ๊ฐ
highlighted_text = generate_annotated_text(text=user_text, keyw_list=extracted_keywords)
return highlighted_text
def gpt_text_naturalizer(user_input):
paraphrasing_task = f"Rewrite the contents of '{user_input}' so that it will pass the writing test."
messages = [
{"role": "system", "content": "You are a helpful assistant. use only korean"},
{"role": "user", "content": paraphrasing_task}
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k",
messages=messages,
temperature=0.1,
max_tokens=2500
)
paraphrased_text = response['choices'][0]['message']['content']
return paraphrased_text
def gpt_explanation_generator(user_input, text_to_consider):
explanation_task = f"Explain the term '{user_input}' in a simple manner, based on the context of the following passage: {text_to_consider}"
messages = [
{"role": "system",
"content": "You are a helpful assistant that explains complex topics in a way that an elementary school student can understand. use only korean"},
{"role": "user", "content": explanation_task}
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k",
messages=messages,
temperature=0.1,
max_tokens=200
)
explanation = response['choices'][0]['message']['content']
return explanation
def gpt_easier_text_generator(user_input):
messages = [
{"role": "system",
"content": "You have a special talent for easily rewriting text. Make it easy to paraphrase, use simple words that an elementary school student can understand, but don't shorten or summarize. Don't forget to use only korean."},
{"role": "user", "content": user_input}
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
temperature=0,
max_tokens=2048
)
explanation = response['choices'][0]['message']['content']
def gpt_rater(user_input):
# ๋ฃจ๋ธ๋ฆญ์ ์ํ ์ฑ์
lubric = """์ฑ์ ๊ธฐ์ค ์: ๋ฌธ์ฅ์ ์ฃผ์ ๋ฅผ ํ์
ํ๊ณ , ์ฃผ์ ๋ด์ฉ์ ํ์
ํ ์ ์๋ค. ์ค: ๋ฌธ์ฅ์ ์ฃผ์ ๋ฅผ ํ์
ํ ์ ์๋ค. ํ: ๋ฌธ์ฅ์ ์ฃผ์ ๋ฅผ ํ์
ํ ์ ์๋ค."""
# ๋ฃจ๋ธ๋ฆญ ๊ธฐ์ค์ ์ด์ฉํด์ ์
๋ ฅ์นธ์ ์
๋ ฅํ ๋ด์ฉ์ ์ฑ์ ํ๋ ์์ด๋ก ํ๋กฌํํธ
explanation_task = f"{lubric}์ ๊ธฐ์ค์ผ๋ก {user_input}์ ๋ด์ฉ์ ์ฑ์ ํด์ฃผ์ธ์. ์ฑ์ ๊ธฐ์ค์ ๊ณต๊ฐํ์ง ๋ง๊ณ ์, ์ค,ํ๋ก ๋๋๊ณ ๊ฐ๋จํ ์ด์ ๋ฅผ ์๋ ค์ฃผ์ธ์."
messages = [
{"role": "system", "content": "You are a helpful assistant. use only korean"},
{"role": "user", "content": explanation_task}
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k",
messages=messages,
temperature=0.1,
max_tokens=2500
)
feedback = response['choices'][0]['message']['content']
return feedback |