response_synthesizer = get_response_synthesizer(response_mode="tree_summarize", use_async=True) doc_summary_index = DocumentSummaryIndex.from_documents( [data_document], service_context=service_context, response_synthesizer=response_synthesizer, show_progress=True, ) doc_summary_index.storage_context.persist("index_summary")
doc_summary_index.get_document_summary(DOC_ID)
is in English not in French.[data_document]
contain text in French.summary_query
in DocumentSummaryIndex
as this is used as a instruction while creating the summary. summary_query = DEFAULT_SUMMARY_QUERY
with DEFAULT_SUMMARY_QUERY = (
"Describe what the provided text is about. "
"Also describe some of the questions that this text can answer. "
)
docSummIndex = DocumentSummaryIndex(summary_query= "YOUR_MODIFIED_INSTRUCTION", .... rest of things) index = docSummIndex.from_documents( [data_document], service_context=service_context, response_synthesizer=response_synthesizer, show_progress=True, )
french_summary_query = ( "Summarize the content in 5 lines. " "The response should be in the language french. " ) docSummIndex = DocumentSummaryIndex( service_context=service_context, response_synthesizer=response_synthesizer, summary_query=french_summary_query, show_progress=True ) french_doc_summary_index = docSummIndex.from_documents([data_document])
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-14-1c2d4fe7b925> in <cell line: 5>() 3 "The response should be in the language french. " 4 ) ----> 5 docSummIndex = DocumentSummaryIndex( 6 service_context=service_context, 7 response_synthesizer=response_synthesizer, 1 frames /usr/local/lib/python3.10/dist-packages/llama_index/indices/base.py in __init__(self, nodes, index_struct, storage_context, service_context, show_progress, **kwargs) 45 """Initialize with parameters.""" 46 if index_struct is None and nodes is None: ---> 47 raise ValueError("One of nodes or index_struct must be provided.") 48 if index_struct is not None and nodes is not None: 49 raise ValueError("Only one of nodes or index_struct can be provided.") ValueError: One of nodes or index_struct must be provided.
french_summary_query = ( "Summarize the content in 5 lines. " "The response should be in the language french. " ) chatgpt = OpenAI(temperature=0, model="gpt-3.5-turbo") response_synthesizer = get_response_synthesizer(response_mode="tree_summarize", use_async=True) service_context = ServiceContext.from_defaults(llm=chatgpt, chunk_size=1024) node_parser = service_context.node_parser french_doc_summary_index = DocumentSummaryIndex( service_context=service_context, nodes=node_parser.get_nodes_from_documents([data_document]), response_synthesizer=response_synthesizer, summary_query=french_summary_query, show_progress=True )