joao-vectara commited on
Commit
08152a0
·
verified ·
1 Parent(s): 4b92b03

Update agent.py

Browse files

update model and prompt

Files changed (1) hide show
  1. agent.py +36 -19
agent.py CHANGED
@@ -9,15 +9,34 @@ from vectara_agentic.tools import ToolsFactory, VectaraToolFactory
9
 
10
  initial_prompt = "How can I help you today?"
11
 
12
- years = range(2015, 2025)
13
-
14
-
15
- def get_valid_years() -> list[str]:
16
- """
17
- Returns a list of the years for which financial reports are available.
18
- Always check this before using any other tool.
19
- """
20
- return years
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def create_assistant_tools(cfg):
23
 
@@ -28,7 +47,7 @@ def create_assistant_tools(cfg):
28
  vec_factory = VectaraToolFactory(vectara_api_key=cfg.api_key,
29
  vectara_customer_id=cfg.customer_id,
30
  vectara_corpus_id=cfg.corpus_id)
31
- summarizer = 'vectara-summary-ext-24-05-med-omni'
32
  ask_publications = vec_factory.create_rag_tool(
33
  tool_name = "ask_publications",
34
  tool_description = """
@@ -36,28 +55,26 @@ def create_assistant_tools(cfg):
36
  """,
37
  tool_args_schema = QueryPublicationsArgs,
38
  reranker = "multilingual_reranker_v1", rerank_k = 100,
39
- n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
40
  summary_num_results = 10,
41
  vectara_summarizer = summarizer,
42
  include_citations = True,
 
43
  )
44
 
45
  tools_factory = ToolsFactory()
46
  return (
47
- [tools_factory.create_tool(tool) for tool in
48
- [
49
- get_valid_years,
50
- ]
51
- ] +
52
  tools_factory.standard_tools() +
53
  [ask_publications]
54
  )
55
 
56
  def initialize_agent(_cfg, agent_progress_callback=None):
57
  menarini_bot_instructions = """
58
- - You are a helpful clinical trial assistant, with expertise in clinical trial test publications, in conversation with a user.
59
- - Use the ask_publications tool to answer most questions about the results of clinical trials, risks, and more.
60
- - Responses from ask_publications are summarized. You don't need to further summarize them.
 
 
61
  """
62
 
63
  agent = Agent(
 
9
 
10
  initial_prompt = "How can I help you today?"
11
 
12
+ prompt = """
13
+ [
14
+ {"role": "system", "content": "You are a search bot that forms a coherent answer to a user query based on search results that are provided to you." },
15
+ {"role": "user", "content": " [INSTRUCTIONS]
16
+ If the search results are irrelevant to the question respond with *** I do not have enough information to answer this question.***
17
+ 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.
18
+ Do not cobble facts together from multiple search results, instead summarize the main facts into a consistent and easy to understand response.
19
+ Do not base your response on information or knowledge that is not in the search results.
20
+ 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.
21
+ For queries where only a short answer is required, you can give a brief response.
22
+ Consider that each search result is a partial segment from a bigger text, and may be incomplete.
23
+ Your output should always be in a single language - the $vectaraLangName language. Check spelling and grammar for the $vectaraLangName language.
24
+ Search results for the query *** $vectaraQuery***, are listed below, some are text, some MAY be tables in the format described above.
25
+ #foreach ($qResult in $vectaraQueryResultsDeduped)
26
+ [$esc.java($foreach.index + 1)]
27
+ #if($qResult.hasTable())
28
+ Table Title: $qResult.getTable().title() || Table Description: $qResult.getTable().description() || Table Data:
29
+ $qResult.getTable().markdown()
30
+ #else
31
+ $qResult.getText()
32
+ #end
33
+ #end
34
+ Generate a coherent response (but no more than $vectaraOutChars characters) to the query *** $vectaraQuery *** by summarizing the search results provided. Give a slight preference to search results that appear earlier in the list.
35
+ Include as many statistical numerical evidence from the search results in your response.
36
+ Only cite relevant search results in your answer following these specific instructions: $vectaraCitationInstructions
37
+ If the search results are irrelevant to the query, respond with ***I do not have enough information to answer this question.***. Respond always in the $vectaraLangName language, and only in that language."}
38
+ ]
39
+ """
40
 
41
  def create_assistant_tools(cfg):
42
 
 
47
  vec_factory = VectaraToolFactory(vectara_api_key=cfg.api_key,
48
  vectara_customer_id=cfg.customer_id,
49
  vectara_corpus_id=cfg.corpus_id)
50
+ summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
51
  ask_publications = vec_factory.create_rag_tool(
52
  tool_name = "ask_publications",
53
  tool_description = """
 
55
  """,
56
  tool_args_schema = QueryPublicationsArgs,
57
  reranker = "multilingual_reranker_v1", rerank_k = 100,
58
+ n_sentences_before = 3, n_sentences_after = 3, lambda_val = 0.005,
59
  summary_num_results = 10,
60
  vectara_summarizer = summarizer,
61
  include_citations = True,
62
+ vectara_prompt_text=prompt
63
  )
64
 
65
  tools_factory = ToolsFactory()
66
  return (
 
 
 
 
 
67
  tools_factory.standard_tools() +
68
  [ask_publications]
69
  )
70
 
71
  def initialize_agent(_cfg, agent_progress_callback=None):
72
  menarini_bot_instructions = """
73
+ - You are a helpful clinical trial assistant, with expertise in clinical trial publications, in conversation with a user.
74
+ - You always respond to the user with supporting evidence based on the data, with p-values where available.
75
+ - Your responses follow a standard statistical format for results of clinical trials.
76
+ for example: instead of "Reduced 4-component MACE by 30%" use "Reduced 4-component MACE by 30% (HR: 0.70; p=0.002)"
77
+ - Call the ask_publications tool as much as needed, with appropiate queries, until you have all the numerical data to respond properly to the user question.
78
  """
79
 
80
  agent = Agent(