ofermend commited on
Commit
213f561
·
1 Parent(s): 991b668
Files changed (4) hide show
  1. Dockerfile +3 -0
  2. agent.py +47 -22
  3. requirements.txt +2 -2
  4. st_app.py +1 -1
Dockerfile CHANGED
@@ -13,6 +13,9 @@ 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
 
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
@@ -12,6 +12,7 @@ load_dotenv(override=True)
12
  from vectara_agentic.agent import Agent
13
  from vectara_agentic.agent_config import AgentConfig
14
  from vectara_agentic.tools import ToolsFactory, VectaraToolFactory
 
15
 
16
  class AgentTools:
17
  def __init__(self, _cfg, agent_config):
@@ -21,13 +22,12 @@ class AgentTools:
21
 
22
 
23
  def get_tools(self):
24
- class QueryElectricCars(BaseModel):
25
- query: str = Field(description="The user query.")
26
-
27
- vec_factory_1 = VectaraToolFactory(vectara_api_key=self.cfg.api_keys[0],
28
- vectara_corpus_key=self.cfg.corpus_keys[0])
29
 
30
- summarizer = 'vectara-experimental-summary-ext-2023-12-11-med-omni'
31
 
32
  ask_vehicles = vec_factory_1.create_rag_tool(
33
  tool_name = "ask_vehicles",
@@ -35,12 +35,11 @@ class AgentTools:
35
  Given a user query,
36
  returns a response to a user question about electric vehicles.
37
  """,
38
- tool_args_schema = QueryElectricCars,
39
  reranker = "chain", rerank_k = 100,
40
  rerank_chain = [
41
  {
42
  "type": "slingshot",
43
- "cutoff": 0.2
44
  },
45
  {
46
  "type": "mmr",
@@ -48,24 +47,29 @@ class AgentTools:
48
  }
49
  ],
50
  n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
51
- summary_num_results = 5,
52
  vectara_summarizer = summarizer,
53
- include_citations = False,
 
 
 
54
  )
55
 
56
- vec_factory_2 = VectaraToolFactory(vectara_api_key=self.cfg.api_keys[1],
57
- vectara_corpus_key=self.cfg.corpus_keys[1])
 
 
58
 
59
 
60
  class QueryEVLaws(BaseModel):
61
- query: str = Field(description="The user query")
62
- state: Optional[str] = Field(default=None,
63
- description="The two digit state code. Optional.",
64
- examples=['CA', 'US', 'WA'])
65
- policy_type: Optional[str] = Field(default=None,
66
- description="The type of policy. Optional",
67
- examples = ['Laws and Regulations', 'State Incentives', 'Incentives', 'Utility / Private Incentives', 'Programs'])
68
-
69
 
70
  ask_policies = vec_factory_2.create_rag_tool(
71
  tool_name = "ask_policies",
@@ -79,7 +83,7 @@ class AgentTools:
79
  rerank_chain = [
80
  {
81
  "type": "slingshot",
82
- "cutoff": 0.2
83
  },
84
  {
85
  "type": "mmr",
@@ -88,12 +92,15 @@ class AgentTools:
88
  ],
89
  n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
90
  summary_num_results = 10,
 
 
91
  vectara_summarizer = summarizer,
92
  include_citations = False,
 
 
93
  )
94
 
95
  tools_factory = ToolsFactory()
96
-
97
  db_tools = tools_factory.database_tools(
98
  tool_name_prefix = "ev",
99
  content_description = 'Electric Vehicles in the state of Washington and other population information',
@@ -111,8 +118,26 @@ def initialize_agent(_cfg, agent_progress_callback=None):
111
  - You are a helpful research assistant, with expertise in electric vehicles, in conversation with a user.
112
  - Never discuss politics, and always respond politely.
113
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  agent = Agent(
 
 
116
  tools=AgentTools(_cfg, AgentConfig()).get_tools(),
117
  topic="Electric vehicles in the United States",
118
  custom_instructions=electric_vehicle_bot_instructions,
 
12
  from vectara_agentic.agent import Agent
13
  from vectara_agentic.agent_config import AgentConfig
14
  from vectara_agentic.tools import ToolsFactory, VectaraToolFactory
15
+ from vectara_agentic.types import ModelProvider, AgentType
16
 
17
  class AgentTools:
18
  def __init__(self, _cfg, agent_config):
 
22
 
23
 
24
  def get_tools(self):
25
+ vec_factory_1 = VectaraToolFactory(
26
+ vectara_api_key=self.cfg.api_keys[0],
27
+ vectara_corpus_key=self.cfg.corpus_keys[0]
28
+ )
 
29
 
30
+ summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
31
 
32
  ask_vehicles = vec_factory_1.create_rag_tool(
33
  tool_name = "ask_vehicles",
 
35
  Given a user query,
36
  returns a response to a user question about electric vehicles.
37
  """,
 
38
  reranker = "chain", rerank_k = 100,
39
  rerank_chain = [
40
  {
41
  "type": "slingshot",
42
+ "cutoff": 0.3
43
  },
44
  {
45
  "type": "mmr",
 
47
  }
48
  ],
49
  n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
50
+ summary_num_results = 10,
51
  vectara_summarizer = summarizer,
52
+ max_tokens = 4096, max_response_chars = 8192,
53
+ include_citations = True,
54
+ save_history = True,
55
+ verbose = False,
56
  )
57
 
58
+ vec_factory_2 = VectaraToolFactory(
59
+ vectara_api_key=self.cfg.api_keys[1],
60
+ vectara_corpus_key=self.cfg.corpus_keys[1]
61
+ )
62
 
63
 
64
  class QueryEVLaws(BaseModel):
65
+ state: Optional[str] = Field(
66
+ default=None, description="The two digit state code. Optional.",
67
+ examples=['CA', 'US', 'WA']
68
+ )
69
+ policy_type: Optional[str] = Field(
70
+ default=None, description="The type of policy. Optional",
71
+ examples = ['Laws and Regulations', 'State Incentives', 'Incentives', 'Utility / Private Incentives', 'Programs']
72
+ )
73
 
74
  ask_policies = vec_factory_2.create_rag_tool(
75
  tool_name = "ask_policies",
 
83
  rerank_chain = [
84
  {
85
  "type": "slingshot",
86
+ "cutoff": 0.3
87
  },
88
  {
89
  "type": "mmr",
 
92
  ],
93
  n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
94
  summary_num_results = 10,
95
+ max_tokens = 4096,
96
+ max_response_chars = 8192,
97
  vectara_summarizer = summarizer,
98
  include_citations = False,
99
+ save_history = True,
100
+ verbose = False,
101
  )
102
 
103
  tools_factory = ToolsFactory()
 
104
  db_tools = tools_factory.database_tools(
105
  tool_name_prefix = "ev",
106
  content_description = 'Electric Vehicles in the state of Washington and other population information',
 
118
  - You are a helpful research assistant, with expertise in electric vehicles, in conversation with a user.
119
  - Never discuss politics, and always respond politely.
120
  """
121
+ agent_config = AgentConfig(
122
+ agent_type = os.getenv("VECTARA_AGENTIC_AGENT_TYPE", AgentType.OPENAI.value),
123
+ main_llm_provider = os.getenv("VECTARA_AGENTIC_MAIN_LLM_PROVIDER", ModelProvider.OPENAI.value),
124
+ main_llm_model_name = os.getenv("VECTARA_AGENTIC_MAIN_MODEL_NAME", ""),
125
+ tool_llm_provider = os.getenv("VECTARA_AGENTIC_TOOL_LLM_PROVIDER", ModelProvider.OPENAI.value),
126
+ tool_llm_model_name = os.getenv("VECTARA_AGENTIC_TOOL_MODEL_NAME", ""),
127
+ observer = os.getenv("VECTARA_AGENTIC_OBSERVER_TYPE", "NO_OBSERVER")
128
+ )
129
+ fallback_agent_config = AgentConfig(
130
+ agent_type = os.getenv("VECTARA_AGENTIC_FALLBACK_AGENT_TYPE", AgentType.OPENAI.value),
131
+ main_llm_provider = os.getenv("VECTARA_AGENTIC_FALLBACK_MAIN_LLM_PROVIDER", ModelProvider.OPENAI.value),
132
+ main_llm_model_name = os.getenv("VECTARA_AGENTIC_FALLBACK_MAIN_MODEL_NAME", ""),
133
+ tool_llm_provider = os.getenv("VECTARA_AGENTIC_FALLBACK_TOOL_LLM_PROVIDER", ModelProvider.OPENAI.value),
134
+ tool_llm_model_name = os.getenv("VECTARA_AGENTIC_FALLBACK_TOOL_MODEL_NAME", ""),
135
+ observer = os.getenv("VECTARA_AGENTIC_OBSERVER_TYPE", "NO_OBSERVER")
136
+ )
137
 
138
  agent = Agent(
139
+ agent_config=agent_config,
140
+ fallback_agent_config=fallback_agent_config,
141
  tools=AgentTools(_cfg, AgentConfig()).get_tools(),
142
  topic="Electric vehicles in the United States",
143
  custom_instructions=electric_vehicle_bot_instructions,
requirements.txt CHANGED
@@ -1,10 +1,10 @@
1
  omegaconf==2.3.0
2
  python-dotenv==1.0.1
3
- streamlit==1.43.2
4
  streamlit-feedback==0.1.3
5
  langdetect==1.0.9
6
  langcodes==3.4.0
7
  datasets==2.19.2
8
  uuid==1.30
9
- vectara-agentic==0.2.9
10
  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
  langdetect==1.0.9
6
  langcodes==3.4.0
7
  datasets==2.19.2
8
  uuid==1.30
9
+ vectara-agentic==0.2.15
10
  torch==2.6.0
st_app.py CHANGED
@@ -131,7 +131,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)
 
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 = await st.session_state.agent.achat(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)