Spaces:
Sleeping
Sleeping
updated
Browse files- Dockerfile +4 -1
- agent.py +35 -17
- requirements.txt +3 -3
- 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
@@ -11,11 +11,13 @@ load_dotenv(override=True)
|
|
11 |
|
12 |
from vectara_agentic.agent import Agent
|
13 |
from vectara_agentic.tools import ToolsFactory, VectaraToolFactory
|
|
|
|
|
|
|
14 |
|
15 |
def create_assistant_tools(cfg):
|
16 |
|
17 |
class QueryCFPBComplaints(BaseModel):
|
18 |
-
query: str = Field(description="The user query.")
|
19 |
company: Optional[str] = Field(
|
20 |
default=None,
|
21 |
description="The company that the complaint is about.",
|
@@ -32,7 +34,7 @@ def create_assistant_tools(cfg):
|
|
32 |
vectara_corpus_key=cfg.corpus_keys
|
33 |
)
|
34 |
|
35 |
-
summarizer = 'vectara-
|
36 |
ask_complaints = vec_factory.create_rag_tool(
|
37 |
tool_name = "ask_complaints",
|
38 |
tool_description = """
|
@@ -40,7 +42,7 @@ def create_assistant_tools(cfg):
|
|
40 |
returns a response to a user question about customer complaints for bank services.
|
41 |
""",
|
42 |
tool_args_schema = QueryCFPBComplaints,
|
43 |
-
reranker = "chain", rerank_k = 100,
|
44 |
rerank_chain = [
|
45 |
{
|
46 |
"type": "slingshot",
|
@@ -49,46 +51,62 @@ def create_assistant_tools(cfg):
|
|
49 |
{
|
50 |
"type": "mmr",
|
51 |
"diversity_bias": 0.2,
|
52 |
-
"limit": 30
|
53 |
}
|
54 |
],
|
55 |
-
n_sentences_before = 2, n_sentences_after =
|
|
|
|
|
56 |
vectara_summarizer = summarizer,
|
57 |
include_citations = True,
|
58 |
-
verbose=
|
59 |
)
|
60 |
|
61 |
tools_factory = ToolsFactory()
|
62 |
-
|
63 |
db_tools = tools_factory.database_tools(
|
64 |
tool_name_prefix = "cfpb",
|
65 |
-
content_description =
|
66 |
sql_database = SQLDatabase(create_engine('sqlite:///cfpb_database.db')),
|
67 |
)
|
68 |
|
69 |
return (tools_factory.standard_tools() +
|
70 |
-
tools_factory.guardrail_tools() +
|
71 |
db_tools +
|
72 |
[ask_complaints]
|
73 |
)
|
74 |
|
75 |
def initialize_agent(_cfg, agent_progress_callback=None):
|
76 |
cfpb_complaints_bot_instructions = """
|
77 |
-
- You are a helpful research assistant
|
78 |
-
|
79 |
-
|
80 |
-
- For questions
|
81 |
-
You only need the query parameter to use this tool, but you can supply other parameters if provided.
|
82 |
-
Do not include the "References" section in your response.
|
83 |
-
- When using a company name with a tool, if the tool returns no information, try a difference variation of that company names, as well as different capitalization.
|
84 |
- Never discuss politics, and always respond politely.
|
85 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
agent = Agent(
|
88 |
tools=create_assistant_tools(_cfg),
|
89 |
topic="Customer complaints from the Consumer Financial Protection Bureau (CFPB)",
|
90 |
custom_instructions=cfpb_complaints_bot_instructions,
|
91 |
-
agent_progress_callback=agent_progress_callback
|
|
|
|
|
|
|
|
|
92 |
)
|
93 |
agent.report(detailed=False)
|
94 |
return agent
|
|
|
11 |
|
12 |
from vectara_agentic.agent import Agent
|
13 |
from vectara_agentic.tools import ToolsFactory, VectaraToolFactory
|
14 |
+
from vectara_agentic.types import ModelProvider, AgentType
|
15 |
+
from vectara_agentic.agent_config import AgentConfig
|
16 |
+
|
17 |
|
18 |
def create_assistant_tools(cfg):
|
19 |
|
20 |
class QueryCFPBComplaints(BaseModel):
|
|
|
21 |
company: Optional[str] = Field(
|
22 |
default=None,
|
23 |
description="The company that the complaint is about.",
|
|
|
34 |
vectara_corpus_key=cfg.corpus_keys
|
35 |
)
|
36 |
|
37 |
+
summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
|
38 |
ask_complaints = vec_factory.create_rag_tool(
|
39 |
tool_name = "ask_complaints",
|
40 |
tool_description = """
|
|
|
42 |
returns a response to a user question about customer complaints for bank services.
|
43 |
""",
|
44 |
tool_args_schema = QueryCFPBComplaints,
|
45 |
+
reranker = "chain", rerank_k = 100,
|
46 |
rerank_chain = [
|
47 |
{
|
48 |
"type": "slingshot",
|
|
|
51 |
{
|
52 |
"type": "mmr",
|
53 |
"diversity_bias": 0.2,
|
|
|
54 |
}
|
55 |
],
|
56 |
+
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
|
57 |
+
summary_num_results = 10,
|
58 |
+
max_tokens = 4096, max_response_chars = 8192,
|
59 |
vectara_summarizer = summarizer,
|
60 |
include_citations = True,
|
61 |
+
verbose = True
|
62 |
)
|
63 |
|
64 |
tools_factory = ToolsFactory()
|
|
|
65 |
db_tools = tools_factory.database_tools(
|
66 |
tool_name_prefix = "cfpb",
|
67 |
+
content_description = "Customer complaints about five banks (Bank of America, Wells Fargo, Capital One, Chase, and CITI Bank) and geographic information (counties and zip codes)",
|
68 |
sql_database = SQLDatabase(create_engine('sqlite:///cfpb_database.db')),
|
69 |
)
|
70 |
|
71 |
return (tools_factory.standard_tools() +
|
|
|
72 |
db_tools +
|
73 |
[ask_complaints]
|
74 |
)
|
75 |
|
76 |
def initialize_agent(_cfg, agent_progress_callback=None):
|
77 |
cfpb_complaints_bot_instructions = """
|
78 |
+
- You are a helpful research assistant in conversation with a user.
|
79 |
+
- You are in expert in the domain of complaints recorded by the CFPB (Consumer Financial Protection Bureau).
|
80 |
+
- For informational questions about customer complaints, use the 'ask_complaints' tool.
|
81 |
+
- For analytical questions, use the database tools: cfpb_load_data, cfpb_load_sample_data, cfpb_list_tables, cfpb_describe_tables and cfpb_load_unique_values.
|
|
|
|
|
|
|
82 |
- Never discuss politics, and always respond politely.
|
83 |
"""
|
84 |
+
agent_config = AgentConfig(
|
85 |
+
agent_type = os.getenv("VECTARA_AGENTIC_AGENT_TYPE", AgentType.OPENAI.value),
|
86 |
+
main_llm_provider = os.getenv("VECTARA_AGENTIC_MAIN_LLM_PROVIDER", ModelProvider.OPENAI.value),
|
87 |
+
main_llm_model_name = os.getenv("VECTARA_AGENTIC_MAIN_MODEL_NAME", ""),
|
88 |
+
tool_llm_provider = os.getenv("VECTARA_AGENTIC_TOOL_LLM_PROVIDER", ModelProvider.OPENAI.value),
|
89 |
+
tool_llm_model_name = os.getenv("VECTARA_AGENTIC_TOOL_MODEL_NAME", ""),
|
90 |
+
observer = os.getenv("VECTARA_AGENTIC_OBSERVER_TYPE", "NO_OBSERVER")
|
91 |
+
)
|
92 |
+
fallback_agent_config = AgentConfig(
|
93 |
+
agent_type = os.getenv("VECTARA_AGENTIC_FALLBACK_AGENT_TYPE", AgentType.OPENAI.value),
|
94 |
+
main_llm_provider = os.getenv("VECTARA_AGENTIC_FALLBACK_MAIN_LLM_PROVIDER", ModelProvider.OPENAI.value),
|
95 |
+
main_llm_model_name = os.getenv("VECTARA_AGENTIC_FALLBACK_MAIN_MODEL_NAME", ""),
|
96 |
+
tool_llm_provider = os.getenv("VECTARA_AGENTIC_FALLBACK_TOOL_LLM_PROVIDER", ModelProvider.OPENAI.value),
|
97 |
+
tool_llm_model_name = os.getenv("VECTARA_AGENTIC_FALLBACK_TOOL_MODEL_NAME", ""),
|
98 |
+
observer = os.getenv("VECTARA_AGENTIC_OBSERVER_TYPE", "NO_OBSERVER")
|
99 |
+
)
|
100 |
|
101 |
agent = Agent(
|
102 |
tools=create_assistant_tools(_cfg),
|
103 |
topic="Customer complaints from the Consumer Financial Protection Bureau (CFPB)",
|
104 |
custom_instructions=cfpb_complaints_bot_instructions,
|
105 |
+
agent_progress_callback=agent_progress_callback,
|
106 |
+
validate_tools=True,
|
107 |
+
verbose=True,
|
108 |
+
agent_config=agent_config,
|
109 |
+
fallback_agent_config=fallback_agent_config,
|
110 |
)
|
111 |
agent.report(detailed=False)
|
112 |
return agent
|
requirements.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
omegaconf==2.3.0
|
2 |
python-dotenv==1.0.1
|
3 |
-
streamlit==1.
|
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.
|
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.
|
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)
|