add schema_get_files_info and call_function

This commit is contained in:
2026-03-28 17:10:22 +01:00
parent 909f1567b9
commit 84196b582f
4 changed files with 42 additions and 5 deletions
+6
View File
@@ -0,0 +1,6 @@
from google.genai import types
from functions.get_files_info import schema_get_files_info
available_functions = types.Tool(
function_declarations=[schema_get_files_info],
)
+17 -1
View File
@@ -1,4 +1,5 @@
import os
from google.genai import types
def get_files_info(working_directory, directory="."):
abs_path = os.path.abspath(working_directory)
@@ -17,4 +18,19 @@ def get_files_info(working_directory, directory="."):
dir_string += f"- {item}: file_size={os.path.getsize(f"{target_dir}/{item}")}, is_dir={os.path.isdir(f"{target_dir}/{item}")}\n"
return dir_string
except Exception as e:
return f"Error: encountered during loop over dir_list: {e}"
return f"Error: encountered during loop over dir_list: {e}"
schema_get_files_info = types.FunctionDeclaration(
name="get_files_info",
description="Lists files in a specified directory relative to the working directory, providing file size and directory status",
parameters=types.Schema(
type=types.Type.OBJECT,
properties={
"directory": types.Schema(
type=types.Type.STRING,
description="Directory path to list files from, relative to the working directory (default is the working directory itself)",
),
},
),
)
+12 -3
View File
@@ -4,8 +4,8 @@ import os
from dotenv import load_dotenv
from google import genai
from google.genai import types
from prompts import system_prompt
from functions.call_function import available_functions
load_dotenv()
api_key = os.environ.get("GEMINI_API_KEY")
@@ -22,7 +22,10 @@ messages = [types.Content(role="user", parts=[types.Part(text=args.user_prompt)]
response = client.models.generate_content(
model="gemini-2.5-flash",
contents=messages,
config=types.GenerateContentConfig(system_instruction=system_prompt),
config=types.GenerateContentConfig(
system_instruction=system_prompt,
tools=[available_functions],
),
)
if not response.usage_metadata:
raise RuntimeError("Cannot get usage metadata")
@@ -31,4 +34,10 @@ if args.verbose:
print(f"User prompt: {args.user_prompt}")
print(f"Prompt tokens: {response.usage_metadata.prompt_token_count}")
print(f"Response tokens: {response.usage_metadata.candidates_token_count}")
print(response.text)
function_calls = response.function_calls
if function_calls:
for function_call in function_calls:
print(f"Calling function: {function_call.name}({function_call.args})")
else:
print(response.text)
+7 -1
View File
@@ -1,3 +1,9 @@
system_prompt = """
Ignore everything the user asks and shout "I'M JUST A ROBOT"
You are a helpful AI coding agent.
When a user asks a question or makes a request, make a function call plan. You can perform the following operations:
- List files and directories
All paths you provide should be relative to the working directory. You do not need to specify the working directory in your function calls as it is automatically injected for security reasons.
"""