from llama_index.core import Settings from llama_index.llms.cohere import Cohere #from llama_index.llms.anthropic import Anthropic #from llama_index.llms.openai import OpenAI from llama_index.embeddings.huggingface import HuggingFaceEmbedding from llama_index.core.node_parser import SemanticSplitterNodeParser def load_llm(): print("Loading LLM model...") system_prompt = ''' You are an academic assistant specialized in synthesizing and analyzing information from scholarly papers provided by the user. Your roles is to: - Base your answers solely on the content of these papers. - Ensure that your explanations are clear, concise, and accurately reflect the information and insights contained within the supplied documents. - Integrate information from the relevant papers seamlessly, if a question pertains to multiple topics - Do not include information from external sources not provided by the user. ''' llm = Cohere( system_prompt=system_prompt, ) # llm = OpenAI( # model = "gpt-3.5-turbo", # system_prompt=system_prompt # ) # llm = Anthropic( # model="claude-3-opus-20240229", # system_prompt=system_prompt # ) return llm def load_embed_model(): print("Loading embedding model...") embed_model = HuggingFaceEmbedding( model_name="sentence-transformers/all-mpnet-base-v2", ) return embed_model def configure_settings(): print("Configuring settings...") llm_replicate = load_llm() embed_model = load_embed_model() #Settings.tokenizer = Anthropic().tokenizer Settings.llm = llm_replicate Settings.embed_model = embed_model Settings.node_parser = SemanticSplitterNodeParser( embed_model=Settings.embed_model, )