-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsummarizer.py
More file actions
31 lines (26 loc) · 893 Bytes
/
summarizer.py
File metadata and controls
31 lines (26 loc) · 893 Bytes
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
from openai import OpenAI
from config.settings import Settings
class Summarizer:
def __init__(self, config: Settings):
self.api_key = config.API_KEY
self.base_url = config.BASE_URL
self.model = config.MODEL
self.client = OpenAI(
base_url=self.base_url,
api_key=self.api_key,
)
def summarize(self, text: str) -> str:
try:
completion = self.client.chat.completions.create(
model = self.model,
messages=[
{
"role": "user",
"content": f"Summarize this text:\n\n{text}"
}
]
)
result = completion.choices[0].message.content
return result
except Exception as e:
raise Exception(f"Summarization error: {str(e)}")