Commit
·
d364047
1
Parent(s):
1492293
additional prompt
Browse files- openai_api.py +8 -4
openai_api.py
CHANGED
@@ -16,8 +16,12 @@ def sentiment(text):
|
|
16 |
# Create a prompt for the model
|
17 |
prompt = f"""You are trained to analyze and detect the sentiment of the given text.
|
18 |
If you are unsure of an answer, you can say "not sure" and recommend the user review manually.
|
19 |
-
Analyze the following text and determine if the sentiment is: POSITIVE, NEGATIVE
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
22 |
# Call the OpenAI API to generate a response
|
23 |
response = client.chat.completions.create(
|
@@ -26,11 +30,11 @@ def sentiment(text):
|
|
26 |
{"role": "system", "content": "You are a helpful assistant."},
|
27 |
{"role": "user", "content": prompt}
|
28 |
],
|
29 |
-
max_tokens=1, # Limit response to a single word
|
30 |
temperature=0 # Keep response consistent
|
31 |
)
|
32 |
print(response)
|
33 |
# Extract the sentiment from the response
|
34 |
-
sentiment = response.choices[0].message.content.strip()
|
35 |
|
36 |
return sentiment
|
|
|
16 |
# Create a prompt for the model
|
17 |
prompt = f"""You are trained to analyze and detect the sentiment of the given text.
|
18 |
If you are unsure of an answer, you can say "not sure" and recommend the user review manually.
|
19 |
+
Analyze the following text and determine if the sentiment is: POSITIVE, NEGATIVE or NEUTRAL.
|
20 |
+
Reply in single word.
|
21 |
+
Examples
|
22 |
+
Input: dress was beautiful. Output: POSITIVE
|
23 |
+
Input: pizza had weird smell. Output: NEGATIVE
|
24 |
+
Input: {text}. Output:"""
|
25 |
|
26 |
# Call the OpenAI API to generate a response
|
27 |
response = client.chat.completions.create(
|
|
|
30 |
{"role": "system", "content": "You are a helpful assistant."},
|
31 |
{"role": "user", "content": prompt}
|
32 |
],
|
33 |
+
# max_tokens=1, # Limit response to a single word
|
34 |
temperature=0 # Keep response consistent
|
35 |
)
|
36 |
print(response)
|
37 |
# Extract the sentiment from the response
|
38 |
+
sentiment = response.choices[0].message.content.strip()
|
39 |
|
40 |
return sentiment
|