agent
: hard-code max_results=10 in brave_search
This commit is contained in:
parent
26e76f9704
commit
6b4a454735
2 changed files with 9 additions and 7 deletions
|
@ -1,9 +1,10 @@
|
||||||
|
from pydantic import Field
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from typing import Dict, List
|
from typing import Annotated, Dict, List
|
||||||
import urllib.parse
|
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.
|
Search the Brave Search API for the specified query.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
query (str): The query to search for.
|
query (str): The query to search for.
|
||||||
max_results (int): The maximum number of results to return (defaults to 10)
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List[Dict]: The search results.
|
List[Dict]: The search results.
|
||||||
'''
|
'''
|
||||||
logging.debug('[brave_search] Searching for %s', query)
|
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)}'
|
url = f'https://api.search.brave.com/res/v1/web/search?q={urllib.parse.quote(query)}'
|
||||||
headers = {
|
headers = {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'''
|
'''
|
||||||
Fetches the Jinja chat template of a HuggingFace model.
|
Fetches the Jinja chat template of a HuggingFace model.
|
||||||
If a model
|
If a model
|
||||||
|
|
||||||
Syntax:
|
Syntax:
|
||||||
get_hf_chat_template.py model_id [variant]
|
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")
|
raise ValueError("Please provide a model ID and an optional variant name")
|
||||||
model_id = args[0]
|
model_id = args[0]
|
||||||
variant = None if len(args) < 2 else args[1]
|
variant = None if len(args) < 2 else args[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Use huggingface_hub library if available.
|
# Use huggingface_hub library if available.
|
||||||
# Allows access to gated models if the user has access and ran `huggingface-cli login`.
|
# 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
|
for ct in chat_template
|
||||||
}
|
}
|
||||||
format_variants = lambda: ', '.join(f'"{v}"' for v in variants.keys())
|
format_variants = lambda: ', '.join(f'"{v}"' for v in variants.keys())
|
||||||
|
|
||||||
if variant is None:
|
if variant is None:
|
||||||
if 'default' not in variants:
|
if 'default' not in variants:
|
||||||
raise Exception(f'Please specify a chat template variant (one of {format_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)
|
print(f'Note: picked "default" chat template variant (out of {format_variants()})', file=sys.stderr)
|
||||||
elif variant not in variants:
|
elif variant not in variants:
|
||||||
raise Exception(f"Variant {variant} not found in chat template (found {format_variants()})")
|
raise Exception(f"Variant {variant} not found in chat template (found {format_variants()})")
|
||||||
|
|
||||||
print(variants[variant], end=None)
|
print(variants[variant], end=None)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue