chATLAS_Chains 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- benchmark/basic.py +34 -0
- benchmark/conversational.py +0 -0
- chATLAS_Chains/__init__.py +0 -0
- chATLAS_Chains/chains/__init__.py +0 -0
- chATLAS_Chains/chains/basic.py +42 -0
- chATLAS_Chains/chains/basic_graph.py +163 -0
- chATLAS_Chains/chains/conversational.py +0 -0
- chATLAS_Chains/chains/websearch_retrieval_chain.py +447 -0
- chATLAS_Chains/llm/__init__.py +0 -0
- chATLAS_Chains/llm/model_selection.py +47 -0
- chATLAS_Chains/log.py +20 -0
- chATLAS_Chains/prompt/__init__.py +0 -0
- chATLAS_Chains/prompt/doc_joiners.py +5 -0
- chATLAS_Chains/prompt/starters.py +151 -0
- chATLAS_Chains/search/__init__.py +0 -0
- chATLAS_Chains/search/basic.py +45 -0
- chATLAS_Chains/utils/__init__.py +0 -0
- chATLAS_Chains/utils/doc_utils.py +28 -0
- chATLAS_Chains/vectorstore.py +94 -0
- chatlas_chains-0.1.3.dist-info/METADATA +113 -0
- chatlas_chains-0.1.3.dist-info/RECORD +30 -0
- chatlas_chains-0.1.3.dist-info/WHEEL +5 -0
- chatlas_chains-0.1.3.dist-info/licenses/LICENSE +201 -0
- chatlas_chains-0.1.3.dist-info/top_level.txt +3 -0
- tests/__init__.py +0 -0
- tests/conftest.py +274 -0
- tests/test_chains.py +54 -0
- tests/test_llm.py +81 -0
- tests/test_search.py +48 -0
- tests/test_utils.py +27 -0
|
@@ -0,0 +1,201 @@
|
|
|
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 (C) 2023 CERN for the benefit of the ATLAS collaboration
|
|
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.
|
tests/__init__.py
ADDED
|
File without changes
|
tests/conftest.py
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Some elements of a chain require a LangChainVectorStore object with a running PG server to connect to locally.
|
|
3
|
+
This
|
|
4
|
+
|
|
5
|
+
**NOTE** If running tests on lxplus can just connect to CERN dbod and
|
|
6
|
+
update the TEST_DB_CONFIG to be correct for your server
|
|
7
|
+
|
|
8
|
+
Pytest fixtures to:
|
|
9
|
+
- Creates a test_db environment for testing the postgresql
|
|
10
|
+
- Creates fake twiki documents to write to the db with
|
|
11
|
+
- Populates the vectorstore with these documents
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
import tempfile
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
import psycopg2
|
|
19
|
+
import pytest
|
|
20
|
+
|
|
21
|
+
from chATLAS_Embed import (
|
|
22
|
+
PostgresParentChildVectorStore,
|
|
23
|
+
RecursiveTextSplitter,
|
|
24
|
+
syncedTwikiVectorStoreCreator,
|
|
25
|
+
)
|
|
26
|
+
from chATLAS_Embed.EmbeddingModels import SentenceTransformerEmbedding
|
|
27
|
+
|
|
28
|
+
# Database configuration for testing
|
|
29
|
+
TEST_DB_CONFIG = {
|
|
30
|
+
"host": "localhost",
|
|
31
|
+
"port": 5432,
|
|
32
|
+
"user": "postgres",
|
|
33
|
+
"password": "password",
|
|
34
|
+
"database": "chatlas_test_db",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.fixture(scope="session")
|
|
39
|
+
def test_db():
|
|
40
|
+
"""Create a test database and clean it up after tests"""
|
|
41
|
+
# Connect to default postgres database to create test database
|
|
42
|
+
conn = psycopg2.connect(
|
|
43
|
+
host=TEST_DB_CONFIG["host"],
|
|
44
|
+
port=TEST_DB_CONFIG["port"],
|
|
45
|
+
user=TEST_DB_CONFIG["user"],
|
|
46
|
+
password=TEST_DB_CONFIG["password"],
|
|
47
|
+
database="postgres",
|
|
48
|
+
)
|
|
49
|
+
conn.autocommit = True
|
|
50
|
+
cursor = conn.cursor()
|
|
51
|
+
|
|
52
|
+
# Drop test database if it exists and create new one
|
|
53
|
+
cursor.execute(f"DROP DATABASE IF EXISTS {TEST_DB_CONFIG['database']}")
|
|
54
|
+
cursor.execute(f"CREATE DATABASE {TEST_DB_CONFIG['database']}")
|
|
55
|
+
|
|
56
|
+
cursor.close()
|
|
57
|
+
conn.close()
|
|
58
|
+
|
|
59
|
+
# Return connection string for the test database
|
|
60
|
+
connection_string = f"postgresql://{TEST_DB_CONFIG['user']}:{TEST_DB_CONFIG['password']}@{TEST_DB_CONFIG['host']}:{TEST_DB_CONFIG['port']}/{TEST_DB_CONFIG['database']}"
|
|
61
|
+
|
|
62
|
+
yield connection_string
|
|
63
|
+
|
|
64
|
+
# Cleanup: Drop test database after all tests
|
|
65
|
+
try:
|
|
66
|
+
# Reconnect to the postgres database
|
|
67
|
+
conn = psycopg2.connect(
|
|
68
|
+
host=TEST_DB_CONFIG["host"],
|
|
69
|
+
port=TEST_DB_CONFIG["port"],
|
|
70
|
+
user=TEST_DB_CONFIG["user"],
|
|
71
|
+
password=TEST_DB_CONFIG["password"],
|
|
72
|
+
database="postgres",
|
|
73
|
+
)
|
|
74
|
+
conn.autocommit = True
|
|
75
|
+
cursor = conn.cursor()
|
|
76
|
+
|
|
77
|
+
# Disconnect any other sessions connected to the test database
|
|
78
|
+
cursor.execute(f"""
|
|
79
|
+
SELECT pg_terminate_backend(pid)
|
|
80
|
+
FROM pg_stat_activity
|
|
81
|
+
WHERE datname = '{TEST_DB_CONFIG["database"]}'
|
|
82
|
+
AND pid <> pg_backend_pid();
|
|
83
|
+
""")
|
|
84
|
+
|
|
85
|
+
# Now drop the database
|
|
86
|
+
cursor.execute(f"DROP DATABASE IF EXISTS {TEST_DB_CONFIG['database']}")
|
|
87
|
+
cursor.close()
|
|
88
|
+
conn.close()
|
|
89
|
+
|
|
90
|
+
except psycopg2.errors.ObjectInUse:
|
|
91
|
+
print(f"Database {TEST_DB_CONFIG['database']} is still in use, skipping drop.")
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@pytest.fixture(scope="session")
|
|
95
|
+
def embedding_model():
|
|
96
|
+
"""Initialize the real embedding model"""
|
|
97
|
+
return SentenceTransformerEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@pytest.fixture(scope="session")
|
|
101
|
+
def test_docs():
|
|
102
|
+
"""Create temporary test documents"""
|
|
103
|
+
temp_dir = tempfile.mkdtemp()
|
|
104
|
+
docs = []
|
|
105
|
+
|
|
106
|
+
# Create sample TWiki documents
|
|
107
|
+
test_contents = [
|
|
108
|
+
{
|
|
109
|
+
"filename": "ADCPlotOperations.txt",
|
|
110
|
+
"content": """%META:TOPICINFO{author="BaseUserMapping_333" date="1416477899" format="1.1" version="1.369"}%
|
|
111
|
+
%META:TOPICPARENT{name="ADCOperationsDailyReports"}%
|
|
112
|
+
%STARTINCLUDE%
|
|
113
|
+
The ATLAS Experiment is one of the largest particle physics experiments at CERN.
|
|
114
|
+
It is designed to study particle collisions at the Large Hadron Collider.
|
|
115
|
+
The detector is 46 meters long and weighs about 7,000 tonnes.
|
|
116
|
+
ATLAS is one of two general-purpose detectors at the Large Hadron Collider (LHC). It investigates a wide range of physics,
|
|
117
|
+
from the Higgs boson to extra dimensions and particles that could make up dark matter.
|
|
118
|
+
Although it has the same scientific goals as the CMS experiment, it uses different technical solutions and a different magnet-system design.
|
|
119
|
+
Beams of particles from the LHC collide at the centre of the ATLAS detector making collision debris in the form of new particles,
|
|
120
|
+
which fly out from the collision point in all directions. Six different detecting subsystems arranged in layers around the collision point record the paths,
|
|
121
|
+
momentum, and energy of the particles, allowing them to be individually identified. A huge magnet system bends the paths of charged particles so that their momenta can be measured.
|
|
122
|
+
|
|
123
|
+
The interactions in the ATLAS detectors create an enormous flow of data. To digest the data, ATLAS uses an advanced
|
|
124
|
+
“trigger” system to tell the detector which events to record and which to ignore. Complex data-acquisition and
|
|
125
|
+
computing systems are then used to analyse the collision events recorded. At 46 m long, 25 m high and 25 m wide,
|
|
126
|
+
the 7000-tonne ATLAS detector is the largest volume particle detector ever constructed. It sits in a cavern 100 m
|
|
127
|
+
below ground near the main CERN site, close to the village of Meyrin in Switzerland.
|
|
128
|
+
|
|
129
|
+
below ground near the main CERN site, close to the village of Meyrin in Switzerland.
|
|
130
|
+
below ground near the main CERN site, close to the village of Meyrin in Switzerland.
|
|
131
|
+
below ground near the main CERN site, close to the village of Meyrin in Switzerland.
|
|
132
|
+
below ground near the main CERN site, close to the village of Meyrin in Switzerland.
|
|
133
|
+
below ground near the main CERN site, close to the village of Meyrin in Switzerland.
|
|
134
|
+
|
|
135
|
+
More than 5500 scientists from 245 institutes in 42 countries work on the ATLAS experiment (March 2022).
|
|
136
|
+
For the latest information, see here.
|
|
137
|
+
%STOPINCLUDE%
|
|
138
|
+
Extra other info which should not be included.
|
|
139
|
+
""",
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"filename": "Higgs_Boson.txt",
|
|
143
|
+
"content": """%META:TOPICINFO{author="wikipedia" date="1736878918" format="1.1" version="1.3"}%
|
|
144
|
+
%META:TOPICPARENT{name="HiggsToTauTauToHH2012Winter"}%
|
|
145
|
+
|
|
146
|
+
%STARTINCLUDE%
|
|
147
|
+
TWiki https://twiki.cern.ch/twiki/bin/view/Main/WebHome
|
|
148
|
+
Atlas Web https://twiki.cern.ch/twiki/bin/view/Atlas/WebHome
|
|
149
|
+
AtlasUpgrade https://twiki.cern.ch/twiki/bin/view/Atlas/AtlasUpgrade
|
|
150
|
+
UpgradeProjectOffice https://twiki.cern.ch/twiki/bin/view/Atlas/UpgradeProjectOffice
|
|
151
|
+
UpgradeProjectOfficeCAD https://twiki.cern.ch/twiki/bin/view/Atlas/UpgradeProjectOfficeCAD
|
|
152
|
+
3DDataExchangeProcess https://twiki.cern.ch/twiki/bin/view/Atlas/3DDataExchangeProcess
|
|
153
|
+
-----HEADERS-----
|
|
154
|
+
h1: 3D Data exchange between ATLAS TC and collaboration institutes
|
|
155
|
+
|
|
156
|
+
-----TEXT-----
|
|
157
|
+
The Higgs boson was discovered by the ATLAS and CMS experiments in 2012.
|
|
158
|
+
This discovery confirmed the existence of the Higgs field, which gives particles their mass.
|
|
159
|
+
Peter Higgs and François Englert won the Nobel Prize in Physics for this theoretical prediction.
|
|
160
|
+
The Higgs boson, sometimes called the Higgs particle, is an elementary particle in the Standard Model of particle
|
|
161
|
+
physics produced by the quantum excitation of the Higgs field, one of the fields in particle physics theory.
|
|
162
|
+
In the Standard Model, the Higgs particle is a massive scalar boson with zero spin, even (positive) parity,
|
|
163
|
+
no electric charge, and no colour charge that couples to (interacts with) mass. It is also very unstable,
|
|
164
|
+
decaying into other particles almost immediately upon generation.
|
|
165
|
+
The Higgs field is a scalar field with two neutral and two electrically charged components that form a complex doublet
|
|
166
|
+
of the weak isospin SU(2) symmetry. Its "Sombrero potential" leads it to take a nonzero value everywhere
|
|
167
|
+
(including otherwise empty space), which breaks the weak isospin symmetry of the electroweak interaction and,
|
|
168
|
+
via the Higgs mechanism, gives a rest mass to all massive elementary particles of the Standard Model,
|
|
169
|
+
including the Higgs boson itself. The existence of the Higgs field became the last unverified part of the Standard
|
|
170
|
+
Model of particle physics, and for several decades was considered "the central problem in particle physics"
|
|
171
|
+
The Higgs boson, sometimes called the Higgs particle, is an elementary particle in the Standard Model of
|
|
172
|
+
particle physics produced by the quantum excitation of the Higgs field, one of the fields in particle physics theory.
|
|
173
|
+
As a layman I would now say… I think we have it.
|
|
174
|
+
|
|
175
|
+
“It” was the Higgs boson, the almost-mythical entity that had put particle physics in the global spotlight,
|
|
176
|
+
and the man proclaiming to be a mere layman was none other than CERN’s Director-General, Rolf Heuer.
|
|
177
|
+
Heuer spoke in the Laboratory’s main auditorium on 4 July 2012, moments after the CMS and ATLAS collaborations
|
|
178
|
+
at the Large Hadron Collider announced the discovery of a new elementary particle, which we now know is a Higgs boson.
|
|
179
|
+
Applause reverberated in Geneva from as far away as Melbourne, Australia, where delegates of the International
|
|
180
|
+
Conference on High Energy Physics were connected via video-conference.higgsjuly4,seminar,Milestones,
|
|
181
|
+
Higgs Boson Discovery,360
|
|
182
|
+
4 July 2012: A packed auditorium at CERN listens keenly to the announcement from CMS and ATLAS (Image: Maximilien Brice/CERN)
|
|
183
|
+
So what exactly is so special about this particle?“Easy! It is the first and only elementary scalar
|
|
184
|
+
particle we have observed,” grins Rebeca Gonzalez Suarez, who, as a doctoral student, was involved in
|
|
185
|
+
the CMS search for the Higgs boson. Easy for a physicist,
|
|
186
|
+
%STOPINCLUDE%
|
|
187
|
+
Extra text that should be ignored
|
|
188
|
+
""",
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"filename": "LHC.txt",
|
|
192
|
+
"content": """%META:TOPICINFO{author="google" date="1328618061" format="1.1" version="1.3"}%
|
|
193
|
+
%META:TOPICPARENT{name="LHC"}%
|
|
194
|
+
|
|
195
|
+
%STARTINCLUDE%
|
|
196
|
+
-----PARENT STRUCTURE----
|
|
197
|
+
TWiki https://twiki.cern.ch/twiki/bin/view/Main/WebHome
|
|
198
|
+
Atlas Web https://twiki.cern.ch/twiki/bin/view/Atlas/WebHome
|
|
199
|
+
AtlasUpgrade https://twiki.cern.ch/twiki/bin/view/Atlas/AtlasUpgrade
|
|
200
|
+
UpgradeProjectOffice https://twiki.cern.ch/twiki/bin/view/Atlas/UpgradeProjectOffice
|
|
201
|
+
UpgradeProjectOfficeCAD https://twiki.cern.ch/twiki/bin/view/Atlas/UpgradeProjectOfficeCAD
|
|
202
|
+
-----HEADERS-----
|
|
203
|
+
h1: 3D Data exchange between ATLAS TC and collaboration institutes
|
|
204
|
+
|
|
205
|
+
-----TEXT-----
|
|
206
|
+
The Large Hadron Collider (LHC) is the world's largest particle accelerator.
|
|
207
|
+
It consists of a 27-kilometer ring of superconducting magnets.
|
|
208
|
+
The LHC can collide protons at energies up to 13 TeV.
|
|
209
|
+
Inside the accelerator, two high-energy particle beams travel at close to the speed of light before they
|
|
210
|
+
are made to collide. The beams travel in opposite directions in separate beam pipes – two tubes kept at
|
|
211
|
+
ultrahigh vacuum. They are guided around the accelerator ring by a strong magnetic field maintained by
|
|
212
|
+
superconducting electromagnets. The electromagnets are built from coils of special electric cable that
|
|
213
|
+
operates in a superconducting state, efficiently conducting electricity without resistance or loss of energy.
|
|
214
|
+
This requires chilling the magnets to ‑271.3°C – a temperature colder than outer space. For this reason,
|
|
215
|
+
much of the accelerator is connected to a distribution system of liquid helium, which cools the magnets,
|
|
216
|
+
as well as to other supply services.
|
|
217
|
+
|
|
218
|
+
LHC stands for Large Hadron Collider, the world's largest and most powerful particle accelerator. It's located in a tunnel at CERN, the European Organization for Nuclear Research, on the Swiss-French border.
|
|
219
|
+
How it works
|
|
220
|
+
The LHC is a 27-kilometer ring of superconducting magnets that accelerate particles.
|
|
221
|
+
Beams of particles collide at four locations around the ring.
|
|
222
|
+
The collisions produce tiny fireballs that are hotter than the core of the sun.
|
|
223
|
+
What it's used for
|
|
224
|
+
The LHC has helped scientists discover the Higgs boson, a particle that gives mass to other particles.
|
|
225
|
+
The LHC may also help scientists understand why there is an imbalance of matter and antimatter in the universe.
|
|
226
|
+
Safety
|
|
227
|
+
The LHC Safety Assessment Group (LSAG) has concluded that the LHC collisions are not dangerous.
|
|
228
|
+
The LSAG's conclusions have been endorsed by CERN's Scientific Policy Committee.
|
|
229
|
+
History
|
|
230
|
+
The LHC was built between 1998 and 2008 with the help of over 10,000 scientists from hundreds of universities and laboratories.
|
|
231
|
+
It first started up on September 10, 2008.
|
|
232
|
+
%STOPINCLUDE%
|
|
233
|
+
""",
|
|
234
|
+
},
|
|
235
|
+
]
|
|
236
|
+
|
|
237
|
+
for doc in test_contents:
|
|
238
|
+
doc_path = Path(temp_dir) / doc["filename"]
|
|
239
|
+
with open(doc_path, "w", encoding="UTF-8") as f:
|
|
240
|
+
f.write(doc["content"])
|
|
241
|
+
docs.append(doc_path)
|
|
242
|
+
|
|
243
|
+
yield Path(temp_dir)
|
|
244
|
+
|
|
245
|
+
# Cleanup temporary files
|
|
246
|
+
for doc in docs:
|
|
247
|
+
os.remove(doc)
|
|
248
|
+
os.rmdir(temp_dir)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
@pytest.fixture(scope="session")
|
|
252
|
+
def vector_store(test_db, embedding_model):
|
|
253
|
+
"""Initialize the vector store with test database"""
|
|
254
|
+
return PostgresParentChildVectorStore(connection_string=test_db, embedding_model=embedding_model)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
@pytest.fixture(scope="session")
|
|
258
|
+
def populated_vector_store(vector_store, test_docs):
|
|
259
|
+
"""Populate the vector store with test documents"""
|
|
260
|
+
parent_splitter = RecursiveTextSplitter(chunk_size=2048, chunk_overlap=24)
|
|
261
|
+
child_splitter = RecursiveTextSplitter(chunk_size=256, chunk_overlap=24)
|
|
262
|
+
|
|
263
|
+
twiki_creator = syncedTwikiVectorStoreCreator(
|
|
264
|
+
vector_store=vector_store,
|
|
265
|
+
child_splitter=child_splitter,
|
|
266
|
+
parent_splitter=parent_splitter,
|
|
267
|
+
output_dir=Path("./test_output"),
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
twiki_creator.create_update_vectorstore(input_path=test_docs, update=True, verbose=True)
|
|
271
|
+
|
|
272
|
+
yield vector_store
|
|
273
|
+
|
|
274
|
+
del vector_store
|
tests/test_chains.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Unit tests for basic_retrieval_chain
|
|
3
|
+
|
|
4
|
+
These**NOTE** These require a running postgres database with a populated vector store.
|
|
5
|
+
|
|
6
|
+
The fixtures used for the tests are defined in conftest.py and are automatically gathered by pytest
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
from langchain_core.runnables import RunnableSequence
|
|
11
|
+
from pydantic import ValidationError
|
|
12
|
+
|
|
13
|
+
from chATLAS_Chains.chains.basic import basic_retrieval_chain
|
|
14
|
+
from chATLAS_Chains.prompt.starters import CHAT_PROMPT_TEMPLATE
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_basic_retrieval_chain_returns_runnablesequence(populated_vector_store):
|
|
18
|
+
"""
|
|
19
|
+
Test the search_runnable function with a populated vector store.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
chain = basic_retrieval_chain(
|
|
23
|
+
prompt=CHAT_PROMPT_TEMPLATE, vectorstore=populated_vector_store, model_name="gpt-4o-mini"
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
assert isinstance(chain, RunnableSequence)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.fixture
|
|
30
|
+
def vectorstores_list(populated_vector_store):
|
|
31
|
+
return [populated_vector_store for _ in range(3)]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_search_runnable_returns_runnablesequence_with_list_of_vectorstores(vectorstores_list):
|
|
35
|
+
chain = basic_retrieval_chain(prompt=CHAT_PROMPT_TEMPLATE, vectorstore=vectorstores_list, model_name="gpt-4o-mini")
|
|
36
|
+
print(type(chain))
|
|
37
|
+
assert isinstance(chain, RunnableSequence)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_search_runnable_error_on_invalid_input():
|
|
41
|
+
with pytest.raises(ValidationError):
|
|
42
|
+
basic_retrieval_chain(prompt=CHAT_PROMPT_TEMPLATE, vectorstore="not a vectorstore", model_name="gpt-4o-mini")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_search_runnable_returns_docs_and_answer(populated_vector_store):
|
|
46
|
+
chain = basic_retrieval_chain(
|
|
47
|
+
prompt=CHAT_PROMPT_TEMPLATE, vectorstore=populated_vector_store, model_name="gpt-4o-mini"
|
|
48
|
+
)
|
|
49
|
+
output = chain.invoke("What is the Higgs boson?")
|
|
50
|
+
|
|
51
|
+
assert "docs" in output
|
|
52
|
+
assert "answer" in output
|
|
53
|
+
|
|
54
|
+
assert isinstance(output["docs"], list)
|
tests/test_llm.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from unittest.mock import MagicMock, patch
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from chATLAS_Chains.llm.model_selection import SUPPORTED_CHAT_MODELS, get_chat_model # Replace with actual path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.fixture
|
|
9
|
+
def mock_env_key(monkeypatch):
|
|
10
|
+
monkeypatch.setenv("CHATLAS_OPENAI_KEY", "fake-api-key")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@pytest.fixture
|
|
14
|
+
def mock_model_class():
|
|
15
|
+
"""Returns a MagicMock class that returns a mock instance when called."""
|
|
16
|
+
mock_instance = MagicMock(name="MockChatModelInstance")
|
|
17
|
+
mock_class = MagicMock(name="MockChatModelClass", return_value=mock_instance)
|
|
18
|
+
return mock_class
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_get_chat_model_valid_model_name(mock_env_key, mock_model_class):
|
|
22
|
+
with patch("importlib.import_module") as mock_import_module:
|
|
23
|
+
mock_import_module.return_value = MagicMock(ChatOpenAI=mock_model_class)
|
|
24
|
+
|
|
25
|
+
model = get_chat_model("gpt-4")
|
|
26
|
+
|
|
27
|
+
mock_import_module.assert_called_with("langchain_openai")
|
|
28
|
+
mock_model_class.assert_called_once_with(model_name="gpt-4", openai_api_key="fake-api-key")
|
|
29
|
+
assert model is mock_model_class.return_value
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_get_chat_model_unsupported_model_name_defaults(mock_env_key, mock_model_class):
|
|
33
|
+
with patch("importlib.import_module") as mock_import_module:
|
|
34
|
+
mock_import_module.return_value = MagicMock(ChatOpenAI=mock_model_class)
|
|
35
|
+
|
|
36
|
+
model = get_chat_model("unknown-model")
|
|
37
|
+
|
|
38
|
+
mock_model_class.assert_called_once_with(model_name="gpt-4o-mini", openai_api_key="fake-api-key")
|
|
39
|
+
assert model is mock_model_class.return_value
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_get_chat_model_missing_env_var(monkeypatch):
|
|
43
|
+
monkeypatch.delenv("CHATLAS_OPENAI_KEY", raising=False)
|
|
44
|
+
|
|
45
|
+
with pytest.raises(ValueError, match="CHATLAS_OPENAI_KEY not set in environment"):
|
|
46
|
+
get_chat_model("gpt-3.5-turbo")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_get_chat_model_api_key_stripped(monkeypatch, mock_model_class):
|
|
50
|
+
monkeypatch.setenv("CHATLAS_OPENAI_KEY", " api-key-with-spaces ")
|
|
51
|
+
|
|
52
|
+
with patch("importlib.import_module") as mock_import_module:
|
|
53
|
+
mock_import_module.return_value = MagicMock(ChatOpenAI=mock_model_class)
|
|
54
|
+
|
|
55
|
+
get_chat_model("gpt-4")
|
|
56
|
+
mock_model_class.assert_called_once_with(model_name="gpt-4", openai_api_key="api-key-with-spaces")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_get_chat_model_import_error(mock_env_key):
|
|
60
|
+
with patch("importlib.import_module", side_effect=ImportError("Module not found")):
|
|
61
|
+
with pytest.raises(ImportError, match="Module not found"):
|
|
62
|
+
get_chat_model("gpt-4")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_get_chat_model_attribute_error(mock_env_key):
|
|
66
|
+
mock_library = MagicMock()
|
|
67
|
+
del mock_library.ChatOpenAI # simulate missing attribute
|
|
68
|
+
|
|
69
|
+
with patch("importlib.import_module", return_value=mock_library):
|
|
70
|
+
with pytest.raises(AttributeError):
|
|
71
|
+
get_chat_model("gpt-4")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_all_supported_models_resolve(mock_env_key, mock_model_class):
|
|
75
|
+
"""Checks that all models in the supported list work correctly."""
|
|
76
|
+
with patch("importlib.import_module") as mock_import_module:
|
|
77
|
+
mock_import_module.return_value = MagicMock(ChatOpenAI=mock_model_class)
|
|
78
|
+
|
|
79
|
+
for model_name in SUPPORTED_CHAT_MODELS:
|
|
80
|
+
result = get_chat_model(model_name)
|
|
81
|
+
assert result is mock_model_class.return_value
|
tests/test_search.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Unit tests for search_runnable
|
|
3
|
+
|
|
4
|
+
**NOTE** These require a running postgres database with a populated vector store.
|
|
5
|
+
|
|
6
|
+
The fixtures used for the tests are defined in conftest.py and are automatically gathered by pytest
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
from langchain_core.runnables import RunnableSequence
|
|
12
|
+
from pydantic import ValidationError
|
|
13
|
+
|
|
14
|
+
from chATLAS_Chains.search.basic import search_runnable
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_search_runnable_returns_runnablesequence(populated_vector_store):
|
|
18
|
+
"""
|
|
19
|
+
Test the search_runnable function with a populated vector store.
|
|
20
|
+
"""
|
|
21
|
+
print(type(populated_vector_store))
|
|
22
|
+
# Create a runnable for searching
|
|
23
|
+
searcher = search_runnable(vectorstore=populated_vector_store)
|
|
24
|
+
|
|
25
|
+
assert isinstance(searcher, RunnableSequence)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.fixture
|
|
29
|
+
def vectorstores_list(populated_vector_store):
|
|
30
|
+
return [populated_vector_store for _ in range(3)]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_search_runnable_returns_runnablesequence_with_list_of_vectorstores(vectorstores_list):
|
|
34
|
+
runnable = search_runnable(vectorstores_list)
|
|
35
|
+
assert isinstance(runnable, RunnableSequence)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_search_runnable_error_on_invalid_input():
|
|
39
|
+
with pytest.raises(ValidationError):
|
|
40
|
+
search_runnable("not_a_vectorstore")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_search_runnable_returns_docs_and_questions(populated_vector_store):
|
|
44
|
+
searcher = search_runnable(vectorstore=populated_vector_store)
|
|
45
|
+
output = searcher.invoke("What is the Higgs boson?")
|
|
46
|
+
|
|
47
|
+
assert "docs" in output
|
|
48
|
+
assert "question" in output
|