Duckduckgo Download
Duckduckgo Download
import requests
from bs4 import BeautifulSoup
from duckduckgo_search import DDGS
from langchain_ollama import ChatOllama, OllamaEmbeddings
from langchain.memory import ChatMessageHistory
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain.vectorstores import FAISS
from langchain.text_splitter import RecursiveCharacterTextSplitter
import json
# Initialize Streamlit UI
st.set_page_config(page_title="Enterprise AI Chatbot", layout="wide")
# Chat history
if "history" not in st.session_state:
st.session_state.history = ChatMessageHistory()
# User input
user_input = st.text_input("You:", key="user_input")
if st.button("Ask"):
if user_input:
# Add user input to history
st.session_state.history.add_user_message(user_input)
# Get AI response
ai_response = llm.invoke(st.session_state.history.messages)
st.session_state.history.add_ai_message(ai_response.content)
# Display chat
for msg in st.session_state.history.messages:
if msg.type == "human":
st.write(f"👤 You: {msg.content}")
else:
st.write(f"🤖 AI: {msg.content}")
if urls:
st.write("✅ Found pages:", urls)
# Prompt-based AI interaction
st.sidebar.header("AI-Powered Prompt Generator")
topic = st.sidebar.text_input("Enter a topic for AI-generated content:")
if st.sidebar.button("Generate"):
prompt_template = ChatPromptTemplate.from_template("Tell me a joke about
{topic}")
chain = prompt_template | llm | StrOutputParser()
ai_output = chain.invoke({"topic": topic})
st.sidebar.write(f"📝 AI Response: {ai_output}")