Insights-summary / gpt_s.py
muhyzatar's picture
Update gpt_s.py
b6d730f verified
raw
history blame
1.1 kB
import openai
import os
openai.api_key = "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"
class GPT:
# A class for interacting with the GPT-3.5 model for topic extraction and representation.
def __init__(self, system_message):
self.system_message = system_message
def extract_insights(self, sentence):
"""
Extracts a topic from the given sentence using GPT-3.5.
Parameters:
- sentence (str): The input sentence from which the topic is to be extracted.
Returns:
str: The GPT-3.5 generated representation of the topic.
"""
messages = [
{
"role": "system",
"content": "{}".format(self.system_message)
},
]
messages.append({"role": "user", "content": "{}".format(sentence)})
chat = openai.ChatCompletion.create(
model="gpt-3.5-turbo-1106",
temperature=0.1,
max_tokens=4096,
messages=messages
)
reply = chat.choices[0].message.content
return reply