Spaces:
Runtime error
Runtime error
Sohyun Sim
commited on
Commit
·
8a87758
1
Parent(s):
e483d1b
add rule.md
Browse files- app.py +7 -6
- data/rule.md +8 -0
- src/functions.py +8 -2
- src/semantle.py +4 -4
app.py
CHANGED
|
@@ -10,10 +10,10 @@ from src.functions import get_functions
|
|
| 10 |
from src.utils import add_guess
|
| 11 |
|
| 12 |
GPT_MODEL = "gpt-3.5-turbo"
|
| 13 |
-
TITLE = "
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
def _execute_function(function_call, chat_messages):
|
| 19 |
# Step 3: call the function
|
|
@@ -46,10 +46,12 @@ def _execute_function(function_call, chat_messages):
|
|
| 46 |
|
| 47 |
def create_chat(key, user_input):
|
| 48 |
openai.api_key = key
|
| 49 |
-
chat_messages = [
|
|
|
|
|
|
|
| 50 |
response = openai.ChatCompletion.create(
|
| 51 |
model=GPT_MODEL,
|
| 52 |
-
messages=
|
| 53 |
functions=get_functions()
|
| 54 |
)
|
| 55 |
response_message = response.choices[0].message.to_dict()
|
|
@@ -64,7 +66,6 @@ def create_chat(key, user_input):
|
|
| 64 |
return chat_messages[-1]
|
| 65 |
|
| 66 |
with gr.Blocks() as demo:
|
| 67 |
-
|
| 68 |
with gr.Row():
|
| 69 |
gr.Markdown(
|
| 70 |
"""
|
|
|
|
| 10 |
from src.utils import add_guess
|
| 11 |
|
| 12 |
GPT_MODEL = "gpt-3.5-turbo"
|
| 13 |
+
TITLE = "やりとりイミトル"
|
| 14 |
|
| 15 |
+
with open("data/rule.md", "r", encoding="utf-8") as f:
|
| 16 |
+
RULEBOOK = "\n".join(f.readlines())
|
| 17 |
|
| 18 |
def _execute_function(function_call, chat_messages):
|
| 19 |
# Step 3: call the function
|
|
|
|
| 46 |
|
| 47 |
def create_chat(key, user_input):
|
| 48 |
openai.api_key = key
|
| 49 |
+
chat_messages = [
|
| 50 |
+
{"role": "system", "content": "あなたはiritoruというゲームの進行役です。ユーザーが答えを言ったり、ゲームに関するリクエストをしたら、短くても丁寧に答えてください。"},
|
| 51 |
+
{"role": "user", "content": user_input}]
|
| 52 |
response = openai.ChatCompletion.create(
|
| 53 |
model=GPT_MODEL,
|
| 54 |
+
messages=chat_messages,
|
| 55 |
functions=get_functions()
|
| 56 |
)
|
| 57 |
response_message = response.choices[0].message.to_dict()
|
|
|
|
| 66 |
return chat_messages[-1]
|
| 67 |
|
| 68 |
with gr.Blocks() as demo:
|
|
|
|
| 69 |
with gr.Row():
|
| 70 |
gr.Markdown(
|
| 71 |
"""
|
data/rule.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# イミトル(Imitoru)
|
| 2 |
+
|
| 3 |
+
## ゲームの遊び方
|
| 4 |
+
今日の言葉を当てるゲームです。 正解と推測される単語を答えると、正解かどうかがわかります。正解でない場合、正解に近い度合いと順位がわかります。正解に近い程度とは単語の意味や文脈、単語の言語的特性などによって決まります。 推測した単語の近い度合いと順位を参考にして、答えを当て続けてみてください。
|
| 5 |
+
もし正解が難しかったり、ゲームのルールがわかりにくい場合は、ヒントを求めることができます。正解を直接聞くことはできませんが、正解に関する様々な情報を得ることができます。
|
| 6 |
+
|
| 7 |
+
## 正解の単語について
|
| 8 |
+
正解の単語には、固有名詞、助詞、感動詞、及び記号以外の品詞の基本形の単語が含まれています。 正解の単語は、よく使われる表記に従っています。ただし推理する場合は、すべての表記を試すことができます。 同じ単語でも、表記によって類似度が異なる場合は、単語が使用される文脈が反映されていると考えることもできます。 ひらがなやカタカナの表記をする場合は、同音異字の場合にも注意してください。
|
src/functions.py
CHANGED
|
@@ -47,13 +47,19 @@ update_history = {"name": "update_history",
|
|
| 47 |
},
|
| 48 |
"guess_history": {
|
| 49 |
"type": "object",
|
| 50 |
-
"description": "A dataframe containing the guessed words and its
|
| 51 |
}
|
| 52 |
},
|
| 53 |
"required": ["current_guess", "guess_history"]
|
| 54 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
def get_functions():
|
| 58 |
-
functions = [guess_word, lookup_answer]
|
| 59 |
return functions
|
|
|
|
| 47 |
},
|
| 48 |
"guess_history": {
|
| 49 |
"type": "object",
|
| 50 |
+
"description": "A dataframe containing the guessed words and its score and rank in a row."
|
| 51 |
}
|
| 52 |
},
|
| 53 |
"required": ["current_guess", "guess_history"]
|
| 54 |
}}
|
| 55 |
+
retrieve_rule = {"name": "retrieve_rule",
|
| 56 |
+
"description": "Use this function to retrieve the game rule for clarification of your response.",
|
| 57 |
+
"parametrs": {
|
| 58 |
+
"type": "object",
|
| 59 |
+
"properties": {},
|
| 60 |
+
}}
|
| 61 |
|
| 62 |
|
| 63 |
def get_functions():
|
| 64 |
+
functions = [guess_word, lookup_answer, retrieve_puzzle_num, update_history, retrieve_rule]
|
| 65 |
return functions
|
src/semantle.py
CHANGED
|
@@ -4,7 +4,7 @@ import requests
|
|
| 4 |
|
| 5 |
def get_secret(puzzle_num: int):
|
| 6 |
request_url = f"https://semantoru.com/yesterday/{puzzle_num+1}"
|
| 7 |
-
response = requests.get(request_url)
|
| 8 |
if response.status_code == 200:
|
| 9 |
return response.content
|
| 10 |
else:
|
|
@@ -12,7 +12,7 @@ def get_secret(puzzle_num: int):
|
|
| 12 |
|
| 13 |
def get_guess(word: str, puzzle_num: int):
|
| 14 |
request_url = f"https://semantoru.com/guess/{puzzle_num}/{word}"
|
| 15 |
-
response = requests.get(request_url)
|
| 16 |
print(response.status_code)
|
| 17 |
if response.status_code == 200:
|
| 18 |
return response.json()
|
|
@@ -22,5 +22,5 @@ def get_guess(word: str, puzzle_num: int):
|
|
| 22 |
"rank": None}
|
| 23 |
|
| 24 |
def get_puzzle_num():
|
| 25 |
-
|
| 26 |
-
return (utc.localize(datetime.utcnow()).astimezone(timezone('Asia/Tokyo')).date() -
|
|
|
|
| 4 |
|
| 5 |
def get_secret(puzzle_num: int):
|
| 6 |
request_url = f"https://semantoru.com/yesterday/{puzzle_num+1}"
|
| 7 |
+
response = requests.get(request_url, timeout=5)
|
| 8 |
if response.status_code == 200:
|
| 9 |
return response.content
|
| 10 |
else:
|
|
|
|
| 12 |
|
| 13 |
def get_guess(word: str, puzzle_num: int):
|
| 14 |
request_url = f"https://semantoru.com/guess/{puzzle_num}/{word}"
|
| 15 |
+
response = requests.get(request_url, timeout=5)
|
| 16 |
print(response.status_code)
|
| 17 |
if response.status_code == 200:
|
| 18 |
return response.json()
|
|
|
|
| 22 |
"rank": None}
|
| 23 |
|
| 24 |
def get_puzzle_num():
|
| 25 |
+
fisrt_day = date(2023, 4, 2)
|
| 26 |
+
return (utc.localize(datetime.utcnow()).astimezone(timezone('Asia/Tokyo')).date() - fisrt_day).days
|