Spaces:
Paused
Paused
Add a tool providing random ayah location
Browse files
app.py
CHANGED
|
@@ -7,6 +7,21 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
@tool
|
| 11 |
def get_quran_ayah(surah_number: int, ayah_number: int) -> str:
|
| 12 |
"""Fetches a specific ayah arabic and translation textes from the Quran API for the specified surah and ayah numbers.
|
|
@@ -66,7 +81,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 66 |
|
| 67 |
agent = CodeAgent(
|
| 68 |
model=model,
|
| 69 |
-
tools=[get_quran_ayah, final_answer], ## add your tools here (don't remove final answer)
|
| 70 |
max_steps=6,
|
| 71 |
verbosity_level=1,
|
| 72 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
@tool
|
| 11 |
+
def get_random_ayah_number(surah_number: int = None) -> str:
|
| 12 |
+
"""Returns random Quran ayah location info.
|
| 13 |
+
Args:
|
| 14 |
+
surah_number: The surah number. If None, a random surah is chosen.
|
| 15 |
+
"""
|
| 16 |
+
import random
|
| 17 |
+
ayahs_meta = [7, 286, 200, 176, 120, 165, 206, 75, 129, 109, 123, 111, 43, 52, 99, 128,111, 110, 98, 135, 112, 78, 118, 64, 77, 227, 93, 88, 69, 60, 34, 30, 73, 54, 45, 83, 182, 88, 75, 85, 54, 53, 89, 59, 37, 35, 38, 29, 18, 45, 60, 49, 62, 55, 78, 96, 29, 22, 24, 13, 14, 11, 11, 18, 12, 12, 30, 52, 52, 44, 28, 28, 20, 56, 40, 31, 50, 40, 46, 42, 29, 19, 36, 25, 22, 17, 19, 26, 30, 20, 15, 21, 11, 8, 8, 19, 5, 8, 8, 11, 11, 8, 3, 9, 5, 4, 7, 3, 6, 3, 5, 4, 5, 6]
|
| 18 |
+
if surah_number is not None:
|
| 19 |
+
ayah = random.randint(1, ayahs_meta[surah_number-1])
|
| 20 |
+
else:
|
| 21 |
+
surah = random.randint(1, 114)
|
| 22 |
+
ayah = random.randint(1, ayahs_meta[surah-1])
|
| 23 |
+
return "Surah " + str(surah) + " ayah " + str(ayah)
|
| 24 |
+
|
| 25 |
@tool
|
| 26 |
def get_quran_ayah(surah_number: int, ayah_number: int) -> str:
|
| 27 |
"""Fetches a specific ayah arabic and translation textes from the Quran API for the specified surah and ayah numbers.
|
|
|
|
| 81 |
|
| 82 |
agent = CodeAgent(
|
| 83 |
model=model,
|
| 84 |
+
tools=[get_random_ayah_number, get_quran_ayah, final_answer], ## add your tools here (don't remove final answer)
|
| 85 |
max_steps=6,
|
| 86 |
verbosity_level=1,
|
| 87 |
grammar=None,
|