mgbam commited on
Commit
80c4f7e
·
verified ·
1 Parent(s): 7a81cc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -1,14 +1,13 @@
1
  # app.py
2
- # Advanced Hugging Face Space Multi-Agent Chatbot
3
  #
4
- # Developed with a forward-looking vision, inspired by Bill Gates’ drive for technological innovation.
5
- # This app leverages LangGraph, DeepSeek-R1 (via text-based function calling), and Agentic RAG to deliver
6
- # a multi-agent chatbot capable of autonomous reasoning and action.
7
  #
8
  # To deploy:
9
- # 1. Add your API keys to the Hugging Face Space secrets (e.g., DEEPSEEK_API_KEY).
10
- # 2. Install dependencies via a requirements.txt file.
11
- # 3. Enjoy a robust and scalable AI assistant for research and development.
12
 
13
  import os
14
  import re
@@ -27,7 +26,7 @@ from langgraph.graph import END, StateGraph, START
27
  from langgraph.prebuilt import ToolNode
28
  from langgraph.graph.message import add_messages
29
 
30
- # Configure logging for better observability
31
  logging.basicConfig(level=logging.INFO)
32
  logger = logging.getLogger(__name__)
33
 
@@ -49,9 +48,7 @@ splitter = RecursiveCharacterTextSplitter(chunk_size=100, chunk_overlap=10)
49
  research_docs = splitter.create_documents(research_texts)
50
  development_docs = splitter.create_documents(development_texts)
51
 
52
- embeddings = OpenAIEmbeddings(
53
- model="text-embedding-3-large"
54
- )
55
 
56
  research_vectorstore = Chroma.from_documents(
57
  documents=research_docs,
@@ -99,7 +96,7 @@ Otherwise, just answer directly.
99
  """
100
  headers = {
101
  "Accept": "application/json",
102
- "Authorization": f"Bearer {os.environ.get('DEEPSEEK_API_KEY')}",
103
  "Content-Type": "application/json"
104
  }
105
  data = {
@@ -108,7 +105,6 @@ Otherwise, just answer directly.
108
  "temperature": 0.7,
109
  "max_tokens": 1024
110
  }
111
-
112
  response = requests.post(
113
  "https://api.deepseek.com/v1/chat/completions",
114
  headers=headers,
@@ -151,7 +147,7 @@ def generate(state: AgentState):
151
  docs = last_message.content[last_message.content.find("Results: ["):]
152
  headers = {
153
  "Accept": "application/json",
154
- "Authorization": f"Bearer {os.environ.get('DEEPSEEK_API_KEY')}",
155
  "Content-Type": "application/json"
156
  }
157
  prompt = f"""Based on these research documents, summarize the latest advancements in AI:
@@ -184,7 +180,7 @@ def rewrite(state: AgentState):
184
  original_question = state["messages"][0].content if state["messages"] else "N/A"
185
  headers = {
186
  "Accept": "application/json",
187
- "Authorization": f"Bearer {os.environ.get('DEEPSEEK_API_KEY')}",
188
  "Content-Type": "application/json"
189
  }
190
  data = {
@@ -214,7 +210,7 @@ def custom_tools_condition(state: AgentState):
214
  return "tools"
215
  return END
216
 
217
- # Build the workflow using LangGraph's StateGraph
218
  workflow = StateGraph(AgentState)
219
  workflow.add_node("agent", agent)
220
  retrieve_node = ToolNode(tools)
 
1
  # app.py
2
+ # Advanced AI R&D Assistant for Hugging Face Spaces
3
  #
4
+ # This app leverages LangGraph, DeepSeek-R1 via text-based function calling, and Agentic RAG.
5
+ # API keys are securely loaded via environment variables.
 
6
  #
7
  # To deploy:
8
+ # 1. Add your API key to Hugging Face Space secrets with the key DEEP_SEEK_API.
9
+ # 2. Ensure your requirements.txt is properly configured.
10
+ # 3. Run the app with Streamlit.
11
 
12
  import os
13
  import re
 
26
  from langgraph.prebuilt import ToolNode
27
  from langgraph.graph.message import add_messages
28
 
29
+ # Configure logging
30
  logging.basicConfig(level=logging.INFO)
31
  logger = logging.getLogger(__name__)
32
 
 
48
  research_docs = splitter.create_documents(research_texts)
49
  development_docs = splitter.create_documents(development_texts)
50
 
51
+ embeddings = OpenAIEmbeddings(model="text-embedding-3-large")
 
 
52
 
53
  research_vectorstore = Chroma.from_documents(
54
  documents=research_docs,
 
96
  """
97
  headers = {
98
  "Accept": "application/json",
99
+ "Authorization": f"Bearer {os.environ.get('DEEP_SEEK_API')}",
100
  "Content-Type": "application/json"
101
  }
102
  data = {
 
105
  "temperature": 0.7,
106
  "max_tokens": 1024
107
  }
 
108
  response = requests.post(
109
  "https://api.deepseek.com/v1/chat/completions",
110
  headers=headers,
 
147
  docs = last_message.content[last_message.content.find("Results: ["):]
148
  headers = {
149
  "Accept": "application/json",
150
+ "Authorization": f"Bearer {os.environ.get('DEEP_SEEK_API')}",
151
  "Content-Type": "application/json"
152
  }
153
  prompt = f"""Based on these research documents, summarize the latest advancements in AI:
 
180
  original_question = state["messages"][0].content if state["messages"] else "N/A"
181
  headers = {
182
  "Accept": "application/json",
183
+ "Authorization": f"Bearer {os.environ.get('DEEP_SEEK_API')}",
184
  "Content-Type": "application/json"
185
  }
186
  data = {
 
210
  return "tools"
211
  return END
212
 
213
+ # Build the workflow with LangGraph's StateGraph
214
  workflow = StateGraph(AgentState)
215
  workflow.add_node("agent", agent)
216
  retrieve_node = ToolNode(tools)