forked from beat-b/CProjectG6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreviews_utils.py
More file actions
38 lines (30 loc) · 1.24 KB
/
reviews_utils.py
File metadata and controls
38 lines (30 loc) · 1.24 KB
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
import random
import pandas as pd
def get_random_rating(random_item):
if random_item == 'ExcellentRating':
return round(random.uniform(4.1, 5), 1)
elif random_item == 'VeryGoodRating':
return round(random.uniform(3.1, 4), 1)
elif random_item == 'AverageRating':
return round(random.uniform(2.1, 3), 1)
elif random_item == 'PoorRating':
return round(random.uniform(1.1, 2), 1)
else:
return round(random.uniform(0, 1), 1)
def get_rating(row, rating_columns):
# Generate weights based on quantities of ratings
weights = [row[col] / row[rating_columns].sum() for col in rating_columns]
# Use random.choices to pick a random item based on weights
random_item = random.choices(rating_columns, weights=weights, k=1)[0]
return get_random_rating(random_item)
def get_completion(prompt, client, model="gpt-3.5-turbo", temperature=1, messages=None):
if not messages:
messages = [{"role": "user", "content": prompt}]
else:
messages.append({"role": "user", "content": prompt})
completion = client.chat.completions.create(
model=model,
messages=messages,
temperature=temperature,
)
return completion.choices[0].message.content