Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,6 +31,8 @@ if not openai_api_key or not serper_api_key:
|
|
| 31 |
logger.error("API keys are not set properly.")
|
| 32 |
st.error("API keys for OpenAI and SERPER must be set in the .env file.")
|
| 33 |
st.stop()
|
|
|
|
|
|
|
| 34 |
|
| 35 |
# Initialize OpenAI client
|
| 36 |
try:
|
|
@@ -44,7 +46,7 @@ except Exception as e:
|
|
| 44 |
# Load knowledge base
|
| 45 |
def load_knowledge_base():
|
| 46 |
try:
|
| 47 |
-
loader = TextLoader(
|
| 48 |
documents = loader.load()
|
| 49 |
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
| 50 |
docs = text_splitter.split_documents(documents)
|
|
@@ -124,8 +126,8 @@ def google_search_tool(query: str):
|
|
| 124 |
"""
|
| 125 |
return google_search(query)
|
| 126 |
|
| 127 |
-
tools = [
|
| 128 |
-
|
| 129 |
# Create the prompt template
|
| 130 |
prompt_message = """
|
| 131 |
Act as an expert copywriter who specializes in creating compelling marketing copy using AI technologies.
|
|
@@ -144,11 +146,12 @@ prompt_template = ChatPromptTemplate.from_messages(
|
|
| 144 |
|
| 145 |
# Create Langchain Agent with specific model and temperature
|
| 146 |
try:
|
| 147 |
-
llm = ChatOpenAI(model="gpt-4o", temperature=0.5)
|
| 148 |
llm_with_tools = llm.bind_tools(tools)
|
| 149 |
except Exception as e:
|
| 150 |
logger.error(f"Error creating Langchain Agent: {e}")
|
| 151 |
-
|
|
|
|
| 152 |
|
| 153 |
# Define the agent pipeline to handle the conversation flow
|
| 154 |
try:
|
|
@@ -192,6 +195,7 @@ def chatbot_response(message, history):
|
|
| 192 |
|
| 193 |
# Streamlit app
|
| 194 |
|
|
|
|
| 195 |
# Create input field for user message
|
| 196 |
user_input = st.text_input("You:", "")
|
| 197 |
|
|
|
|
| 31 |
logger.error("API keys are not set properly.")
|
| 32 |
st.error("API keys for OpenAI and SERPER must be set in the .env file.")
|
| 33 |
st.stop()
|
| 34 |
+
else:
|
| 35 |
+
logger.info("API keys loaded successfully.")
|
| 36 |
|
| 37 |
# Initialize OpenAI client
|
| 38 |
try:
|
|
|
|
| 46 |
# Load knowledge base
|
| 47 |
def load_knowledge_base():
|
| 48 |
try:
|
| 49 |
+
loader = TextLoader("./data_source/time_to_rethink_trust_book.md")
|
| 50 |
documents = loader.load()
|
| 51 |
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
| 52 |
docs = text_splitter.split_documents(documents)
|
|
|
|
| 126 |
"""
|
| 127 |
return google_search(query)
|
| 128 |
|
| 129 |
+
tools = [knowledge_base_tool, google_search_tool]
|
| 130 |
+
|
| 131 |
# Create the prompt template
|
| 132 |
prompt_message = """
|
| 133 |
Act as an expert copywriter who specializes in creating compelling marketing copy using AI technologies.
|
|
|
|
| 146 |
|
| 147 |
# Create Langchain Agent with specific model and temperature
|
| 148 |
try:
|
| 149 |
+
llm = ChatOpenAI(model="gpt-4o", temperature=0.5) # Set temperature to 0.5
|
| 150 |
llm_with_tools = llm.bind_tools(tools)
|
| 151 |
except Exception as e:
|
| 152 |
logger.error(f"Error creating Langchain Agent: {e}")
|
| 153 |
+
st.error(f"Error creating Langchain Agent: {e}")
|
| 154 |
+
st.stop()
|
| 155 |
|
| 156 |
# Define the agent pipeline to handle the conversation flow
|
| 157 |
try:
|
|
|
|
| 195 |
|
| 196 |
# Streamlit app
|
| 197 |
|
| 198 |
+
|
| 199 |
# Create input field for user message
|
| 200 |
user_input = st.text_input("You:", "")
|
| 201 |
|