-
Notifications
You must be signed in to change notification settings - Fork 0
/
summarizer.py
37 lines (31 loc) · 1.03 KB
/
summarizer.py
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
from configparser import ConfigParser
import openai
config = ConfigParser()
config.read('config.ini')
def summarize_text(text):
"""
This function uses the OpenAI Chat completion api to summarize provided text.
:param text: the text which will be summarized
:return: summarized text
"""
model = config.get('OPENAI', 'model')
temperature = config.getfloat('OPENAI', 'temperature')
max_tokens = config.getint('OPENAI', 'max_tokens')
top_p = config.getint('OPENAI', 'top_p')
response = openai.chat.completions.create(
model=model,
messages=[
{
"role": "system",
"content": "Summarize content you are provided with for a second-grade student."
},
{
"role": "user",
"content": f"Summarize the following text in one sentence:\n\n{text}"
}
],
temperature=temperature,
max_tokens=max_tokens,
top_p=top_p
)
return response.choices[0].message.content