Spaces:
Sleeping
Sleeping
updates
Browse files
app.py
CHANGED
@@ -35,32 +35,14 @@ def create_tools(cfg):
|
|
35 |
tools_factory = ToolsFactory(vectara_api_key=cfg.api_key,
|
36 |
vectara_customer_id=cfg.customer_id,
|
37 |
vectara_corpus_id=cfg.corpus_id)
|
38 |
-
|
39 |
-
tool_name = "
|
40 |
tool_description = """
|
41 |
-
Responds to query based on information in hacker news from the last 6 months.
|
42 |
-
Performs a semantic search to find relevant information.
|
43 |
-
Use this tool to perform pure semantic search.
|
44 |
""",
|
45 |
tool_args_schema = QueryHackerNews,
|
46 |
reranker = "multilingual_reranker_v1", rerank_k = 100,
|
47 |
-
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.
|
48 |
-
summary_num_results = 10,
|
49 |
-
vectara_summarizer = 'vectara-summary-ext-24-05-med-omni',
|
50 |
-
include_citations = True,
|
51 |
-
)
|
52 |
-
|
53 |
-
ask_hackernews_hybrid = tools_factory.create_rag_tool(
|
54 |
-
tool_name = "ask_hackernews_keyword",
|
55 |
-
tool_description = """
|
56 |
-
Responds to query based on information in hacker news from the last 6 months
|
57 |
-
performs a hybrid search (both semantic and keyword) to find relevant information.
|
58 |
-
Use this tool when some amount of keyword search is expected to work better than semantic search,
|
59 |
-
For example, when you are looking for specific keywords or use rare words in the query.
|
60 |
-
""",
|
61 |
-
tool_args_schema = QueryHackerNews,
|
62 |
-
reranker = "multilingual_reranker_v1", rerank_k = 100,
|
63 |
-
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.1,
|
64 |
summary_num_results = 10,
|
65 |
vectara_summarizer = 'vectara-summary-ext-24-05-med-omni',
|
66 |
include_citations = True,
|
@@ -71,7 +53,7 @@ def create_tools(cfg):
|
|
71 |
) -> list[str]:
|
72 |
"""
|
73 |
Get the top stories from hacker news.
|
74 |
-
Returns a list of story IDS for the top stories right now
|
75 |
"""
|
76 |
db_url = 'https://hacker-news.firebaseio.com/v0/'
|
77 |
top_stories = requests.get(f"{db_url}topstories.json").json()
|
@@ -82,7 +64,7 @@ def create_tools(cfg):
|
|
82 |
) -> list[str]:
|
83 |
"""
|
84 |
Get the top SHOW HN stories from hacker news.
|
85 |
-
Returns a list of story IDS for the top SHOW HN stories right now
|
86 |
"""
|
87 |
db_url = 'https://hacker-news.firebaseio.com/v0/'
|
88 |
top_stories = requests.get(f"{db_url}showstories.json").json()
|
@@ -93,7 +75,7 @@ def create_tools(cfg):
|
|
93 |
) -> list[str]:
|
94 |
"""
|
95 |
Get the top ASK HN stories from hacker news.
|
96 |
-
Returns a list of story IDS for the top ASK HN stories right now
|
97 |
"""
|
98 |
db_url = 'https://hacker-news.firebaseio.com/v0/'
|
99 |
top_stories = requests.get(f"{db_url}askstories.json").json()
|
@@ -155,7 +137,7 @@ def create_tools(cfg):
|
|
155 |
) +
|
156 |
tools_factory.standard_tools() +
|
157 |
tools_factory.guardrail_tools() +
|
158 |
-
[
|
159 |
)
|
160 |
|
161 |
def initialize_agent(_cfg):
|
@@ -181,6 +163,7 @@ def initialize_agent(_cfg):
|
|
181 |
custom_instructions=bot_instructions,
|
182 |
update_func=update_func
|
183 |
)
|
|
|
184 |
return agent
|
185 |
|
186 |
def toggle_logs():
|
@@ -211,7 +194,7 @@ def launch_bot():
|
|
211 |
# left side content
|
212 |
with st.sidebar:
|
213 |
image = Image.open('Vectara-logo.png')
|
214 |
-
st.image(image, width=
|
215 |
st.markdown("## Welcome to the hacker news assistant demo.\n\n\n")
|
216 |
|
217 |
st.markdown("\n\n")
|
|
|
35 |
tools_factory = ToolsFactory(vectara_api_key=cfg.api_key,
|
36 |
vectara_customer_id=cfg.customer_id,
|
37 |
vectara_corpus_id=cfg.corpus_id)
|
38 |
+
ask_hackernews = tools_factory.create_rag_tool(
|
39 |
+
tool_name = "ask_hackernews",
|
40 |
tool_description = """
|
41 |
+
Responds to query based on information and stories in hacker news from the last 6-9 months.
|
|
|
|
|
42 |
""",
|
43 |
tool_args_schema = QueryHackerNews,
|
44 |
reranker = "multilingual_reranker_v1", rerank_k = 100,
|
45 |
+
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
summary_num_results = 10,
|
47 |
vectara_summarizer = 'vectara-summary-ext-24-05-med-omni',
|
48 |
include_citations = True,
|
|
|
53 |
) -> list[str]:
|
54 |
"""
|
55 |
Get the top stories from hacker news.
|
56 |
+
Returns a list of story IDS for the top stories right now. These are the top stories on hacker news.
|
57 |
"""
|
58 |
db_url = 'https://hacker-news.firebaseio.com/v0/'
|
59 |
top_stories = requests.get(f"{db_url}topstories.json").json()
|
|
|
64 |
) -> list[str]:
|
65 |
"""
|
66 |
Get the top SHOW HN stories from hacker news.
|
67 |
+
Returns a list of story IDS for the top SHOW HN stories right now. These are stories where users show their projects.
|
68 |
"""
|
69 |
db_url = 'https://hacker-news.firebaseio.com/v0/'
|
70 |
top_stories = requests.get(f"{db_url}showstories.json").json()
|
|
|
75 |
) -> list[str]:
|
76 |
"""
|
77 |
Get the top ASK HN stories from hacker news.
|
78 |
+
Returns a list of story IDS for the top ASK HN stories right now. These are stories where users ask questions to the community.
|
79 |
"""
|
80 |
db_url = 'https://hacker-news.firebaseio.com/v0/'
|
81 |
top_stories = requests.get(f"{db_url}askstories.json").json()
|
|
|
137 |
) +
|
138 |
tools_factory.standard_tools() +
|
139 |
tools_factory.guardrail_tools() +
|
140 |
+
[ask_hackernews]
|
141 |
)
|
142 |
|
143 |
def initialize_agent(_cfg):
|
|
|
163 |
custom_instructions=bot_instructions,
|
164 |
update_func=update_func
|
165 |
)
|
166 |
+
agent.report()
|
167 |
return agent
|
168 |
|
169 |
def toggle_logs():
|
|
|
194 |
# left side content
|
195 |
with st.sidebar:
|
196 |
image = Image.open('Vectara-logo.png')
|
197 |
+
st.image(image, width=175)
|
198 |
st.markdown("## Welcome to the hacker news assistant demo.\n\n\n")
|
199 |
|
200 |
st.markdown("\n\n")
|