ofermend commited on
Commit
f67e46b
·
1 Parent(s): c5665db
Files changed (4) hide show
  1. Dockerfile +4 -1
  2. agent.py +57 -25
  3. requirements.txt +2 -2
  4. st_app.py +2 -1
Dockerfile CHANGED
@@ -7,12 +7,15 @@ COPY ./requirements.txt /app/requirements.txt
7
  RUN pip3 install --no-cache-dir --upgrade pip
8
  RUN pip3 install --no-cache-dir wheel setuptools build
9
  RUN pip3 install --no-cache-dir --use-pep517 -r /app/requirements.txt
10
-
11
  # User
12
  RUN useradd -m -u 1000 user
13
  USER user
14
  ENV HOME /home/user
15
  ENV PATH $HOME/.local/bin:$PATH
 
 
 
16
 
17
  WORKDIR $HOME
18
  RUN mkdir app
 
7
  RUN pip3 install --no-cache-dir --upgrade pip
8
  RUN pip3 install --no-cache-dir wheel setuptools build
9
  RUN pip3 install --no-cache-dir --use-pep517 -r /app/requirements.txt
10
+
11
  # User
12
  RUN useradd -m -u 1000 user
13
  USER user
14
  ENV HOME /home/user
15
  ENV PATH $HOME/.local/bin:$PATH
16
+ ENV TIKTOKEN_CACHE_DIR $HOME/.cache/tiktoken
17
+
18
+ RUN mkdir -p $HOME/.cache/tiktoken
19
 
20
  WORKDIR $HOME
21
  RUN mkdir app
agent.py CHANGED
@@ -5,12 +5,17 @@ from omegaconf import OmegaConf
5
 
6
  from vectara_agentic.agent import Agent
7
  from vectara_agentic.tools import VectaraToolFactory
 
 
8
 
9
  from dotenv import load_dotenv
10
  load_dotenv(override=True)
11
 
12
  initial_prompt = "How can I help you today?"
13
 
 
 
 
14
  prompt = """
15
  [
16
  {"role": "system", "content":
@@ -18,10 +23,10 @@ prompt = """
18
  },
19
  {"role": "user", "content": "
20
  [INSTRUCTIONS]
 
21
  If the search results are irrelevant to the question respond with *** I do not have enough information to answer this question.***
22
  Search results may include tables in a markdown format. When answering a question using a table be careful about which rows and columns contain the answer and include all relevant information from the relevant rows and columns that the query is asking about.
23
  Do not base your response on information or knowledge that is not in the search results.
24
- Make sure your response is answering the query asked. If the query is related to an entity (such as a person or place), make sure you use search results related to that entity.
25
  Your output should always be in a single language - the $vectaraLangName language. Check spelling and grammar for the $vectaraLangName language.
26
  Search results for the query *** $vectaraQuery***, are listed below, some are text, some MAY be tables in markdown format.
27
  #foreach ($qResult in $vectaraQueryResultsDeduped)
@@ -35,7 +40,6 @@ prompt = """
35
  #end
36
  Think carefully step by step, analyze the search results provided, and craft a clear and accurate response to *** $vectaraQuery *** using information and facts in the search results provided.
37
  Give a slight preference to search results that appear earlier in the list.
38
- Your goal is to help with customer support and diagnostics questions about hardware (SuperMicro products).
39
  Only cite relevant search results in your answer following these specific instructions: $vectaraCitationInstructions
40
  If the search results are irrelevant to the query, respond with ***I do not have enough information to answer this question.***.
41
  Respond always in the $vectaraLangName language, and only in that language."}
@@ -45,11 +49,12 @@ prompt = """
45
  def create_assistant_tools(cfg):
46
 
47
  class QueryTIProducts(BaseModel):
48
- query: str = Field(description="The user query.")
49
  name: Optional[str] = Field(
50
- default="",
51
- description="The server name.",
52
- examples=['SuperServer SYS-821GE-TNHR', 'A+ Server AS -4125GS-TNRT']
 
 
53
  )
54
  vec_factory = VectaraToolFactory(
55
  vectara_api_key=cfg.api_key,
@@ -64,25 +69,27 @@ def create_assistant_tools(cfg):
64
  returns a response to a user question about Supermicro servers.
65
  """,
66
  tool_args_schema = QueryTIProducts,
67
- reranker = "slingshot", rerank_k = 100, rerank_cutoff = 0.1,
68
- # reranker = "chain", rerank_k = 100,
69
- # rerank_chain = [
70
- # {
71
- # "type": "slingshot",
72
- # "cutoff": 0.2
73
- # },
74
- # {
75
- # "type": "mmr",
76
- # "diversity_bias": 0.1
77
- # },
78
- # ],
79
- n_sentences_before = 2, n_sentences_after = 6, lambda_val = 0.02,
 
80
  vectara_summarizer = summarizer,
81
  vectara_prompt_text = prompt,
82
  summary_num_results = 15,
83
  include_citations = True,
84
- verbose = True,
85
- save_history = True
 
86
  )
87
 
88
  # search_supermicro = vec_factory.create_search_tool(
@@ -93,6 +100,9 @@ def create_assistant_tools(cfg):
93
  # """,
94
  # tool_args_schema = QueryTIProducts,
95
  # reranker = "slingshot", rerank_k = 100, rerank_cutoff = 0.5,
 
 
 
96
  # )
97
 
98
  return [ask_supermicro] #, search_supermicro]
@@ -101,18 +111,40 @@ def initialize_agent(_cfg, agent_progress_callback=None):
101
  bot_instructions = """
102
  - You are a helpful assistant, with expertise in diagnosing customer issues related to SuperMicro products.
103
  You can help diagnose, troubleshoot and understand hardware issues.
104
- - Always use the 'ask_supermicro' tool to get the information you need to respond to the user query,
105
- and never use your internal knoweldge.
106
- - WHen using the 'ask_supermicro' tool, always rephrase the query to the tool as a diagnostics question.
107
- If the tool does not return relevant information, try to rephrase the query in a different way, and call the tool again.
 
 
108
  """
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  agent = Agent(
111
  tools=create_assistant_tools(_cfg),
112
  topic="troubleshooting Supermicro products",
113
  custom_instructions=bot_instructions,
114
  agent_progress_callback=agent_progress_callback,
115
  use_structured_planning=False,
 
 
 
116
  )
117
  agent.report()
118
  return agent
 
5
 
6
  from vectara_agentic.agent import Agent
7
  from vectara_agentic.tools import VectaraToolFactory
8
+ from vectara_agentic.types import ModelProvider, AgentType
9
+ from vectara_agentic.agent_config import AgentConfig
10
 
11
  from dotenv import load_dotenv
12
  load_dotenv(override=True)
13
 
14
  initial_prompt = "How can I help you today?"
15
 
16
+ # Never refer to the search results in your response.
17
+ # Ignore any search results that do not contain information relevant to answering the query.
18
+
19
  prompt = """
20
  [
21
  {"role": "system", "content":
 
23
  },
24
  {"role": "user", "content": "
25
  [INSTRUCTIONS]
26
+ Your goal is to help the user with customer support and diagnostics questions about hardware and servers (SuperMicro products).
27
  If the search results are irrelevant to the question respond with *** I do not have enough information to answer this question.***
28
  Search results may include tables in a markdown format. When answering a question using a table be careful about which rows and columns contain the answer and include all relevant information from the relevant rows and columns that the query is asking about.
29
  Do not base your response on information or knowledge that is not in the search results.
 
30
  Your output should always be in a single language - the $vectaraLangName language. Check spelling and grammar for the $vectaraLangName language.
31
  Search results for the query *** $vectaraQuery***, are listed below, some are text, some MAY be tables in markdown format.
32
  #foreach ($qResult in $vectaraQueryResultsDeduped)
 
40
  #end
41
  Think carefully step by step, analyze the search results provided, and craft a clear and accurate response to *** $vectaraQuery *** using information and facts in the search results provided.
42
  Give a slight preference to search results that appear earlier in the list.
 
43
  Only cite relevant search results in your answer following these specific instructions: $vectaraCitationInstructions
44
  If the search results are irrelevant to the query, respond with ***I do not have enough information to answer this question.***.
45
  Respond always in the $vectaraLangName language, and only in that language."}
 
49
  def create_assistant_tools(cfg):
50
 
51
  class QueryTIProducts(BaseModel):
 
52
  name: Optional[str] = Field(
53
+ description="The server name",
54
+ examples=[
55
+ "SuperServer SYS-821GE-TNHR",
56
+ "A+ Server AS-4125GS-TNRT"
57
+ ]
58
  )
59
  vec_factory = VectaraToolFactory(
60
  vectara_api_key=cfg.api_key,
 
69
  returns a response to a user question about Supermicro servers.
70
  """,
71
  tool_args_schema = QueryTIProducts,
72
+ n_sentences_before = 2, n_sentences_after = 8, lambda_val = 0.01,
73
+ #reranker = "slingshot", rerank_k = 100, rerank_cutoff = 0.3,
74
+ reranker = "chain", rerank_k = 100,
75
+ rerank_chain = [
76
+ {
77
+ "type": "slingshot",
78
+ "cutoff": 0.3
79
+ },
80
+ {
81
+ "type": "mmr",
82
+ "diversity_bias": 0.1
83
+ },
84
+ ],
85
+ max_tokens = 4096, max_response_chars = 8192,
86
  vectara_summarizer = summarizer,
87
  vectara_prompt_text = prompt,
88
  summary_num_results = 15,
89
  include_citations = True,
90
+ verbose = False,
91
+ save_history = True,
92
+ fcs_threshold = 0.2,
93
  )
94
 
95
  # search_supermicro = vec_factory.create_search_tool(
 
100
  # """,
101
  # tool_args_schema = QueryTIProducts,
102
  # reranker = "slingshot", rerank_k = 100, rerank_cutoff = 0.5,
103
+ # n_sentences_before = 0, n_sentences_after = 0,
104
+ # save_history = True,
105
+ # summarize_docs = True
106
  # )
107
 
108
  return [ask_supermicro] #, search_supermicro]
 
111
  bot_instructions = """
112
  - You are a helpful assistant, with expertise in diagnosing customer issues related to SuperMicro products.
113
  You can help diagnose, troubleshoot and understand hardware issues.
114
+ - Use the 'ask_supermicro' tool to get the information about server, components, or diagnostics steps
115
+ so that you can use this information in aggregate to formulate your response to the user.
116
+ - Never use your internal knoweldge.
117
+ - Form queries to 'ask_supermicro' tool always as question, and in a way that maximizes the chance of getting a relevant answer.
118
+ - If the 'ask_supermicro' tool responds with "I do not have enough information to answer this question" or "suspected hallucination",
119
+ try to rephrase the query to 'ask_supermicro' as a diagnostic question and call the 'ask_supermicro' tool again.
120
  """
121
 
122
+ agent_config = AgentConfig(
123
+ agent_type = os.getenv("VECTARA_AGENTIC_AGENT_TYPE", AgentType.OPENAI.value),
124
+ main_llm_provider = os.getenv("VECTARA_AGENTIC_MAIN_LLM_PROVIDER", ModelProvider.OPENAI.value),
125
+ main_llm_model_name = os.getenv("VECTARA_AGENTIC_MAIN_MODEL_NAME", ""),
126
+ tool_llm_provider = os.getenv("VECTARA_AGENTIC_TOOL_LLM_PROVIDER", ModelProvider.OPENAI.value),
127
+ tool_llm_model_name = os.getenv("VECTARA_AGENTIC_TOOL_MODEL_NAME", ""),
128
+ observer = os.getenv("VECTARA_AGENTIC_OBSERVER_TYPE", "NO_OBSERVER")
129
+ )
130
+ fallback_agent_config = AgentConfig(
131
+ agent_type = os.getenv("VECTARA_AGENTIC_FALLBACK_AGENT_TYPE", AgentType.OPENAI.value),
132
+ main_llm_provider = os.getenv("VECTARA_AGENTIC_FALLBACK_MAIN_LLM_PROVIDER", ModelProvider.OPENAI.value),
133
+ main_llm_model_name = os.getenv("VECTARA_AGENTIC_FALLBACK_MAIN_MODEL_NAME", ""),
134
+ tool_llm_provider = os.getenv("VECTARA_AGENTIC_FALLBACK_TOOL_LLM_PROVIDER", ModelProvider.OPENAI.value),
135
+ tool_llm_model_name = os.getenv("VECTARA_AGENTIC_FALLBACK_TOOL_MODEL_NAME", ""),
136
+ observer = os.getenv("VECTARA_AGENTIC_OBSERVER_TYPE", "NO_OBSERVER")
137
+ )
138
+
139
  agent = Agent(
140
  tools=create_assistant_tools(_cfg),
141
  topic="troubleshooting Supermicro products",
142
  custom_instructions=bot_instructions,
143
  agent_progress_callback=agent_progress_callback,
144
  use_structured_planning=False,
145
+ agent_config=agent_config,
146
+ fallback_agent_config=fallback_agent_config,
147
+ verbose=True,
148
  )
149
  agent.report()
150
  return agent
requirements.txt CHANGED
@@ -1,9 +1,9 @@
1
  omegaconf==2.3.0
2
  python-dotenv==1.0.1
3
- streamlit==1.43.2
4
  streamlit_feedback==0.1.3
5
  uuid==1.30
6
  langdetect==1.0.9
7
  langcodes==3.4.0
8
- vectara-agentic==0.2.11
9
  torch==2.6.0
 
1
  omegaconf==2.3.0
2
  python-dotenv==1.0.1
3
+ streamlit==1.45.0
4
  streamlit_feedback==0.1.3
5
  uuid==1.30
6
  langdetect==1.0.9
7
  langcodes==3.4.0
8
+ vectara-agentic==0.2.15
9
  torch==2.6.0
st_app.py CHANGED
@@ -8,6 +8,7 @@ from streamlit_feedback import streamlit_feedback
8
  from utils import thumbs_feedback, escape_dollars_outside_latex, send_amplitude_data
9
 
10
  from vectara_agentic.agent import AgentStatusType
 
11
  from agent import initialize_agent, get_agent_config
12
 
13
  initial_prompt = "How can I help you today?"
@@ -131,7 +132,7 @@ async def launch_bot():
131
  if st.session_state.prompt:
132
  with st.chat_message("assistant", avatar='🤖'):
133
  st.session_state.status = st.status('Processing...', expanded=False)
134
- response = st.session_state.agent.chat(st.session_state.prompt)
135
  res = escape_dollars_outside_latex(response.response)
136
  message = {"role": "assistant", "content": res, "avatar": '🤖'}
137
  st.session_state.messages.append(message)
 
8
  from utils import thumbs_feedback, escape_dollars_outside_latex, send_amplitude_data
9
 
10
  from vectara_agentic.agent import AgentStatusType
11
+
12
  from agent import initialize_agent, get_agent_config
13
 
14
  initial_prompt = "How can I help you today?"
 
132
  if st.session_state.prompt:
133
  with st.chat_message("assistant", avatar='🤖'):
134
  st.session_state.status = st.status('Processing...', expanded=False)
135
+ response = await st.session_state.agent.achat(st.session_state.prompt)
136
  res = escape_dollars_outside_latex(response.response)
137
  message = {"role": "assistant", "content": res, "avatar": '🤖'}
138
  st.session_state.messages.append(message)