Spaces:
Sleeping
Sleeping
updated
Browse files- Dockerfile +4 -1
- agent.py +34 -16
- requirements.txt +2 -2
- st_app.py +1 -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,14 +5,15 @@ import requests
|
|
5 |
from typing import Tuple
|
6 |
from bs4 import BeautifulSoup
|
7 |
|
8 |
-
from
|
9 |
-
load_dotenv(override=True)
|
10 |
-
|
11 |
-
from pydantic import Field, BaseModel
|
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.tools_catalog import ToolsCatalog
|
|
|
|
|
|
|
|
|
16 |
|
17 |
initial_prompt = "How can I help you today?"
|
18 |
|
@@ -120,24 +121,24 @@ class AgentTools:
|
|
120 |
|
121 |
|
122 |
def get_tools(self):
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
summarizer = 'vectara-summary-ext-24-05-med-omni'
|
129 |
ask_hackernews = vec_factory.create_rag_tool(
|
130 |
tool_name = "ask_hackernews",
|
131 |
tool_description = """
|
132 |
Provides information on any topic or query, based on relevant hacker news stories.
|
133 |
""",
|
134 |
-
|
135 |
-
|
136 |
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.0,
|
137 |
-
summary_num_results =
|
138 |
vectara_summarizer = summarizer,
|
139 |
include_citations = True,
|
140 |
-
verbose=
|
|
|
141 |
)
|
142 |
|
143 |
tools_factory = ToolsFactory()
|
@@ -171,13 +172,30 @@ def initialize_agent(_cfg, agent_progress_callback = None):
|
|
171 |
- You can use the tavily_search tool to gain additional information if needed for follow up questions about Hacker News topic.
|
172 |
- When including information or links provided by the tavily_search tool, make sure to notify the user in your response that this is not based on Hacker News stories.
|
173 |
"""
|
174 |
-
agent_config = AgentConfig(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
agent = Agent(
|
176 |
tools=AgentTools(_cfg, agent_config).get_tools(),
|
177 |
topic="hacker news",
|
178 |
custom_instructions=bot_instructions,
|
179 |
agent_progress_callback=agent_progress_callback,
|
180 |
-
verbose=True
|
|
|
|
|
181 |
)
|
182 |
agent.report()
|
183 |
return agent
|
|
|
5 |
from typing import Tuple
|
6 |
from bs4 import BeautifulSoup
|
7 |
|
8 |
+
from pydantic import Field
|
|
|
|
|
|
|
9 |
from vectara_agentic.agent import Agent
|
10 |
from vectara_agentic.agent_config import AgentConfig
|
11 |
from vectara_agentic.tools import ToolsFactory, VectaraToolFactory
|
12 |
from vectara_agentic.tools_catalog import ToolsCatalog
|
13 |
+
from vectara_agentic.types import ModelProvider, AgentType
|
14 |
+
|
15 |
+
from dotenv import load_dotenv
|
16 |
+
load_dotenv(override=True)
|
17 |
|
18 |
initial_prompt = "How can I help you today?"
|
19 |
|
|
|
121 |
|
122 |
|
123 |
def get_tools(self):
|
124 |
+
vec_factory = VectaraToolFactory(
|
125 |
+
vectara_api_key=self.cfg.api_key,
|
126 |
+
vectara_corpus_key=self.cfg.corpus_key
|
127 |
+
)
|
128 |
+
summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
|
|
|
129 |
ask_hackernews = vec_factory.create_rag_tool(
|
130 |
tool_name = "ask_hackernews",
|
131 |
tool_description = """
|
132 |
Provides information on any topic or query, based on relevant hacker news stories.
|
133 |
""",
|
134 |
+
reranker = "multilingual_reranker_v1", rerank_k = 100, rerank_cutoff = 0.3,
|
135 |
+
max_tokens = 4096, max_response_chars = 8192,
|
136 |
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.0,
|
137 |
+
summary_num_results = 15,
|
138 |
vectara_summarizer = summarizer,
|
139 |
include_citations = True,
|
140 |
+
verbose = False,
|
141 |
+
save_history = True,
|
142 |
)
|
143 |
|
144 |
tools_factory = ToolsFactory()
|
|
|
172 |
- You can use the tavily_search tool to gain additional information if needed for follow up questions about Hacker News topic.
|
173 |
- When including information or links provided by the tavily_search tool, make sure to notify the user in your response that this is not based on Hacker News stories.
|
174 |
"""
|
175 |
+
agent_config = AgentConfig(
|
176 |
+
agent_type = os.getenv("VECTARA_AGENTIC_AGENT_TYPE", AgentType.OPENAI.value),
|
177 |
+
main_llm_provider = os.getenv("VECTARA_AGENTIC_MAIN_LLM_PROVIDER", ModelProvider.OPENAI.value),
|
178 |
+
main_llm_model_name = os.getenv("VECTARA_AGENTIC_MAIN_MODEL_NAME", ""),
|
179 |
+
tool_llm_provider = os.getenv("VECTARA_AGENTIC_TOOL_LLM_PROVIDER", ModelProvider.OPENAI.value),
|
180 |
+
tool_llm_model_name = os.getenv("VECTARA_AGENTIC_TOOL_MODEL_NAME", ""),
|
181 |
+
observer = os.getenv("VECTARA_AGENTIC_OBSERVER_TYPE", "NO_OBSERVER")
|
182 |
+
)
|
183 |
+
fallback_agent_config = AgentConfig(
|
184 |
+
agent_type = os.getenv("VECTARA_AGENTIC_FALLBACK_AGENT_TYPE", AgentType.OPENAI.value),
|
185 |
+
main_llm_provider = os.getenv("VECTARA_AGENTIC_FALLBACK_MAIN_LLM_PROVIDER", ModelProvider.OPENAI.value),
|
186 |
+
main_llm_model_name = os.getenv("VECTARA_AGENTIC_FALLBACK_MAIN_MODEL_NAME", ""),
|
187 |
+
tool_llm_provider = os.getenv("VECTARA_AGENTIC_FALLBACK_TOOL_LLM_PROVIDER", ModelProvider.OPENAI.value),
|
188 |
+
tool_llm_model_name = os.getenv("VECTARA_AGENTIC_FALLBACK_TOOL_MODEL_NAME", ""),
|
189 |
+
observer = os.getenv("VECTARA_AGENTIC_OBSERVER_TYPE", "NO_OBSERVER")
|
190 |
+
)
|
191 |
agent = Agent(
|
192 |
tools=AgentTools(_cfg, agent_config).get_tools(),
|
193 |
topic="hacker news",
|
194 |
custom_instructions=bot_instructions,
|
195 |
agent_progress_callback=agent_progress_callback,
|
196 |
+
verbose=True,
|
197 |
+
agent_config=agent_config,
|
198 |
+
fallback_agent_config=fallback_agent_config,
|
199 |
)
|
200 |
agent.report()
|
201 |
return agent
|
requirements.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
omegaconf==2.3.0
|
2 |
python-dotenv==1.0.1
|
3 |
-
streamlit==1.
|
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.
|
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
@@ -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.
|
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)
|