├── rag
├── __init__.py
└── pipeline.py
├── .gitattributes
├── data
└── invoice_1.pdf
├── requirements.txt
├── config.yml
├── README.md
├── main.py
├── ingest.py
├── prompts_zephyr.txt
├── prompts_starling.txt
├── .gitignore
└── LICENSE
/rag/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/data/invoice_1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/katanaml/llm-ollama-invoice-cpu/HEAD/data/invoice_1.pdf
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | langchain==0.0.344
2 | langchain-experimental==0.0.43
3 | chromadb==0.4.18
4 | sentence_transformers
5 | pypdf
6 | python-box
--------------------------------------------------------------------------------
/config.yml:
--------------------------------------------------------------------------------
1 | CHUNK_SIZE: 1000
2 | CHUNK_OVERLAP: 30
3 | NUM_RESULTS: 1
4 | DATA_PATH: 'data/'
5 | EMBEDDINGS: 'sentence-transformers/all-mpnet-base-v2'
6 | VECTOR_DB: 'vectorstore/sparrow'
7 | NORMALIZE_EMBEDDINGS: True
8 | COLLECTION_NAME: 'sparrow'
9 | DEVICE: 'cpu'
10 | VECTOR_SPACE: 'cosine'
11 | LLM: 'starling-lm:7b-alpha-q5_K_M'
12 | #LLM: 'zephyr:7b-alpha-q5_K_M'
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Invoice data processing LLM RAG on CPU with Ollama and ChromaDB
2 |
3 |
4 | Easy-to-Follow RAG Pipeline Tutorial: Invoice Processing with ChromaDB & LangChain
5 |
6 | Secure and Private: On-Premise Invoice Processing with LangChain and Ollama RAG
7 |
8 | ___
9 |
10 | ## Quickstart
11 |
12 | ### RAG runs offline on local CPU
13 |
14 | 1. Install the requirements:
15 |
16 | ```
17 | pip install -r requirements.txt
18 | ```
19 |
20 | 2. Install Ollama and pull LLM model specified in config.yml
21 |
22 | 3. Copy text PDF files to the `data` folder.
23 |
24 | 4. Run the script, to convert text to vector embeddings and save in Chroma vector storage:
25 |
26 | ```
27 | python ingest.py
28 | ```
29 |
30 | 5. Run the script, to process data with LLM RAG and return the answer:
31 |
32 | ```
33 | python main.py "What is the invoice number value?"
34 | ```
35 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | import timeit
2 | import argparse
3 | from rag.pipeline import build_rag_pipeline
4 | import json
5 |
6 |
7 | def get_rag_response(query, chain):
8 | response = chain({'query': query})
9 |
10 | res = response['result']
11 |
12 | start_index = res.find('{')
13 | end_index = res.rfind('}')
14 |
15 | if start_index != -1 and end_index != -1 and end_index > start_index:
16 | json_fragment = res[start_index:end_index + 1]
17 | try:
18 | # Convert the extracted string to JSON
19 | json_data = json.loads(json_fragment)
20 | return json_data
21 | except json.JSONDecodeError as e:
22 | print(f"Error parsing JSON: {e}")
23 | else:
24 | print("No JSON object found in the string.")
25 |
26 | return res
27 |
28 |
29 | if __name__ == "__main__":
30 | parser = argparse.ArgumentParser()
31 | parser.add_argument('input',
32 | type=str,
33 | default='What is the invoice number value?',
34 | help='Enter the query to pass into the LLM')
35 | args = parser.parse_args()
36 |
37 | start = timeit.default_timer()
38 |
39 | qa_chain = build_rag_pipeline()
40 | print('Retrieving answer...')
41 | answer = get_rag_response(args.input, qa_chain)
42 |
43 | end = timeit.default_timer()
44 |
45 | print(f'\nAnswer:\n {answer}')
46 | print('=' * 50)
47 |
48 | print(f"Time to retrieve answer: {end - start}")
--------------------------------------------------------------------------------
/ingest.py:
--------------------------------------------------------------------------------
1 | from langchain.vectorstores import Chroma
2 | from langchain.text_splitter import RecursiveCharacterTextSplitter
3 | from langchain.document_loaders import PyPDFLoader, DirectoryLoader
4 | from langchain.embeddings import HuggingFaceEmbeddings
5 | import shutil
6 | import box
7 | import yaml
8 | import warnings
9 |
10 |
11 | warnings.filterwarnings("ignore", category=DeprecationWarning)
12 |
13 |
14 | def run_ingest():
15 | # Import config vars
16 | with open('config.yml', 'r', encoding='utf8') as ymlfile:
17 | cfg = box.Box(yaml.safe_load(ymlfile))
18 |
19 | loader = DirectoryLoader(cfg.DATA_PATH,
20 | glob='*.pdf',
21 | loader_cls=PyPDFLoader)
22 |
23 | documents = loader.load()
24 | text_splitter = RecursiveCharacterTextSplitter(chunk_size=cfg.CHUNK_SIZE,
25 | chunk_overlap=cfg.CHUNK_OVERLAP)
26 | texts = text_splitter.split_documents(documents)
27 | print(f"Loaded {len(texts)} splits")
28 |
29 | embeddings = HuggingFaceEmbeddings(model_name=cfg.EMBEDDINGS,
30 | model_kwargs={'device': cfg.DEVICE},
31 | encode_kwargs={'normalize_embeddings': cfg.NORMALIZE_EMBEDDINGS})
32 |
33 | shutil.rmtree(cfg.VECTOR_DB, ignore_errors=True)
34 |
35 | vector_store = Chroma.from_documents(texts,
36 | embeddings,
37 | collection_name=cfg.COLLECTION_NAME,
38 | collection_metadata={"hnsw:space": cfg.VECTOR_SPACE},
39 | persist_directory=cfg.VECTOR_DB)
40 |
41 | print(f"Vector store created at {cfg.VECTOR_DB}")
42 |
43 |
44 | if __name__ == "__main__":
45 | run_ingest()
--------------------------------------------------------------------------------
/rag/pipeline.py:
--------------------------------------------------------------------------------
1 | from langchain.vectorstores import Chroma
2 | from langchain.embeddings import HuggingFaceEmbeddings
3 | from langchain.prompts import PromptTemplate
4 | from langchain.chains import RetrievalQA
5 | from langchain.llms import Ollama
6 | import box
7 | import yaml
8 | import warnings
9 |
10 |
11 | warnings.filterwarnings("ignore", category=DeprecationWarning)
12 |
13 |
14 | def load_embedding_model(model_name, normalize_embedding=True, device='cpu'):
15 | return HuggingFaceEmbeddings(
16 | model_name=model_name,
17 | model_kwargs={'device': device},
18 | encode_kwargs={
19 | 'normalize_embeddings': normalize_embedding
20 | }
21 | )
22 |
23 |
24 | def load_retriever(embeddings, store_path, collection_name, vector_space, num_results=1):
25 | vector_store = Chroma(collection_name=collection_name,
26 | persist_directory=store_path,
27 | collection_metadata={"hnsw:space": vector_space},
28 | embedding_function=embeddings)
29 | retriever = vector_store.as_retriever(search_kwargs={"k": num_results})
30 |
31 | return retriever
32 |
33 |
34 | def load_prompt_template():
35 | template = """Use the following pieces of information to answer the user's question.
36 | If you don't know the answer, just say that you don't know, don't try to make up an answer.
37 |
38 | Context: {context}
39 | Question: {question}
40 |
41 | Only return the helpful answer below and nothing else.
42 | Helpful answer:
43 | """
44 |
45 | prompt = PromptTemplate.from_template(template)
46 |
47 | return prompt
48 |
49 |
50 | def load_qa_chain(retriever, llm, prompt):
51 | return RetrievalQA.from_chain_type(
52 | llm=llm,
53 | retriever=retriever,
54 | chain_type="stuff",
55 | return_source_documents=True,
56 | chain_type_kwargs={'prompt': prompt}
57 | )
58 |
59 |
60 | def build_rag_pipeline():
61 | # Import config vars
62 | with open('config.yml', 'r', encoding='utf8') as ymlfile:
63 | cfg = box.Box(yaml.safe_load(ymlfile))
64 |
65 | print("Loading embedding model...")
66 | embeddings = load_embedding_model(model_name=cfg.EMBEDDINGS,
67 | normalize_embedding=cfg.NORMALIZE_EMBEDDINGS,
68 | device=cfg.DEVICE)
69 |
70 | print("Loading vector store and retriever...")
71 | retriever = load_retriever(embeddings,
72 | cfg.VECTOR_DB,
73 | cfg.COLLECTION_NAME,
74 | cfg.VECTOR_SPACE,
75 | cfg.NUM_RESULTS)
76 |
77 | print("Loading prompt template...")
78 | prompt = load_prompt_template()
79 |
80 | print("Loading Ollama...")
81 | llm = Ollama(model=cfg.LLM, verbose=False, temperature=0)
82 |
83 | print("Loading QA chain...")
84 | qa_chain = load_qa_chain(retriever, llm, prompt)
85 |
86 | return qa_chain
87 |
88 |
89 |
--------------------------------------------------------------------------------
/prompts_zephyr.txt:
--------------------------------------------------------------------------------
1 | python main.py "retrieve one value: invoice number. format response as following {\"invoice_number\": {}}"
2 |
3 | {'invoice_number': '61356291'}
4 | ==================================================
5 | Time to retrieve answer: 103.90454878797755
6 |
7 |
8 | python main.py "retrieve one value: invoice date. format response as following {\"invoice_date\": {}}"
9 |
10 | {'invoice_date': {'09/06/2012': {}}}
11 | ==================================================
12 | Time to retrieve answer: 104.87561345699942
13 |
14 |
15 | python main.py "retrieve three values: client name, complete address and tax ID. format response as following {\"client_name\": {},\"address\": {},\"tax_id\": {}}"
16 |
17 | {'client_name': 'Rodriguez-Stevens', 'address': '2280 Angela Plain\nHortonshire, MS 93248', 'tax_id': '939-98-8477'}
18 | ==================================================
19 | Time to retrieve answer: 108.91416592500173
20 |
21 |
22 | python main.py "retrieve three values: seller name, complete address and tax ID. format response as following {\"seller_name\": {},\"address\": {},\"tax_id\": {}}"
23 |
24 | {'seller_name': 'Chapman, Kim and Green', 'address': '64731 James Branch\nSmithmouth, NC 26872', 'tax_id': '949-84-9105'}
25 | ==================================================
26 | Time to retrieve answer: 113.15477752301376
27 |
28 |
29 | python main.py "retrieve one value: invoice iban. format response as following {\"invoice_iban\": {}}"
30 |
31 | -
32 |
33 |
34 | python main.py "retrieve two values: net price and gross worth for the second invoice item from the table. format response as following {\"net_price\": {},\"gross_worth\": {}}"
35 |
36 | {'net_price': 280.8, 'gross_worth': 315.4}
37 | ==================================================
38 | Time to retrieve answer: 129.65302655799314
39 |
40 |
41 | python main.py "retrieve gross worth value for each invoice item from the table. format response as following {\"gross_worth\": []}"
42 |
43 | {'gross_worth': [6600, 12355, 825, 1429]}
44 | ==================================================
45 | Time to retrieve answer: 107.56224957900122
46 |
47 |
48 | python main.py "retrieve names of invoice items included into this invoice. format response as following {\"item_name\": []}"
49 |
50 | {'item_name': ['Wine Glasses Goblets Pair Clear', 'With Hooks Stemware Storage', 'Replacement Corkscrew Parts Spiral Worm Wine Opener Bottle Houdini', 'HOME ESSENTIALS GRADIENT STEMLESS WINE GLASSES SET OF 4 20 FL OZ (591 ml) NEW']}
51 | ==================================================
52 | Time to retrieve answer: 135.3677220880054
53 |
54 |
55 | python main.py "retrieve invoice total info. use this format for the answer {\"invoice_total\": {}}"
56 |
57 | {'invoice_total': {'net_worth': 192.81, 'vat': 19.28, 'gross_worth': 212.09}}
58 | ==================================================
59 | Time to retrieve answer: 111.45547287299996
60 |
61 |
62 | python main.py "retrieve three values: total gross worth, invoice number and invoice date. use this format for the response {\"total_gross_worth\": {}, \"invoice_number\": {}, \"invoice_date\": {}}"
63 |
64 | {'total_gross_worth': 21209, 'invoice_number': '61356291', 'invoice_date': '09/06/2012'}
65 | ==================================================
66 | Time to retrieve answer: 122.91637057694606
67 |
--------------------------------------------------------------------------------
/prompts_starling.txt:
--------------------------------------------------------------------------------
1 | python main.py "retrieve one value: invoice number. format response as following {\"invoice_number\": {}}"
2 |
3 | {'invoice_number': 61356291}
4 | ==================================================
5 | Time to retrieve answer: 97.6245634490042
6 |
7 |
8 | python main.py "retrieve one value: invoice date. format response as following {\"invoice_date\": {}}"
9 |
10 | {'invoice_date': '09/06/2012'}
11 | ==================================================
12 | Time to retrieve answer: 97.94699124002364
13 |
14 |
15 | python main.py "retrieve three values: client name, complete address and tax ID. format response as following {\"client_name\": {},\"address\": {},\"tax_id\": {}}"
16 |
17 | {'client_name': 'Rodriguez-Stevens', 'address': '2280 Angela Plain', 'tax_id': '939-98-8477'}
18 | ==================================================
19 | Time to retrieve answer: 102.29442486795597
20 |
21 |
22 | python main.py "retrieve three values: seller name, complete address and tax ID. format response as following {\"seller_name\": {},\"address\": {},\"tax_id\": {}}"
23 |
24 | {'seller_name': 'Chapman, Kim and Green', 'address': '64731 James Branch, Smithmouth, NC 26872', 'tax_id': '949-84-9105'}
25 | ==================================================
26 | Time to retrieve answer: 114.44599518104224
27 |
28 |
29 | python main.py "retrieve one value: invoice iban. format response as following {\"invoice_iban\": {}}"
30 |
31 | {'invoice_iban': 'GB50ACIE59715038217063'}
32 | ==================================================
33 | Time to retrieve answer: 100.62414190900745
34 |
35 |
36 | python main.py "retrieve two values: net price and gross worth for the second invoice item from the table. format response as following {\"net_price\": {},\"gross_worth\": {}}"
37 |
38 | {'net_price': 123.55, 'gross_worth': 246.7}
39 | ==================================================
40 | Time to retrieve answer: 103.98144886799855
41 |
42 |
43 | python main.py "retrieve gross worth value for each invoice item from the table. format response as following {\"gross_worth\": []}"
44 |
45 | {'gross_worth': [66.0, 123.55, 8.25, 14.29]}
46 | ==================================================
47 | Time to retrieve answer: 99.5734898429946
48 |
49 |
50 | python main.py "retrieve names of invoice items included into this invoice. format response as following {\"item_name\": []}"
51 |
52 | {'item_name': ['Wine Glasses Goblets Pair Clear Glass', 'With Hooks Stemware Storage Multiple Uses Iron Wine Rack Hanging Glass', 'Replacement Corkscrew Parts Spiral Worm Wine Opener Bottle Houdini', 'HOME ESSENTIALS GRADIENT STEMLESS WINE GLASSES SET OF 4 20 FL OZ (591 ml) NEW']}
53 | ==================================================
54 | Time to retrieve answer: 110.7761614319752
55 |
56 |
57 | python main.py "retrieve invoice total info. use this format for the answer {\"invoice_total\": {}}"
58 |
59 | {'invoice_total': 212.09}
60 | ==================================================
61 | Time to retrieve answer: 102.51593980001053
62 |
63 |
64 | python main.py "retrieve three values: total gross worth, invoice number and invoice date. use this format for the response {\"total_gross_worth\": {}, \"invoice_number\": {}, \"invoice_date\": {}}"
65 |
66 | {'total_gross_worth': 212.09, 'invoice_number': 61356291, 'invoice_date': '09/06/2012'}
67 | ==================================================
68 | Time to retrieve answer: 109.37831377796829
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | share/python-wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 | MANIFEST
28 |
29 | # PyInstaller
30 | # Usually these files are written by a python script from a template
31 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
32 | *.manifest
33 | *.spec
34 |
35 | # Installer logs
36 | pip-log.txt
37 | pip-delete-this-directory.txt
38 |
39 | # Unit test / coverage reports
40 | htmlcov/
41 | .tox/
42 | .nox/
43 | .coverage
44 | .coverage.*
45 | .cache
46 | nosetests.xml
47 | coverage.xml
48 | *.cover
49 | *.py,cover
50 | .hypothesis/
51 | .pytest_cache/
52 | cover/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | .pybuilder/
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | # For a library or package, you might want to ignore these files since the code is
87 | # intended to run in multiple environments; otherwise, check them in:
88 | # .python-version
89 |
90 | # pipenv
91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
94 | # install all needed dependencies.
95 | #Pipfile.lock
96 |
97 | # poetry
98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99 | # This is especially recommended for binary packages to ensure reproducibility, and is more
100 | # commonly ignored for libraries.
101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102 | #poetry.lock
103 |
104 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
105 | __pypackages__/
106 |
107 | # Celery stuff
108 | celerybeat-schedule
109 | celerybeat.pid
110 |
111 | # SageMath parsed files
112 | *.sage.py
113 |
114 | # Environments
115 | .env
116 | .venv
117 | env/
118 | venv/
119 | ENV/
120 | env.bak/
121 | venv.bak/
122 |
123 | # Spyder project settings
124 | .spyderproject
125 | .spyproject
126 |
127 | # Rope project settings
128 | .ropeproject
129 |
130 | # mkdocs documentation
131 | /site
132 |
133 | # mypy
134 | .mypy_cache/
135 | .dmypy.json
136 | dmypy.json
137 |
138 | # Pyre type checker
139 | .pyre/
140 |
141 | # pytype static type analyzer
142 | .pytype/
143 |
144 | # Cython debug symbols
145 | cython_debug/
146 |
147 | # PyCharm
148 | # JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
149 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
150 | # and can be added to the global gitignore or merged into this file. For a more nuclear
151 | # option (not recommended) you can uncomment the following to ignore the entire idea folder.
152 | .idea
153 | vectorstore/
154 | .DS_Store
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------