service_context = ServiceContext.from_defaults(llm=llm, embed_model="local", chunk_size=chunk_size, context_window=context_window - 200, llm_predictor=llm ) documents = SimpleDirectoryReader(input_dir="C:/temp_my/text_embeddings").load_data() # %% response_synthesizer = get_response_synthesizer(response_mode='tree_summarize', use_async=True, )
if llm != "default": if llm_predictor is not None: raise ValueError("Cannot specify both llm and llm_predictor")
llm_predictor
, you can just set the llm to point to your LLM with your downloaded modeldef resolve_llm(llm: Optional[LLMType] = None) -> LLM: """Resolve LLM from string or LLM instance.""" if llm == "default": # return default OpenAI model. If it fails, return LlamaCPP try: llm = OpenAI() except ValueError as e: llm = "local" print( "******\n" "Could not load OpenAI model. Using default LlamaCPP=llama2-13b-chat. " "If you intended to use OpenAI, please check your OPENAI_API_KEY.\n" "Original error:\n" f"{e!s}" "\n******" )
from llama_index import set_global_service_context set_global_service_context(service_context)
response_synthesizer = get_response_synthesizer(response_mode='tree_summarize', use_async=True, service_context=service_context)
storage_context = StorageContext.from_defaults(persist_dir='doc_summary_index') doc_summary_index = load_index_from_storage(storage_context) if not doc_summary_index: doc_summary_index = DocumentSummaryIndex.from_documents( documents, service_context=service_context, response_synthesizer=response_synthesizer, show_progress=True, ) doc_summary_index.get_document_summary('Ranenie Zvezdy 4_ru') doc_summary_index.storage_context.persist('doc_summary_index')