| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | import random |
| | import openai |
| | from sentence_transformers import util |
| |
|
| | gpt_model = "gpt-3.5-turbo" |
| |
|
| |
|
| | |
| | def hint(secret, n, model, last_hint, lang, Config): |
| |
|
| | |
| | hint = "" |
| |
|
| | |
| | if n >= 3: |
| | j = random.randint(0, 2) |
| | while j == last_hint: |
| | j = random.randint(0, 2) |
| |
|
| | |
| | if j == 0: |
| | response = openai.chat.completions.create( |
| | model=gpt_model, |
| | messages=[ |
| | { |
| | "role": "user", |
| | "content": Config.hint_0_0 |
| | + secret |
| | + Config.hint_0_1 |
| | + secret |
| | + Config.hint_0_2, |
| | } |
| | ], |
| | temperature=1, |
| | max_tokens=256, |
| | top_p=1, |
| | frequency_penalty=0.5, |
| | presence_penalty=0, |
| | ) |
| | output = str(response.choices[0].message.content) |
| | output = output.replace('"', "").replace("'", "") |
| |
|
| | |
| | if lang == 0: |
| | output = ireplace("la " + secret, "La palabra secreta", output) |
| | output = ireplace("las " + secret, "La palabra secreta", output) |
| | output = ireplace("el " + secret, "La palabra secreta", output) |
| | output = ireplace("los " + secret, "La palabra secreta", output) |
| | output = ireplace("un " + secret, "La palabra secreta", output) |
| | output = ireplace("una " + secret, "La palabra secreta", output) |
| | output = ireplace("unos " + secret, "La palabra secreta", output) |
| | output = ireplace("unas " + secret, "La palabra secreta", output) |
| | elif lang == 1: |
| | output = ireplace("the " + secret, "The secret word", output) |
| | output = ireplace("a " + secret, "The secret word", output) |
| |
|
| | hint += Config.hint_0_3 + output |
| | last_hint = 0 |
| |
|
| | |
| | elif j == 1: |
| | response = openai.chat.completions.create( |
| | model=gpt_model, |
| | messages=[ |
| | { |
| | "role": "user", |
| | "content": Config.hint_1_0 + secret + Config.hint_1_1, |
| | } |
| | ], |
| | temperature=1, |
| | max_tokens=256, |
| | top_p=1, |
| | frequency_penalty=0, |
| | presence_penalty=0, |
| | ) |
| | output = str(response.choices[0].message.content) |
| | hint += Config.hint_1_2 + output |
| | last_hint = 1 |
| |
|
| | |
| | elif j == 2: |
| | response = openai.chat.completions.create( |
| | model=gpt_model, |
| | messages=[ |
| | { |
| | "role": "user", |
| | "content": Config.hint_2_0 + secret + Config.hint_2_1, |
| | } |
| | ], |
| | temperature=1, |
| | max_tokens=256, |
| | top_p=1, |
| | frequency_penalty=0, |
| | presence_penalty=0, |
| | ) |
| | output = str(response.choices[0].message.content) |
| |
|
| | hint += Config.hint_2_2 + output |
| |
|
| | last_hint = 2 |
| | |
| | else: |
| | j = random.randint(3, 4) |
| | while j == last_hint: |
| | j = random.randint(3, 4) |
| |
|
| | |
| | if j == 3: |
| | words = [] |
| | response = openai.chat.completions.create( |
| | model=gpt_model, |
| | messages=[ |
| | { |
| | "role": "user", |
| | "content": Config.hint_3_0, |
| | } |
| | ], |
| | temperature=1.25, |
| | max_tokens=256, |
| | top_p=1, |
| | frequency_penalty=0, |
| | presence_penalty=0, |
| | ) |
| | output = str(response.choices[0].message.content) |
| | output = (output.replace(" ", "").replace(".", "")).lower() |
| | words.extend(output.strip().split(",")) |
| | response = openai.chat.completions.create( |
| | model=gpt_model, |
| | messages=[ |
| | { |
| | "role": "user", |
| | "content": Config.hint_3_1 |
| | + secret |
| | + Config.hint_3_2, |
| | } |
| | ], |
| | temperature=1.1, |
| | max_tokens=256, |
| | top_p=1, |
| | frequency_penalty=0, |
| | presence_penalty=0, |
| | ) |
| | output = str(response.choices[0].message.content) |
| | output = (output.replace(".", "")).lower() |
| | words.append(output) |
| | random.shuffle(words) |
| | sentences1 = [secret, secret, secret, secret] |
| | sentences2 = words |
| | embeddings1 = model.encode(sentences1, convert_to_tensor=True) |
| | embeddings2 = model.encode(sentences2, convert_to_tensor=True) |
| |
|
| | cosine_scores = util.cos_sim(embeddings1, embeddings2) |
| | scores = cosine_scores[0].tolist() |
| | sum_scores = sum(scores) |
| | normalized_scores = [round(score * 100 / sum_scores, 1) for score in scores] |
| |
|
| | hint += Config.hint_3_3 |
| |
|
| | max_len = -1 |
| | for ele in words: |
| | if len(ele) > max_len: |
| | max_len = len(ele) |
| | longest_word = ele |
| |
|
| | for i in range(len(words)): |
| |
|
| | word_hint = words[i].ljust(len(longest_word) + 1) |
| | hint += ( |
| | |
| | word_hint |
| | + "|" |
| | + ("🟩") * round(normalized_scores[i] * 0.2) |
| | + " " |
| | + str(normalized_scores[i]) |
| | + "%\n" |
| | ) |
| | last_hint = 3 |
| |
|
| | |
| | elif j == 4: |
| | response = openai.chat.completions.create( |
| | model=gpt_model, |
| | messages=[ |
| | { |
| | "role": "user", |
| | "content": Config.hint_4_0 |
| | + secret |
| | + Config.hint_4_1, |
| | } |
| | ], |
| | temperature=1, |
| | max_tokens=256, |
| | top_p=1, |
| | frequency_penalty=0, |
| | presence_penalty=0, |
| | ) |
| | film_title = str(response.choices[0].message.content).replace('"', "") |
| | response = openai.chat.completions.create( |
| | model=gpt_model, |
| | messages=[ |
| | { |
| | "role": "user", |
| | "content": Config.hint_4_2 |
| | + film_title |
| | + Config.hint_4_3, |
| | } |
| | ], |
| | temperature=1, |
| | max_tokens=256, |
| | top_p=1, |
| | frequency_penalty=0, |
| | presence_penalty=0, |
| | ) |
| | output = str(response.choices[0].message.content) |
| | hint += Config.hint_4_4 + "\n" + output |
| | last_hint = 4 |
| |
|
| | return hint, n + 1, last_hint |
| |
|
| |
|
| | |
| | def curiosity(secret, Config): |
| |
|
| | response = openai.chat.completions.create( |
| | model=gpt_model, |
| | messages=[ |
| | { |
| | "role": "user", |
| | "content": Config.curiosity + secret + '".', |
| | } |
| | ], |
| | temperature=1, |
| | max_tokens=256, |
| | top_p=1, |
| | frequency_penalty=0, |
| | presence_penalty=0, |
| | ) |
| | output = str(response.choices[0].message.content) |
| |
|
| | return output |
| |
|
| |
|
| | |
| | def ireplace(old, new, text): |
| | idx = 0 |
| | while idx < len(text): |
| | index_l = text.lower().find(old.lower(), idx) |
| | if index_l == -1: |
| | return text |
| | text = text[:index_l] + new + text[index_l + len(old) :] |
| | idx = index_l + len(new) |
| | return text |
| |
|