Spaces:
Sleeping
Sleeping
added pokedex access
Browse files
app.py
CHANGED
|
@@ -38,20 +38,64 @@ final_answer = FinalAnswerTool()
|
|
| 38 |
model = HfApiModel(
|
| 39 |
max_tokens=2096,
|
| 40 |
temperature=0.5,
|
| 41 |
-
model_id='
|
| 42 |
custom_role_conversions=None,
|
| 43 |
)
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# Import tool from Hub
|
| 47 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 48 |
|
| 49 |
with open("prompts.yaml", 'r') as stream:
|
| 50 |
prompt_templates = yaml.safe_load(stream)
|
| 51 |
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
|
|
|
| 38 |
model = HfApiModel(
|
| 39 |
max_tokens=2096,
|
| 40 |
temperature=0.5,
|
| 41 |
+
model_id='mistralai/Mistral-7B-instruct-v0.3',# it is possible that this model may be overloaded
|
| 42 |
custom_role_conversions=None,
|
| 43 |
)
|
| 44 |
|
| 45 |
+
@tool
|
| 46 |
+
def get_pokemon_information(pokemon_name: str) -> dict:
|
| 47 |
+
'''
|
| 48 |
+
This tool gives information about a pokemon.
|
| 49 |
+
The information given is
|
| 50 |
+
Moves
|
| 51 |
+
Abilities
|
| 52 |
+
Types
|
| 53 |
+
Pokémon Evolution Chains.
|
| 54 |
+
base_experience
|
| 55 |
+
stats
|
| 56 |
+
weight
|
| 57 |
+
height
|
| 58 |
+
sprites-> image url of the pokemon could be shiny
|
| 59 |
+
Use this tool to get the information about a pokemon else use the web search tool.
|
| 60 |
+
Args:
|
| 61 |
+
pokemon_name: The name of the pokemon.
|
| 62 |
+
Returns: dict
|
| 63 |
+
The information about the pokemon.
|
| 64 |
+
'''
|
| 65 |
+
try:
|
| 66 |
+
response = requests.get(f"https://pokeapi.co/api/v2/pokemon/{pokemon_name}")
|
| 67 |
+
response.raise_for_status()
|
| 68 |
+
pokemon_info_json = response.json()
|
| 69 |
+
|
| 70 |
+
pokemon_info = {
|
| 71 |
+
"moves": pokemon_info_json["moves"],
|
| 72 |
+
"abilities": pokemon_info_json["abilities"],
|
| 73 |
+
"types": pokemon_info_json["types"],
|
| 74 |
+
"evolution_chains": pokemon_info_json["evolution_chain"],
|
| 75 |
+
"base_experience": pokemon_info_json["base_experience"],
|
| 76 |
+
"stats": pokemon_info_json["stats"],
|
| 77 |
+
"weight": pokemon_info_json["weight"],
|
| 78 |
+
"height": pokemon_info_json["height"],
|
| 79 |
+
"sprites": pokemon_info_json["sprites"],
|
| 80 |
+
"pokedex_number": pokemon_info_json["id"],
|
| 81 |
+
"location_area_url": pokemon_info_json["location_area_encounters"]
|
| 82 |
+
}
|
| 83 |
+
except requests.exceptions.RequestException as e:
|
| 84 |
+
return f"Error fetching the Pokemon number: {str(e)}"
|
| 85 |
+
except Exception as e:
|
| 86 |
+
return f"An unexpected error occurred: {str(e)}"
|
| 87 |
+
return pokemon_info
|
| 88 |
+
|
| 89 |
+
web_search_tool = DuckDuckGoSearchTool()
|
| 90 |
|
| 91 |
# Import tool from Hub
|
|
|
|
| 92 |
|
| 93 |
with open("prompts.yaml", 'r') as stream:
|
| 94 |
prompt_templates = yaml.safe_load(stream)
|
| 95 |
|
| 96 |
agent = CodeAgent(
|
| 97 |
model=model,
|
| 98 |
+
tools=[final_answer, get_pokemon_information, web_search_tool], ## add your tools here (don't remove final answer)
|
| 99 |
max_steps=6,
|
| 100 |
verbosity_level=1,
|
| 101 |
grammar=None,
|