Spaces:
Runtime error
Runtime error
File size: 1,188 Bytes
f7b43b9 62ec04b f7b43b9 c0ab8a1 f7b43b9 017829e f7b43b9 |
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 |
import ast
import openai
from text_annotator import generate_annotated_text
def gpt_keyw_extract_n_annotator(user_text):
'''
:param user_text: str
:return: annotated_text: str
'''
task_description = "You are a Python function that extract 5 keywords from {input_text}. 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=1019,
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 |