Spaces:
Sleeping
Sleeping
File size: 1,282 Bytes
17478b0 b97a227 17478b0 6b5a80d 17478b0 6b5a80d 17478b0 4d98b8e 6b5a80d b97a227 17478b0 b97a227 17478b0 b97a227 17478b0 b97a227 17478b0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | from langchain_groq import ChatGroq
from langchain_core.tools import tool
from langchain.agents import create_agent
from langchain_tavily import TavilySearch
import gradio as gr
import os
from dotenv import load_dotenv
load_dotenv
tavily_key = os.getenv("TAVILY_API_KEY")
groq_key = os.getenv("GROQ_API_KEY")
@tool
def add_tool(a,b):
"""Add two numbers a and b"""
return a+b
web_search = TavilySearch(tavily_api_key=tavily_key,
max_results=5)
llm = ChatGroq(
model="llama-3.3-70b-versatile",
api_key=groq_key,
)
agent = create_agent(
model=llm,
tools=[add_tool,web_search],
system_prompt="You are the helpful AI assistant, use tools if needed."
)
def chat_func(message, history):
response = agent.invoke({
"messages": [{"role": "user", "content": message}]
})
# Return the content of the response
return response["messages"][-1].content
# This creates the ChatGPT-like layout instantly
demo = gr.ChatInterface(
fn=chat_func, # Uses the modern bubble format
title="Chat Agent",
description="Ask me anything!",
# You can use "soft", "glass", "monochrome", or "ocean"
)
demo.launch()
# print(response["messages"][-1].content)
# print(response["messages"][1].tool_calls) |