Spaces:
Running
Running
updated
Browse files- agent.py +65 -25
- requirements.txt +1 -1
agent.py
CHANGED
@@ -4,13 +4,44 @@ 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
|
8 |
|
9 |
from dotenv import load_dotenv
|
10 |
load_dotenv(override=True)
|
11 |
|
12 |
initial_prompt = "How can I help you today?"
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def create_assistant_tools(cfg):
|
15 |
|
16 |
class QueryTIProducts(BaseModel):
|
@@ -33,46 +64,55 @@ def create_assistant_tools(cfg):
|
|
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.
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
vectara_summarizer = summarizer,
|
39 |
-
|
|
|
40 |
include_citations = True,
|
41 |
verbose = True,
|
42 |
save_history = True
|
43 |
)
|
44 |
|
45 |
-
search_supermicro = vec_factory.create_search_tool(
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
)
|
54 |
|
55 |
-
return [ask_supermicro
|
56 |
|
57 |
def initialize_agent(_cfg, agent_progress_callback=None):
|
58 |
-
|
59 |
-
- You are a helpful assistant, with expertise in
|
|
|
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 |
-
-
|
63 |
-
|
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
|
74 |
-
custom_instructions=
|
75 |
agent_progress_callback=agent_progress_callback,
|
|
|
76 |
)
|
77 |
agent.report()
|
78 |
return agent
|
|
|
4 |
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":
|
17 |
+
"Think step by step, analyze the search results provided, and craft a clear and accurate response to diagnostics and troubleshooting questions from the user."
|
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)
|
28 |
+
[$esc.java($foreach.index + 1)]
|
29 |
+
#if($qResult.hasTable())
|
30 |
+
Table Title: $qResult.getTable().title() || Table Description: $qResult.getTable().description() || Table Data:
|
31 |
+
$qResult.getTable().markdown()
|
32 |
+
#else
|
33 |
+
$qResult.getText()
|
34 |
+
#end
|
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."}
|
42 |
+
]
|
43 |
+
"""
|
44 |
+
|
45 |
def create_assistant_tools(cfg):
|
46 |
|
47 |
class QueryTIProducts(BaseModel):
|
|
|
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(
|
89 |
+
# tool_name = "search_supermicro",
|
90 |
+
# tool_description = """
|
91 |
+
# Given a user query,
|
92 |
+
# returns a list of Supermicro documents matching the query, along with metadata.
|
93 |
+
# """,
|
94 |
+
# tool_args_schema = QueryTIProducts,
|
95 |
+
# reranker = "slingshot", rerank_k = 100, rerank_cutoff = 0.5,
|
96 |
+
# )
|
97 |
|
98 |
+
return [ask_supermicro] #, search_supermicro]
|
99 |
|
100 |
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
|
requirements.txt
CHANGED
@@ -6,4 +6,4 @@ streamlit_feedback==0.1.3
|
|
6 |
uuid==1.30
|
7 |
langdetect==1.0.9
|
8 |
langcodes==3.4.0
|
9 |
-
vectara-agentic==0.2.
|
|
|
6 |
uuid==1.30
|
7 |
langdetect==1.0.9
|
8 |
langcodes==3.4.0
|
9 |
+
vectara-agentic==0.2.5
|