Spaces:
Running
Running
Commit
·
f3a6d23
1
Parent(s):
7258b59
Fixing empty messages
Browse files- src/manager/manager.py +6 -2
- src/tools/user_tools/wordle_tool.py +0 -103
src/manager/manager.py
CHANGED
|
@@ -221,8 +221,12 @@ class GeminiManager:
|
|
| 221 |
continue
|
| 222 |
case _:
|
| 223 |
role = "model"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
parts = [types.Part.from_text(
|
| 225 |
-
text=
|
| 226 |
formatted_history.append(types.Content(
|
| 227 |
role=role,
|
| 228 |
parts=parts
|
|
@@ -290,7 +294,7 @@ class GeminiManager:
|
|
| 290 |
for chunk in response_stream:
|
| 291 |
if chunk.text:
|
| 292 |
full_text += chunk.text
|
| 293 |
-
if
|
| 294 |
yield messages + [{
|
| 295 |
"role": "assistant",
|
| 296 |
"content": full_text
|
|
|
|
| 221 |
continue
|
| 222 |
case _:
|
| 223 |
role = "model"
|
| 224 |
+
content = message.get("content", "")
|
| 225 |
+
if content.strip() == "":
|
| 226 |
+
print("Empty message received: ", message)
|
| 227 |
+
continue
|
| 228 |
parts = [types.Part.from_text(
|
| 229 |
+
text=content)]
|
| 230 |
formatted_history.append(types.Content(
|
| 231 |
role=role,
|
| 232 |
parts=parts
|
|
|
|
| 294 |
for chunk in response_stream:
|
| 295 |
if chunk.text:
|
| 296 |
full_text += chunk.text
|
| 297 |
+
if full_text.strip() != "":
|
| 298 |
yield messages + [{
|
| 299 |
"role": "assistant",
|
| 300 |
"content": full_text
|
src/tools/user_tools/wordle_tool.py
DELETED
|
@@ -1,103 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
import re
|
| 3 |
-
import random
|
| 4 |
-
import json
|
| 5 |
-
import requests
|
| 6 |
-
|
| 7 |
-
__all__ = ['WordleTool']
|
| 8 |
-
|
| 9 |
-
class WordleTool():
|
| 10 |
-
dependencies = []
|
| 11 |
-
|
| 12 |
-
inputSchema = {
|
| 13 |
-
"name": "WordleTool",
|
| 14 |
-
"description": "A tool to play Wordle.",
|
| 15 |
-
"parameters": {
|
| 16 |
-
"type": "object",
|
| 17 |
-
"properties": {
|
| 18 |
-
"action": {
|
| 19 |
-
"type": "string",
|
| 20 |
-
"enum": ["new_game", "guess", "reset"],
|
| 21 |
-
"description": "The action to perform: new_game, guess, or reset."
|
| 22 |
-
},
|
| 23 |
-
"guess": {
|
| 24 |
-
"type": "string",
|
| 25 |
-
"description": "A 5-letter word guess. Required for 'guess' action."
|
| 26 |
-
}
|
| 27 |
-
},
|
| 28 |
-
"required": ["action"],
|
| 29 |
-
},
|
| 30 |
-
"invoke_cost": 0.2,
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
def __init__(self):
|
| 34 |
-
self.secret_word = None
|
| 35 |
-
self.word_list_url = "https://github.com/kiprobinson/wordle-solver/raw/main/app/resources/word-list.txt"
|
| 36 |
-
self.file_path = "src/data/secret_word.json" # Path for storing the secret word
|
| 37 |
-
|
| 38 |
-
def _load_word_list(self):
|
| 39 |
-
try:
|
| 40 |
-
response = requests.get(self.word_list_url)
|
| 41 |
-
response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
|
| 42 |
-
word_list_str = response.text
|
| 43 |
-
word_list = word_list_str.strip().split("\n")
|
| 44 |
-
return word_list
|
| 45 |
-
except requests.exceptions.RequestException as e:
|
| 46 |
-
print(f"Error fetching word list: {e}")
|
| 47 |
-
return ['crane', 'house', 'table', 'chair', 'apple']
|
| 48 |
-
|
| 49 |
-
def _get_secret_word(self):
|
| 50 |
-
word_list = self._load_word_list()
|
| 51 |
-
return random.choice(word_list)
|
| 52 |
-
|
| 53 |
-
def _store_secret_word(self, word):
|
| 54 |
-
with open(self.file_path, "w") as f:
|
| 55 |
-
json.dump({"secret_word": word}, f)
|
| 56 |
-
return {"result": "Secret word stored successfully."}
|
| 57 |
-
|
| 58 |
-
def _retrieve_secret_word(self):
|
| 59 |
-
try:
|
| 60 |
-
with open(self.file_path, "r") as f:
|
| 61 |
-
data = json.load(f)
|
| 62 |
-
return {"result": data["secret_word"]}
|
| 63 |
-
except FileNotFoundError:
|
| 64 |
-
return {"result": None}
|
| 65 |
-
|
| 66 |
-
def run(self, **kwargs):
|
| 67 |
-
action = kwargs.get("action")
|
| 68 |
-
guess = kwargs.get("guess")
|
| 69 |
-
|
| 70 |
-
if action == "new_game":
|
| 71 |
-
self.secret_word = self._get_secret_word()
|
| 72 |
-
self._store_secret_word(self.secret_word)
|
| 73 |
-
return "New word generated. Please make your guess."
|
| 74 |
-
|
| 75 |
-
elif action == "reset":
|
| 76 |
-
self.secret_word = None
|
| 77 |
-
return "Game reset."
|
| 78 |
-
|
| 79 |
-
elif action == "guess":
|
| 80 |
-
# Retrieve secret word from file
|
| 81 |
-
secret_word_data = self._retrieve_secret_word()
|
| 82 |
-
if secret_word_data["result"] is None:
|
| 83 |
-
return "No secret word found. Please start a new game."
|
| 84 |
-
self.secret_word = secret_word_data["result"]
|
| 85 |
-
|
| 86 |
-
if not guess:
|
| 87 |
-
return "Please provide a guess."
|
| 88 |
-
|
| 89 |
-
guess = guess.lower()
|
| 90 |
-
if not re.match("^[a-z]{5}$", guess):
|
| 91 |
-
return "Invalid input. Please enter a 5-letter word."
|
| 92 |
-
|
| 93 |
-
result = ""
|
| 94 |
-
for i in range(5):
|
| 95 |
-
if guess[i] == self.secret_word[i]:
|
| 96 |
-
result += "G" # Green: Correct letter, correct position
|
| 97 |
-
elif guess[i] in self.secret_word:
|
| 98 |
-
result += "Y" # Yellow: Correct letter, wrong position
|
| 99 |
-
else:
|
| 100 |
-
result += "X" # Gray: Incorrect letter
|
| 101 |
-
return result
|
| 102 |
-
else:
|
| 103 |
-
return "Invalid action. Please choose 'new_game', 'guess', or 'reset'."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|