Update agents/tools/ai_tools.py
Browse files- agents/tools/ai_tools.py +17 -1
agents/tools/ai_tools.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
# https://docs.crewai.com/introduction
|
| 4 |
# https://ai.google.dev/gemini-api/docs
|
| 5 |
|
| 6 |
-
import base64, chess, os, time
|
| 7 |
from agents.models.llms import (
|
| 8 |
LLM_WEB_SEARCH,
|
| 9 |
LLM_WEB_BROWSER,
|
|
@@ -535,6 +535,22 @@ class AITools():
|
|
| 535 |
result = part.text
|
| 536 |
break
|
| 537 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 538 |
board = chess.Board(result) # FEN validation
|
| 539 |
|
| 540 |
print(f"🛠️ AITools: img_to_fen_tool: model={model}")
|
|
|
|
| 3 |
# https://docs.crewai.com/introduction
|
| 4 |
# https://ai.google.dev/gemini-api/docs
|
| 5 |
|
| 6 |
+
import base64, chess, os, re, time
|
| 7 |
from agents.models.llms import (
|
| 8 |
LLM_WEB_SEARCH,
|
| 9 |
LLM_WEB_BROWSER,
|
|
|
|
| 535 |
result = part.text
|
| 536 |
break
|
| 537 |
|
| 538 |
+
fen_pattern = r'\b([rnbqkpRNBQKP1-8\/]+\s+[wb]\s+(?:-|[KQkq]+)\s+(?:-|[a-h][36])\s+\d+\s+\d+)\b'
|
| 539 |
+
|
| 540 |
+
match = re.search(fen_pattern, result)
|
| 541 |
+
|
| 542 |
+
if match:
|
| 543 |
+
result = match.group(1)
|
| 544 |
+
else:
|
| 545 |
+
lines = result.strip().split("\n")
|
| 546 |
+
|
| 547 |
+
for line in lines:
|
| 548 |
+
line = line.strip()
|
| 549 |
+
|
| 550 |
+
if "/" in line and (" w " in line or " b " in line):
|
| 551 |
+
result = line
|
| 552 |
+
break
|
| 553 |
+
|
| 554 |
board = chess.Board(result) # FEN validation
|
| 555 |
|
| 556 |
print(f"🛠️ AITools: img_to_fen_tool: model={model}")
|