Spaces:
Sleeping
Sleeping
File size: 1,095 Bytes
86c6643 01abed5 4b0b8c2 86c6643 01abed5 86c6643 b6d730f 86c6643 |
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 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 |