ofermend commited on
Commit
6fb6db8
·
1 Parent(s): d97b2e3

updated agent

Browse files
Files changed (1) hide show
  1. agent.py +43 -16
agent.py CHANGED
@@ -11,8 +11,9 @@ 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.
@@ -21,7 +22,7 @@ prompt = """
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())
@@ -31,8 +32,9 @@ prompt = """
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
  ]
@@ -42,7 +44,8 @@ def create_assistant_tools(cfg):
42
 
43
 
44
  class QueryPublicationsArgs(BaseModel):
45
- query: str = Field(..., description="The user query, always in the form of a question", examples=["what are the risks reported?", "which drug was use on the and how big was the population?"])
 
46
 
47
  vec_factory = VectaraToolFactory(vectara_api_key=cfg.api_key,
48
  vectara_corpus_key=cfg.corpus_key)
@@ -54,28 +57,52 @@ def create_assistant_tools(cfg):
54
  """,
55
  tool_args_schema = QueryPublicationsArgs,
56
  reranker = "multilingual_reranker_v1", rerank_k = 100,
57
- n_sentences_before = 3, n_sentences_after = 3, lambda_val = 0.005,
58
- summary_num_results = 10,
59
  vectara_summarizer = summarizer,
60
  include_citations = True,
61
  vectara_prompt_text=prompt,
62
- save_history = True
 
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
- - Your responses should always include the sample size for the clinical trial and the time to effect when available.
78
- - 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.
 
 
 
 
 
 
 
 
 
 
79
  """
80
 
81
  agent = Agent(
 
11
 
12
  prompt = """
13
  [
14
+ {"role": "system", "content": "You are an AI assistant that forms a coherent answer to a user query based on search results that are provided to you." },
15
+ {"role": "user", "content": "
16
+ [INSTRUCTIONS]
17
  If the search results are irrelevant to the question respond with *** I do not have enough information to answer this question.***
18
  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.
19
  Do not cobble facts together from multiple search results, instead summarize the main facts into a consistent and easy to understand response.
 
22
  For queries where only a short answer is required, you can give a brief response.
23
  Consider that each search result is a partial segment from a bigger text, and may be incomplete.
24
  Your output should always be in a single language - the $vectaraLangName language. Check spelling and grammar for the $vectaraLangName language.
25
+ Search results for the query *** $vectaraQuery***, are listed below, some are text, some MAY be tables in markdown format.
26
  #foreach ($qResult in $vectaraQueryResultsDeduped)
27
  [$esc.java($foreach.index + 1)]
28
  #if($qResult.hasTable())
 
32
  $qResult.getText()
33
  #end
34
  #end
35
+ Generate a coherent response (but no more than $vectaraOutChars characters) to the query *** $vectaraQuery *** using information and facts in the search results provided.
36
+ Give a slight preference to search results that appear earlier in the list.
37
+ Include statistical and numerical evidence to support and contextualize your response.
38
  Only cite relevant search results in your answer following these specific instructions: $vectaraCitationInstructions
39
  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."}
40
  ]
 
44
 
45
 
46
  class QueryPublicationsArgs(BaseModel):
47
+ query: str = Field(..., description="The user query, always in the form of a question",
48
+ examples=["what are the risks reported?", "which drug was use on the and how big was the population?"])
49
 
50
  vec_factory = VectaraToolFactory(vectara_api_key=cfg.api_key,
51
  vectara_corpus_key=cfg.corpus_key)
 
57
  """,
58
  tool_args_schema = QueryPublicationsArgs,
59
  reranker = "multilingual_reranker_v1", rerank_k = 100,
60
+ n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
61
+ summary_num_results = 15,
62
  vectara_summarizer = summarizer,
63
  include_citations = True,
64
  vectara_prompt_text=prompt,
65
+ save_history = True,
66
+ verbose=True
67
  )
68
 
69
+ search_publications = vec_factory.create_search_tool(
70
+ tool_name = "search_publications",
71
+ tool_description = """
72
+ Returns matching publications to a user query.
73
+ """,
74
+ tool_args_schema = QueryPublicationsArgs,
75
+ reranker = "multilingual_reranker_v1", rerank_k = 100,
76
+ n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
77
+ save_history = True,
78
+ verbose=True
79
+ )
80
+
81
+
82
  tools_factory = ToolsFactory()
83
  return (
84
  tools_factory.standard_tools() +
85
+ [ask_publications, search_publications]
86
  )
87
 
88
  def initialize_agent(_cfg, agent_progress_callback=None):
89
  menarini_bot_instructions = """
90
+ - You are an expert statistician and clinical trial data analyst with extensive experience in designing, analyzing, and interpreting clinical research data.
91
+ - Your responses should be technically rigorous, data-driven, and written for an audience familiar with advanced statistical methodologies, regulatory standards, and the nuances of clinical trial design.
92
+ - Call the ask_publications tool to retreive information to answer the user query.
93
+ If the initial query lacks comprehensive data, continue to query ask_publications with refined search parameters until you retrieve all necessary numerical details
94
+ - Call the search_publications tool to retreive a list of publications that may contain the information needed to answer the user query.
95
+ The results include the document_id of each publication, and metadata.
96
+ - When responding to queries:
97
+ 1) Use precise statistical terminology (e.g., randomization, blinding, intention-to-treat, type I/II error, p-values, confidence intervals, Bayesian methods, etc.)
98
+ and reference common methodologies or guidelines where applicable (e.g., CONSORT, FDA, EMA).
99
+ 2) Your responses must include contextual information such as sample size and population characteristics. This nuance is crucial in clinical trial analysis.
100
+ When considering or reporting sample sizes, consider participants who were eligible for the study, those who were randomized, and those who completed the study.
101
+ If it's unclear which one is being referred to, clarify this in your response or ask the user for clarification.
102
+ 3) Provide clear explanations of statistical concepts, including assumptions, potential biases, and limitations in the context of clinical trial data.
103
+ 4) Ensure that your analysis is evidence-based and reflects current best practices in the field of clinical research and data analysis.
104
+ 5) Before finalizing your answer, review the analysis to ensure that all relevant data has been incorporated and that your conclusions are well-supported by the evidence.
105
+ 6) Provide sources and citations for all data and statistical information included in your responses, as provided in the response from the tools.
106
  """
107
 
108
  agent = Agent(