aa
This commit is contained in:
parent
3df1ff5a43
commit
cbaf8b44b7
@ -33,7 +33,7 @@ TAVILY_DEFAULT_MAX_RESULTS = int(os.getenv("TAVILY_DEFAULT_MAX_RESULTS", 5))
|
||||
TAVILY_DISABLE_ADVANCED = os.getenv("TAVILY_DISABLE_ADVANCED", "false").lower() == "true" # For cost control
|
||||
|
||||
# --- Model Configuration ---
|
||||
DEFAULT_MODEL = os.getenv("GURT_DEFAULT_MODEL", "gemini-2.5-flash-preview-04-17")
|
||||
DEFAULT_MODEL = os.getenv("GURT_DEFAULT_MODEL", "projects/gurting/locations/us-central1/models/Gurt")
|
||||
FALLBACK_MODEL = os.getenv("GURT_FALLBACK_MODEL", "gemini-2.5-flash-preview-04-17")
|
||||
SAFETY_CHECK_MODEL = os.getenv("GURT_SAFETY_CHECK_MODEL", "gemini-2.5-flash-preview-04-17") # Use a Vertex AI model for safety checks
|
||||
|
||||
@ -966,4 +966,4 @@ GURT_RESPONSES = [
|
||||
"Gurt!", "Gurt gurt!", "Gurt... gurt gurt.", "*gurts happily*",
|
||||
"*gurts sadly*", "*confused gurting*", "Gurt? Gurt gurt!", "GURT!",
|
||||
"gurt...", "Gurt gurt gurt!", "*aggressive gurting*"
|
||||
]
|
||||
]
|
69
gurt/extrtools.py
Normal file
69
gurt/extrtools.py
Normal file
@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
extract_tools.py
|
||||
|
||||
Usage:
|
||||
python extract_tools.py path/to/your_module.py > tools.json
|
||||
|
||||
Parses the given Python file for calls to:
|
||||
tool_declarations.append(
|
||||
generative_models.FunctionDeclaration(...)
|
||||
)
|
||||
and outputs a JSON list of the kwargs passed to each FunctionDeclaration.
|
||||
"""
|
||||
|
||||
import ast
|
||||
import json
|
||||
import sys
|
||||
|
||||
def extract_function_declarations(source: str):
|
||||
tree = ast.parse(source)
|
||||
tools = []
|
||||
|
||||
for node in ast.walk(tree):
|
||||
# look for expressions like: tool_declarations.append( generative_models.FunctionDeclaration(...) )
|
||||
if (
|
||||
isinstance(node, ast.Expr)
|
||||
and isinstance(node.value, ast.Call)
|
||||
and isinstance(node.value.func, ast.Attribute)
|
||||
and node.value.func.attr == "append"
|
||||
# ensure it's tool_declarations.append
|
||||
and isinstance(node.value.func.value, ast.Name)
|
||||
and node.value.func.value.id == "tool_declarations"
|
||||
and node.value.args
|
||||
and isinstance(node.value.args[0], ast.Call)
|
||||
):
|
||||
decl_call = node.value.args[0]
|
||||
# ensure it's generative_models.FunctionDeclaration(...)
|
||||
if (
|
||||
isinstance(decl_call.func, ast.Attribute)
|
||||
and decl_call.func.attr == "FunctionDeclaration"
|
||||
):
|
||||
tool_obj = {}
|
||||
for kw in decl_call.keywords:
|
||||
# use ast.literal_eval to turn the AST node into a Python object
|
||||
try:
|
||||
value = ast.literal_eval(kw.value)
|
||||
except ValueError:
|
||||
# if something non-literal sneaks in, fallback to the raw source
|
||||
value = ast.get_source_segment(source, kw.value)
|
||||
tool_obj[kw.arg] = value
|
||||
tools.append(tool_obj)
|
||||
|
||||
return tools
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python extract_tools.py path/to/your_module.py", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
path = sys.argv[1]
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
source = f.read()
|
||||
|
||||
tools = extract_function_declarations(source)
|
||||
json.dump(tools, sys.stdout, indent=2)
|
||||
sys.stdout.write("\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user