diff --git a/examples/agent/tools/search.py b/examples/agent/tools/search.py index cac894d1e..5bcddc438 100644 --- a/examples/agent/tools/search.py +++ b/examples/agent/tools/search.py @@ -1,9 +1,10 @@ +from pydantic import Field import aiohttp import itertools import json import logging import os -from typing import Dict, List +from typing import Annotated, Dict, List import urllib.parse @@ -28,19 +29,20 @@ _result_keys_by_type = { } -async def brave_search(query: str, max_results: int = 10) -> List[Dict]: +async def brave_search(*, query: str) -> List[Dict]: ''' Search the Brave Search API for the specified query. Parameters: query (str): The query to search for. - max_results (int): The maximum number of results to return (defaults to 10) Returns: List[Dict]: The search results. ''' logging.debug('[brave_search] Searching for %s', query) + max_results = 10 + url = f'https://api.search.brave.com/res/v1/web/search?q={urllib.parse.quote(query)}' headers = { 'Accept': 'application/json', diff --git a/scripts/get_hf_chat_template.py b/scripts/get_hf_chat_template.py index 49d050025..250e4c274 100644 --- a/scripts/get_hf_chat_template.py +++ b/scripts/get_hf_chat_template.py @@ -1,6 +1,6 @@ ''' Fetches the Jinja chat template of a HuggingFace model. - If a model + If a model Syntax: get_hf_chat_template.py model_id [variant] @@ -21,7 +21,7 @@ def main(args): raise ValueError("Please provide a model ID and an optional variant name") model_id = args[0] variant = None if len(args) < 2 else args[1] - + try: # Use huggingface_hub library if available. # Allows access to gated models if the user has access and ran `huggingface-cli login`. @@ -53,7 +53,7 @@ def main(args): for ct in chat_template } format_variants = lambda: ', '.join(f'"{v}"' for v in variants.keys()) - + if variant is None: if 'default' not in variants: raise Exception(f'Please specify a chat template variant (one of {format_variants()})') @@ -61,7 +61,7 @@ def main(args): print(f'Note: picked "default" chat template variant (out of {format_variants()})', file=sys.stderr) elif variant not in variants: raise Exception(f"Variant {variant} not found in chat template (found {format_variants()})") - + print(variants[variant], end=None)