Spaces:
Sleeping
Sleeping
Siyona commited on
Commit ·
96fcd03
1
Parent(s): 7047f50
Updated to use Mistral free model for public access
Browse files12345679 unmodified lines17181920212223244 unmodified lines2930313233343515 unmodified lines5152535455565758596061626364656667686970717273742 unmodified lines777879808182838485868788899091import streamlit as stfrom dotenv import load_dotenvfrom pydantic import BaseModelfrom langchain_anthropic import ChatAnthropicfrom langchain_core.prompts import ChatPromptTemplatefrom langchain_core.output_parsers import PydanticOutputParserfrom langchain.agents import create_tool_calling_agent, AgentExecutor9 unmodified linessources: list[str]tools_used: list[str]# Initialize Claude model with low token usagellm = ChatAnthropic(model="claude-3-5-sonnet-20241022", max_tokens=300)# Create parserparser = PydanticOutputParser(pydantic_object=ResearchResponse)4 unmodified lines("system","""You are an AI assistant that will help of any general questions.Answer the user query and use necessary tools. Don't answer any offensive questions or any swearings.Wrap the output in this format and provide no other text\n{format_instructions}""",15 unmodified linesst.set_page_config(page_title="TechTales AI - Your own AI Powered Assistant", layout="centered")st.title("💡 TechTales AI - Your own AI Powered Assistant")# Initialize chat history in session stateif "messages" not in st.session_state:st.session_state.messages = []# Display chat historyfor msg in st.session_state.messages:st.chat_message(msg["role"]).write(msg["content"])# Chat input with Enter buttonquery = st.text_input("I am your personal Assistant, Ask me anything...", key="query_input")submit_button = st.button("Enter")if submit_button and query:# Add user message to historyst.session_state.messages.append({"role": "user", "content": query})st.chat_message("user").write(query)# Get AI responseraw_response = agent_executor.invoke({"query": query})try:2 unmodified linesexcept Exception:response_text = "I'm sorry, I couldn't process that request."# Add AI response to historyst.session_state.messages.append({"role": "assistant", "content": response_text})st.chat_message("assistant").write(response_text)# Clear Chat Buttonif st.button("🗑️ Clear Chat"):st.session_state.messages = []st.rerun() # Corrected method# Developer Name Displayst.markdown("---")st.markdown("**Developed by: Pankaj Kumar**", unsafe_allow_html=True)12345679 unmodified lines17181920212223242526274 unmodified lines3233343536373815 unmodified lines545556575859606162636465666768697071722 unmodified lines757677787980818283848586import streamlit as stfrom dotenv import load_dotenvfrom pydantic import BaseModelfrom langchain_community.llms import HuggingFaceHubfrom langchain_core.prompts import ChatPromptTemplatefrom langchain_core.output_parsers import PydanticOutputParserfrom langchain.agents import create_tool_calling_agent, AgentExecutor9 unmodified linessources: list[str]tools_used: list[str]# ✅ Use HuggingFace Mistral model (free)llm = HuggingFaceHub(repo_id="mistralai/Mistral-7B-Instruct-v0.3",model_kwargs={"temperature": 0.7, "max_new_tokens": 500},)# Create parserparser = PydanticOutputParser(pydantic_object=ResearchResponse)4 unmodified lines("system","""You are an AI assistant that will help with any general questions.Answer the user query and use necessary tools. Don't answer any offensive questions or any swearings.Wrap the output in this format and provide no other text\n{format_instructions}""",15 unmodified linesst.set_page_config(page_title="TechTales AI - Your own AI Powered Assistant", layout="centered")st.title("💡 TechTales AI - Your own AI Powered Assistant")if "messages" not in st.session_state:st.session_state.messages = []for msg in st.session_state.messages:st.chat_message(msg["role"]).write(msg["content"])query = st.text_input("I am your personal Assistant, Ask me anything...", key="query_input")submit_button = st.button("Enter")if submit_button and query:st.session_state.messages.append({"role": "user", "content": query})st.chat_message("user").write(query)raw_response = agent_executor.invoke({"query": query})try:2 unmodified linesexcept Exception:response_text = "I'm sorry, I couldn't process that request."st.session_state.messages.append({"role": "assistant", "content": response_text})st.chat_message("assistant").write(response_text)if st.button("🗑️ Clear Chat"):st.session_state.messages = []st.rerun()st.markdown("---")st.markdown("**Developed by: Pankaj Kumar**", unsafe_allow_html=True)
main.py+8-13