New project with gemini thinking1
This commit is contained in:
parent
64d4052e10
commit
5f5bebfc9f
3 changed files with 73 additions and 14 deletions
|
|
@ -1,20 +1,58 @@
|
|||
import streamlit as st
|
||||
from agno.agent import Agent
|
||||
from agno.models.openai import OpenAIChat
|
||||
from agno.models.google import Gemini
|
||||
from agno.tools.duckduckgo import DuckDuckGoTools
|
||||
from agno.tools.yfinance import YFinanceTools
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
thinking_agent = Agent(
|
||||
name="Thinking Agent",
|
||||
role="Think about the problem",
|
||||
model=Gemini(id="gemini-2.0-flash-thinking-exp-1219", api_key=os.getenv("GOOGLE_API_KEY")),
|
||||
instructions="Given the problem, think about it and provide a detailed explanation",
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
)
|
||||
# Streamlit App Title
|
||||
st.title("AI Agent with Agno and Gemini Thinking")
|
||||
|
||||
# Sidebar for API Key Input
|
||||
st.sidebar.header("Configuration")
|
||||
api_key = st.sidebar.text_input("Enter your Google API Key", type="password")
|
||||
if api_key:
|
||||
os.environ["GOOGLE_API_KEY"] = api_key
|
||||
|
||||
thinking_agent.print_response("Explain Deep Q Networks from first principles", stream=True)
|
||||
# File/URL Upload Section
|
||||
st.sidebar.header("Upload Data")
|
||||
uploaded_file = st.sidebar.file_uploader("Upload a document", type=["txt", "pdf", "jpg", "png"])
|
||||
web_url = st.sidebar.text_input("Enter a web URL")
|
||||
|
||||
# Initialize the Agent
|
||||
if api_key:
|
||||
thinking_agent = Agent(
|
||||
name="Thinking Agent",
|
||||
role="Think about the problem",
|
||||
model=Gemini(id="gemini-2.0-flash-exp", api_key=api_key),
|
||||
instructions="Given the problem, think about it and provide a detailed explanation",
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# Chat Interface
|
||||
st.header("Chat with the Agent")
|
||||
user_input = st.text_input("Ask a question or describe the problem:")
|
||||
|
||||
if user_input:
|
||||
# Process the user's input
|
||||
if uploaded_file:
|
||||
# Handle file upload
|
||||
file_content = uploaded_file.read()
|
||||
st.write("File content:", file_content)
|
||||
# Add logic to process the file content with the agent
|
||||
response = thinking_agent.run(f"Given this file content: {file_content}, answer: {user_input}")
|
||||
elif web_url:
|
||||
# Handle web URL
|
||||
st.write("Web URL:", web_url)
|
||||
# Add logic to process the web URL with the agent
|
||||
response = thinking_agent.run(f"Given this web URL: {web_url}, answer: {user_input}")
|
||||
else:
|
||||
# Handle normal chat
|
||||
response = thinking_agent.run(user_input)
|
||||
|
||||
# Display the response
|
||||
st.write("Agent's Response:")
|
||||
st.write(response.content)
|
||||
else:
|
||||
st.warning("Please enter your Google API Key in the sidebar to proceed.")
|
||||
|
|
@ -11,10 +11,10 @@ config = {'thinking_config': {'include_thoughts': True}}
|
|||
|
||||
async def main():
|
||||
chat = client.aio.chats.create(
|
||||
model='gemini-2.0-flash-thinking-exp',
|
||||
model='gemini-2.0-flash-thinking-exp-01-21',
|
||||
config=config
|
||||
)
|
||||
response = await chat.send_message('What is your name?')
|
||||
response = await chat.send_message('Explain Deep Q Networks from first principles')
|
||||
print(response.text)
|
||||
response = await chat.send_message('What did you just say before this?')
|
||||
print(response.text)
|
||||
|
|
|
|||
21
ai_agent_tutorials/ai_gemini_thinking_agent/test2.py
Normal file
21
ai_agent_tutorials/ai_gemini_thinking_agent/test2.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from google import genai
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
from google import genai
|
||||
|
||||
client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY"), http_options={'api_version':'v1alpha'})
|
||||
|
||||
config = {'thinking_config': {'include_thoughts': True}}
|
||||
response = client.models.generate_content(
|
||||
model='gemini-2.0-flash-thinking-exp-01-21',
|
||||
contents='Explain how RLHF works in simple terms.',
|
||||
config=config
|
||||
)
|
||||
|
||||
for part in response.candidates[0].content.parts:
|
||||
if part.thought:
|
||||
print(f"Model Thought:\n{part.text}\n")
|
||||
else:
|
||||
print(f"\nModel Response:\n{part.text}\n")
|
||||
Loading…
Reference in a new issue