Spaces:
Sleeping
Sleeping
Create gppt_s.py
Browse files
gppt_s.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import os
|
3 |
+
|
4 |
+
openai.api_key = "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"
|
5 |
+
|
6 |
+
class GPT:
|
7 |
+
# A class for interacting with the GPT-3.5 model for topic extraction and representation.
|
8 |
+
def __init__(self, config):
|
9 |
+
"""
|
10 |
+
Initializes the GPT instance with the provided configuration.
|
11 |
+
Parameters:
|
12 |
+
- config (dict): Configuration settings for the GPT instance.
|
13 |
+
"""
|
14 |
+
self.config = config
|
15 |
+
|
16 |
+
def extract_insights(self, sentence):
|
17 |
+
"""
|
18 |
+
Extracts a topic from the given sentence using GPT-3.5.
|
19 |
+
Parameters:
|
20 |
+
- sentence (str): The input sentence from which the topic is to be extracted.
|
21 |
+
Returns:
|
22 |
+
str: The GPT-3.5 generated representation of the topic.
|
23 |
+
"""
|
24 |
+
messages = [
|
25 |
+
{
|
26 |
+
"role": "system",
|
27 |
+
"content": "You are a summarizer, you give a comprehensive summary of a transcription you will be provided with. Give back the summary in the same langugae of the text you recieve."
|
28 |
+
},
|
29 |
+
]
|
30 |
+
messages.append({"role": "user", "content": "{}".format(sentence)})
|
31 |
+
chat = openai.ChatCompletion.create(
|
32 |
+
model="gpt-4-1106",
|
33 |
+
temperature=0.1,
|
34 |
+
max_tokens=4096,
|
35 |
+
messages=messages
|
36 |
+
)
|
37 |
+
reply = chat.choices[0].message.content
|
38 |
+
return reply
|