1. Basic Agent
## Basic Agent
from agno.agent import Agent, RunResponse
from agno.models.ollama import Ollama
agent = Agent(
model=Ollama(id="llama3.2"),
markdown=True
)
# Print the response in the terminal
agent.print_response("What is Ministry of Corporate Affairs in India?
what it does?")
Response:
2. Web Search Agent
## Agents with Tools
# Pip install phidata, duckduckgo-search, arxiv
from agno.agent import Agent
from agno.models.ollama import Ollama
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.arxiv import ArxivTools
agent = Agent(
model=Ollama(id="llama3.2"),
# tools=[DuckDuckGoTools()],
tools=[DuckDuckGoTools(), ArxivTools()],
show_tool_calls=True,
markdown=True
)
# Print the response in the terminal
# agent.print_response("What do you think of the Latest news on
US deporting migrants.")
#agent.print_response("Give me some latest news
in Indian Politics.")
# agent.print_response("What is 23+89.")
agent.print_response("Search arxiv for 'Reinforcement Learning")
Response:
#pip install pydantic requests streamlit ollama
import streamlit as st
from pydantic import BaseModel
import ollama
# 🎭 Define AI Agent
class AIAgent(BaseModel):
name: str = "OllamaBot"
version: str = "1.0"
description: str = "A chatbot powered by Ollama LLM."
agent = AIAgent()
# 🛠️ Streamlit UI
st.title("🤖 iMMSS LLM for Legal Assistance")
st.write("Ask anything! (Type 'exit' to stop)")
# 🎤 Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# 🚀 Display chat history
for msg in st.session_state.messages:
st.write(msg)
# 🎤 User Input
user_query = st.text_input("You:", "")
# 🧠 Function to get AI response
def get_ai_response(question: str):
response = ollama.chat(model="llama3.2", messages=[{"role": "user", "content": question}])
return response["message"]["content"]
# 🚀 Process User Query
if user_query:
if user_query.lower() == "exit":
st.write("👋 Chatbot: Goodbye! Closing chat...")
st.stop()
# Get AI response
ai_answer = get_ai_response(user_query)
# Append user and bot messages to session state
st.session_state.messages.append(f"**You:** {user_query}")
st.session_state.messages.append(f"**{agent.name}:** {ai_answer}")
# Display AI response
st.write(f"**{agent.name}:** {ai_answer}")
Response:
No comments:
Post a Comment