Skip to content

Instantly share code, notes, and snippets.

@jeffbryner
Last active February 23, 2025 23:55
Show Gist options
  • Save jeffbryner/e8f889452b2e16e81e86a7418f08b352 to your computer and use it in GitHub Desktop.
Save jeffbryner/e8f889452b2e16e81e86a7418f08b352 to your computer and use it in GitHub Desktop.
csv chat
from agno.agent import Agent, AgentMemory
from agno.memory.classifier import MemoryClassifier
from agno.memory.summarizer import MemorySummarizer
from agno.memory.manager import MemoryManager
from gemini_models import model_pro, model_flash
from agno.tools.file import FileTools
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.duckdb import DuckDbTools
from agno.storage.agent.sqlite import SqliteAgentStorage
from agno.memory.db.sqlite import SqliteMemoryDb
agent = Agent(
model=model_flash,
tools=[
FileTools(save_files=False),
DuckDbTools(),
DuckDuckGoTools(),
],
markdown=True,
show_tool_calls=True,
instructions=[
"You have local .csv files to chat about",
"Only chat about .csv files and always use your file tools to see what you have available.",
"Use your file tools to read the csv files and your duckdb tools to answer questions",
"Be sure to check the columns in the file",
"You can run a query to answer the question.",
"you can search the internet with DuckDuckGo",
],
description="You are an expert researcher, eager to help folks understand their local csv file data.",
storage=SqliteAgentStorage(table_name="chat_agent", db_file="tmp/agent_storage.db"),
# Adds the current date and time to the instructions
add_datetime_to_instructions=True,
# Adds the history of the conversation to the messages
add_history_to_messages=True,
# Number of history responses to add to the messages
num_history_responses=15,
memory=AgentMemory(
db=SqliteMemoryDb(db_file="tmp/agent_memory.db"),
create_user_memories=True,
create_session_summary=True,
update_user_memories_after_run=True,
update_session_summary_after_run=True,
classifier=MemoryClassifier(model=model_flash),
summarizer=MemorySummarizer(model=model_flash),
manager=MemoryManager(model=model_flash),
),
)
agent.cli_app(stream=True)
from agno.models.google import Gemini
# from agno_fixed_gemini import Gemini
from google import genai
from google.genai import types
import google.auth
credentials, PROJECT_ID = google.auth.default()
GEMINI_PRO = "gemini-1.5-pro"
GEMINI_FLASH = "gemini-2.0-flash-lite-preview-02-05"
generation_config = types.GenerateContentConfig(
temperature=0,
top_p=0.1,
top_k=1,
max_output_tokens=4096,
)
safety_settings = [
types.SafetySetting(
category=types.HarmCategory.HARM_CATEGORY_UNSPECIFIED,
threshold=types.HarmBlockThreshold.BLOCK_ONLY_HIGH,
),
types.SafetySetting(
category=types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold=types.HarmBlockThreshold.BLOCK_ONLY_HIGH,
),
types.SafetySetting(
category=types.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold=types.HarmBlockThreshold.BLOCK_ONLY_HIGH,
),
types.SafetySetting(
category=types.HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold=types.HarmBlockThreshold.BLOCK_ONLY_HIGH,
),
types.SafetySetting(
category=types.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold=types.HarmBlockThreshold.BLOCK_ONLY_HIGH,
),
]
# init for Vertex AI API
# client = genai.Client(vertexai=True, project=PROJECT_ID, location="us-central1")
model_pro = Gemini(
id=GEMINI_PRO,
vertexai=True,
project_id=PROJECT_ID,
location="us-central1",
generation_config=generation_config,
safety_settings=safety_settings,
)
model_flash = Gemini(
id=GEMINI_FLASH,
vertexai=True,
project_id=PROJECT_ID,
location="us-central1",
generation_config=generation_config,
safety_settings=safety_settings,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment