forked from TransformerOptimus/SuperAGI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test_llama_document_summary.py
- Loading branch information
1 parent
4d7398e
commit 2d59089
Showing
2 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
tests/unit_tests/resource_manager/test_llama_document_summary.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import pytest | ||
from unittest.mock import patch | ||
from superagi.resource_manager.llama_document_summary import LlamaDocumentSummary | ||
from llama_index.schema import Document | ||
|
||
class MockLLMPredictor: | ||
# This mock class will replace LLMPredictor | ||
def __init__(self, llm): | ||
pass | ||
|
||
class MockServiceContext: | ||
# This mock class will replace ServiceContext | ||
@classmethod | ||
def from_defaults(cls, llm_predictor, chunk_size): | ||
pass | ||
|
||
class MockResponseSynthesizer: | ||
# This mock class will replace ResponseSynthesizer | ||
@classmethod | ||
def from_args(cls, response_mode, use_async): | ||
pass | ||
|
||
class MockDocumentSummaryIndex: | ||
# This mock class will handle DocumentSummaryIndex | ||
@classmethod | ||
def from_documents(cls, documents, service_context, response_synthesizer): | ||
return cls() | ||
|
||
def get_document_summary(cls, doc_id): | ||
return f'This is a summary of the document with id: {doc_id}' | ||
|
||
|
||
@patch('llama_index.LLMPredictor', MockLLMPredictor) | ||
@patch('llama_index.ServiceContext', MockServiceContext) | ||
@patch('llama_index.ResponseSynthesizer', MockResponseSynthesizer) | ||
@patch('llama_index.DocumentSummaryIndex', MockDocumentSummaryIndex) | ||
def test_generate_summary_of_documents(): | ||
lds = LlamaDocumentSummary() | ||
# Documents to be summarized | ||
documents = [ | ||
Document(doc_id='1', text='The quick brown fox jumps over the lazy dog'), | ||
Document(doc_id='2', text='Hello World!') | ||
] | ||
# Generate summary | ||
summary = lds.generate_summary_of_document(documents) | ||
# Ensure mock summary is returned | ||
assert summary == 'This is a summary of the document with id: 1' | ||
|
||
@patch('llama_index.LLMPredictor', MockLLMPredictor) | ||
@patch('llama_index.ServiceContext', MockServiceContext) | ||
@patch('llama_index.ResponseSynthesizer', MockResponseSynthesizer) | ||
@patch('llama_index.DocumentSummaryIndex', MockDocumentSummaryIndex) | ||
def test_generate_summary_of_documents_from_texts(): | ||
lds = LlamaDocumentSummary() | ||
# Documents to be summarized | ||
texts = [ | ||
'The quick brown fox jumps over the lazy dog', | ||
'Hello World!' | ||
] | ||
# Generate summary | ||
summary = lds.generate_summary_of_texts(texts) | ||
# Ensure mock summary is returned | ||
assert summary == 'This is a summary of the document with id: doc_id_0' | ||
|
||
texts = [] | ||
# Generate summary | ||
with pytest.raises(Exception) as excinfo: | ||
lds.generate_summary_of_texts(texts) | ||
assert "texts must be provided" in str(excinfo.value) |