-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsummerizer.py
46 lines (39 loc) · 1.46 KB
/
summerizer.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
38
39
40
41
42
43
44
45
46
import google.generativeai as genai
from openai import AzureOpenAI
import logging
import config
logger = logging.getLogger(__name__)
genai.configure(api_key=config.get_config().GEMINI_TOKEN)
client = AzureOpenAI(
# This is the default and can be omitted
api_key=config.get_config().OPENAI_TOKEN,
api_version="2023-07-01-preview",
azure_endpoint="https://mlk-openai-farhoud.openai.azure.com/",
)
summarize_system_prompt = f"""
You are a Narrator who summarize a chat history for fast boarding
"""
def gai_summarizer(messages):
text_to_summarize = "\n".join([msg[1] for msg in messages])
chat_summarize_model = genai.GenerativeModel(model_name='gemini-1.5-flash-latest',
system_instruction=summarize_system_prompt)
logger.debug("summary request: %s", text_to_summarize)
summary = chat_summarize_model.generate_content(text_to_summarize)
logger.debug("summary response: %s", summary.text)
return summary.text
def openai_summarizer(messages):
text_to_summarize = "\n".join([msg[1] for msg in messages])
chat_completion = client.chat.completions.create(
messages=[
{
"role": "system",
"content": summarize_system_prompt,
},
{
"role": "user",
"content": text_to_summarize,
}
],
model="gpt-35-turbo",
)
return chat_completion.choices[0].message.content