File size: 2,559 Bytes
2fb0169
 
152dfa1
2fb0169
 
 
36aeeec
 
152dfa1
2fb0169
 
9a8ebcf
2fb0169
 
9a8ebcf
 
 
 
 
 
152dfa1
9a8ebcf
2fb0169
 
9a8ebcf
 
 
152dfa1
 
2fb0169
9a8ebcf
 
 
2fb0169
9a8ebcf
2fb0169
9a8ebcf
152dfa1
2fb0169
 
6db8557
7cc108b
2fb0169
 
6db8557
2fb0169
 
 
 
 
 
9a8ebcf
 
2fb0169
 
71a34b2
9a8ebcf
 
 
 
2fb0169
 
 
 
9a8ebcf
 
71a34b2
2fb0169
 
9a8ebcf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pandas as pd
import requests
from pydantic import Field, BaseModel

from omegaconf import OmegaConf

from vectara_agentic.agent import Agent
from vectara_agentic.tools import ToolsFactory, VectaraToolFactory

initial_prompt = "How can I help you today?"

years = range(2015, 2025)


def get_valid_years() -> list[str]:
    """
    Returns a list of the years for which financial reports are available.
    Always check this before using any other tool.
    """
    return years

def create_assistant_tools(cfg):


    class QueryPublicationsArgs(BaseModel):
        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?"])        
        
    vec_factory = VectaraToolFactory(vectara_api_key=cfg.api_key,
                                     vectara_customer_id=cfg.customer_id,
                                     vectara_corpus_id=cfg.corpus_id)
    summarizer = 'vectara-summary-ext-24-05-med-omni'
    ask_publications = vec_factory.create_rag_tool(
        tool_name = "ask_publications",
        tool_description = """
        Responds to an user question about a particular result, based on the publications.
        """,
        tool_args_schema = QueryPublicationsArgs,
        reranker = "multilingual_reranker_v1", rerank_k = 100,
        n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
        summary_num_results = 10,
        vectara_summarizer = summarizer,
        include_citations = True,
    )

    tools_factory = ToolsFactory()
    return (
            [tools_factory.create_tool(tool) for tool in
                [
                    get_valid_years,
                ]
            ] +
            tools_factory.standard_tools() +
            [ask_publications]
    )

def initialize_agent(_cfg, agent_progress_callback=None):
    menarini_bot_instructions = """
    - You are a helpful clinical trial assistant, with expertise in clinical trial test publications, in conversation with a user. 
    - Use the ask_publications tool to answer most questions about the results of clinical trials, risks, and more.
    - Responses from ask_publications are summarized. You don't need to further summarize them.
    """

    agent = Agent(
        tools=create_assistant_tools(_cfg),
        topic="Drug trials publications",
        custom_instructions=menarini_bot_instructions,
        agent_progress_callback=agent_progress_callback,
    )
    agent.report()
    return agent