ofermend commited on
Commit
86f5f56
·
1 Parent(s): 6c6f33d
Files changed (4) hide show
  1. Dockerfile +11 -19
  2. README.md +2 -2
  3. agent.py +42 -20
  4. app.py +1 -1
Dockerfile CHANGED
@@ -1,31 +1,23 @@
1
  FROM python:3.11
2
 
3
- # Create a non-root user
 
 
 
 
 
 
4
  RUN useradd -m -u 1000 user
5
- RUN chown -R user:user $HOME
6
  USER user
7
-
8
- # Set environment variables
9
- ENV HOME=/home/user
10
- ENV PATH=$HOME/.local/bin:$PATH
11
- ENV NLTK_DATA=$HOME/nltk_data
12
- ENV PYTHONUSERBASE=$HOME/.local
13
 
14
  WORKDIR $HOME
15
- RUN mkdir -p app
16
- RUN mkdir -p $NLTK_DATA
17
-
18
- # Install dependencies
19
- COPY ./requirements.txt $HOME/app/requirements.txt
20
- RUN pip3 install --no-cache-dir -r $HOME/app/requirements.txt
21
-
22
  COPY . $HOME/app
23
- RUN python3 -c "import nltk; nltk.download('stopwords', download_dir='$NLTK_DATA')"
24
 
25
  EXPOSE 8501
26
-
27
- WORKDIR $HOME/app
28
-
29
  CMD streamlit run app.py \
30
  --server.headless true \
31
  --server.enableCORS false \
 
1
  FROM python:3.11
2
 
3
+ WORKDIR /app
4
+
5
+ COPY ./requirements.txt /app/requirements.txt
6
+
7
+ RUN pip3 install --no-cache-dir -r /app/requirements.txt
8
+
9
+ # User
10
  RUN useradd -m -u 1000 user
 
11
  USER user
12
+ ENV HOME /home/user
13
+ ENV PATH $HOME/.local/bin:$PATH
 
 
 
 
14
 
15
  WORKDIR $HOME
16
+ RUN mkdir app
17
+ WORKDIR $HOME/app
 
 
 
 
 
18
  COPY . $HOME/app
 
19
 
20
  EXPOSE 8501
 
 
 
21
  CMD streamlit run app.py \
22
  --server.headless true \
23
  --server.enableCORS false \
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Cona Assistant
3
  emoji: 🐨
4
  colorFrom: indigo
5
  colorTo: indigo
@@ -7,7 +7,7 @@ sdk: docker
7
  app_port: 8501
8
  pinned: false
9
  license: apache-2.0
10
- short_description: Ask questions about Cona Services
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: SuperMicro Demo
3
  emoji: 🐨
4
  colorFrom: indigo
5
  colorTo: indigo
 
7
  app_port: 8501
8
  pinned: false
9
  license: apache-2.0
10
+ short_description: Ask questions about Supermicro documents
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
agent.py CHANGED
@@ -1,9 +1,7 @@
1
  import os
2
  from typing import Optional
3
- import json
4
  from pydantic import Field, BaseModel
5
  from omegaconf import OmegaConf
6
- import requests
7
 
8
  from vectara_agentic.agent import Agent
9
  from vectara_agentic.tools import VectaraToolFactory, ToolsFactory
@@ -15,41 +13,65 @@ initial_prompt = "How can I help you today?"
15
 
16
  def create_assistant_tools(cfg):
17
 
18
- class QueryCona(BaseModel):
19
  query: str = Field(description="The user query.")
20
-
 
 
 
 
21
  vec_factory = VectaraToolFactory(
22
  vectara_api_key=cfg.api_key,
23
  vectara_corpus_key=cfg.corpus_key
24
  )
25
 
26
  summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
27
- ask_cona = vec_factory.create_rag_tool(
28
- tool_name = "ask_cona",
29
  tool_description = """
30
  Given a user query,
31
- returns a response to a user question about bottling companies.
32
  """,
33
- tool_args_schema = QueryCona,
34
- reranker = "slingshot", rerank_k = 100,
35
- n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.01,
36
  vectara_summarizer = summarizer,
37
  summary_num_results = 20,
38
  include_citations = True,
39
- verbose = False
 
40
  )
41
- return [ask_cona] + ToolsFactory().guardrail_tools()
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  def initialize_agent(_cfg, agent_progress_callback=None):
44
- bot_instructions = """
45
- - You are a helpful assistant, with expertise in products from coca cola and other bottling companies.
46
- - Use the ask_cona tool to answer most questions about any products related to coca cola.
 
 
 
 
 
 
47
  """
 
 
48
 
49
  agent = Agent(
50
  tools=create_assistant_tools(_cfg),
51
- topic="Cona services and coca cola",
52
- custom_instructions=bot_instructions,
53
  agent_progress_callback=agent_progress_callback,
54
  )
55
  agent.report()
@@ -61,8 +83,8 @@ def get_agent_config() -> OmegaConf:
61
  'corpus_key': str(os.environ['VECTARA_CORPUS_KEY']),
62
  'api_key': str(os.environ['VECTARA_API_KEY']),
63
  'examples': os.environ.get('QUERY_EXAMPLES', None),
64
- 'demo_name': "Cona Demo",
65
- 'demo_welcome': "Cona Assistant.",
66
- 'demo_description': "This assistant can help you with any questions about Cona Serices."
67
  })
68
  return cfg
 
1
  import os
2
  from typing import Optional
 
3
  from pydantic import Field, BaseModel
4
  from omegaconf import OmegaConf
 
5
 
6
  from vectara_agentic.agent import Agent
7
  from vectara_agentic.tools import VectaraToolFactory, ToolsFactory
 
13
 
14
  def create_assistant_tools(cfg):
15
 
16
+ class QueryTIProducts(BaseModel):
17
  query: str = Field(description="The user query.")
18
+ name: Optional[str] = Field(
19
+ default="",
20
+ description="The server name.",
21
+ examples=['SuperServer SYS-821GE-TNHR', 'A+ Server AS -4125GS-TNRT']
22
+ )
23
  vec_factory = VectaraToolFactory(
24
  vectara_api_key=cfg.api_key,
25
  vectara_corpus_key=cfg.corpus_key
26
  )
27
 
28
  summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
29
+ ask_supermicro = vec_factory.create_rag_tool(
30
+ tool_name = "ask_supermicro",
31
  tool_description = """
32
  Given a user query,
33
+ returns a response to a user question about Supermicro servers.
34
  """,
35
+ tool_args_schema = QueryTIProducts,
36
+ reranker = "slingshot", rerank_k = 100, rerank_cutoff = 0.5,
37
+ n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
38
  vectara_summarizer = summarizer,
39
  summary_num_results = 20,
40
  include_citations = True,
41
+ verbose = True,
42
+ save_history = True
43
  )
44
+
45
+ search_supermicro = vec_factory.create_search_tool(
46
+ tool_name = "search_supermicro",
47
+ tool_description = """
48
+ Given a user query,
49
+ returns a list of Supermicro documents matching the query, along with metadata.
50
+ """,
51
+ tool_args_schema = QueryTIProducts,
52
+ reranker = "slingshot", rerank_k = 100, rerank_cutoff = 0.5,
53
+ )
54
+
55
+ return [ask_supermicro, search_supermicro]
56
 
57
  def initialize_agent(_cfg, agent_progress_callback=None):
58
+ ti_bot_instructions = """
59
+ - You are a helpful assistant, with expertise in products from SuperMicro.
60
+ - Always use the 'ask_supermicro' tool to get the information you need to respond to the user query,
61
+ and never use your internal knoweldge.
62
+ - When the 'ask_supermicro' tool does not provide an adequare response,
63
+ plan a sequence of queries that will help you get the information you need.
64
+ Run each query in sequence, and use the results to refine the next query.
65
+ Then use all this information to form a response.
66
+ - If the user does not specify a server type, ask the user to specify it before attempting a response.
67
  """
68
+ # can try "When filtering by the device_name, if the tool cannot provide an answer or does not have enough information
69
+ # try calling the tool again with the device_family and include the device_name in the query string itself."
70
 
71
  agent = Agent(
72
  tools=create_assistant_tools(_cfg),
73
+ topic="Supermicro and its products",
74
+ custom_instructions=ti_bot_instructions,
75
  agent_progress_callback=agent_progress_callback,
76
  )
77
  agent.report()
 
83
  'corpus_key': str(os.environ['VECTARA_CORPUS_KEY']),
84
  'api_key': str(os.environ['VECTARA_API_KEY']),
85
  'examples': os.environ.get('QUERY_EXAMPLES', None),
86
+ 'demo_name': "Supermicro Demo",
87
+ 'demo_welcome': "Supermicro Assistant.",
88
+ 'demo_description': "This assistant can help you with any questions about SuperMicro servers."
89
  })
90
  return cfg
app.py CHANGED
@@ -13,6 +13,6 @@ if "feedback_key" not in st.session_state:
13
  st.session_state.feedback_key = 0
14
 
15
  if __name__ == "__main__":
16
- st.set_page_config(page_title="Cona Assistant", layout="wide")
17
  nest_asyncio.apply()
18
  asyncio.run(launch_bot())
 
13
  st.session_state.feedback_key = 0
14
 
15
  if __name__ == "__main__":
16
+ st.set_page_config(page_title="Supermicro Assistant", layout="wide")
17
  nest_asyncio.apply()
18
  asyncio.run(launch_bot())