add schema_get_files_info and call_function
This commit is contained in:
@@ -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],
|
||||
)
|
||||
@@ -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)",
|
||||
),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
@@ -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
@@ -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.
|
||||
"""
|
||||
Reference in New Issue
Block a user