ragas-examples 0.3.5__tar.gz

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.
Files changed (47) hide show
  1. ragas_examples-0.3.5/LICENSE +201 -0
  2. ragas_examples-0.3.5/PKG-INFO +130 -0
  3. ragas_examples-0.3.5/README.md +96 -0
  4. ragas_examples-0.3.5/gdrive_append_example.py +177 -0
  5. ragas_examples-0.3.5/gdrive_backend_example.py +130 -0
  6. ragas_examples-0.3.5/iterate_prompt/__init__.py +0 -0
  7. ragas_examples-0.3.5/iterate_prompt/datasets/support_triage.csv +21 -0
  8. ragas_examples-0.3.5/iterate_prompt/evals.py +341 -0
  9. ragas_examples-0.3.5/iterate_prompt/promptv1.txt +18 -0
  10. ragas_examples-0.3.5/iterate_prompt/promptv2_fewshot.txt +65 -0
  11. ragas_examples-0.3.5/iterate_prompt/run_prompt.py +41 -0
  12. ragas_examples-0.3.5/pyproject.toml +68 -0
  13. ragas_examples-0.3.5/ragas_examples/__init__.py +17 -0
  14. ragas_examples-0.3.5/ragas_examples/_version.py +34 -0
  15. ragas_examples-0.3.5/ragas_examples/agent_evals/__init__.py +0 -0
  16. ragas_examples-0.3.5/ragas_examples/agent_evals/agent.py +409 -0
  17. ragas_examples-0.3.5/ragas_examples/agent_evals/evals.py +78 -0
  18. ragas_examples-0.3.5/ragas_examples/benchmark_llm/__init__.py +0 -0
  19. ragas_examples-0.3.5/ragas_examples/benchmark_llm/datasets/discount_benchmark.csv +11 -0
  20. ragas_examples-0.3.5/ragas_examples/benchmark_llm/evals.py +274 -0
  21. ragas_examples-0.3.5/ragas_examples/benchmark_llm/prompt.py +71 -0
  22. ragas_examples-0.3.5/ragas_examples/prompt_evals/__init__.py +0 -0
  23. ragas_examples-0.3.5/ragas_examples/prompt_evals/evals.py +75 -0
  24. ragas_examples-0.3.5/ragas_examples/prompt_evals/prompt.py +32 -0
  25. ragas_examples-0.3.5/ragas_examples/rag_eval/__init__.py +0 -0
  26. ragas_examples-0.3.5/ragas_examples/rag_eval/evals.py +84 -0
  27. ragas_examples-0.3.5/ragas_examples/rag_eval/rag.py +481 -0
  28. ragas_examples-0.3.5/ragas_examples/text2sql/__init__.py +36 -0
  29. ragas_examples-0.3.5/ragas_examples/text2sql/analyze_errors.py +198 -0
  30. ragas_examples-0.3.5/ragas_examples/text2sql/data_utils.py +380 -0
  31. ragas_examples-0.3.5/ragas_examples/text2sql/datasets/booksql_sample.csv +100 -0
  32. ragas_examples-0.3.5/ragas_examples/text2sql/db_utils.py +458 -0
  33. ragas_examples-0.3.5/ragas_examples/text2sql/evals.py +387 -0
  34. ragas_examples-0.3.5/ragas_examples/text2sql/prompt.txt +111 -0
  35. ragas_examples-0.3.5/ragas_examples/text2sql/prompt_v2.txt +135 -0
  36. ragas_examples-0.3.5/ragas_examples/text2sql/prompt_v3.txt +144 -0
  37. ragas_examples-0.3.5/ragas_examples/text2sql/text2sql_agent.py +522 -0
  38. ragas_examples-0.3.5/ragas_examples/text2sql/validate_sql_dataset.py +317 -0
  39. ragas_examples-0.3.5/ragas_examples/workflow_eval/__init__.py +0 -0
  40. ragas_examples-0.3.5/ragas_examples/workflow_eval/evals.py +107 -0
  41. ragas_examples-0.3.5/ragas_examples/workflow_eval/workflow.py +670 -0
  42. ragas_examples-0.3.5/ragas_examples.egg-info/PKG-INFO +130 -0
  43. ragas_examples-0.3.5/ragas_examples.egg-info/SOURCES.txt +73 -0
  44. ragas_examples-0.3.5/ragas_examples.egg-info/dependency_links.txt +1 -0
  45. ragas_examples-0.3.5/ragas_examples.egg-info/requires.txt +11 -0
  46. ragas_examples-0.3.5/ragas_examples.egg-info/top_level.txt +1 -0
  47. ragas_examples-0.3.5/setup.cfg +4 -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 [2023] [Exploding Gradients]
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.
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: ragas-examples
3
+ Version: 0.3.5
4
+ Summary: Official examples for the ragas project
5
+ Author: Ragas Team
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/explodinggradients/ragas
8
+ Project-URL: Documentation, https://docs.ragas.io
9
+ Project-URL: Code, https://github.com/explodinggradients/ragas
10
+ Project-URL: Issues, https://github.com/explodinggradients/ragas/issues
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: ragas
25
+ Requires-Dist: openai>=1.0.0
26
+ Requires-Dist: pandas
27
+ Provides-Extra: gdrive
28
+ Requires-Dist: ragas[gdrive]; extra == "gdrive"
29
+ Provides-Extra: text2sql
30
+ Requires-Dist: huggingface_hub>=0.16.0; extra == "text2sql"
31
+ Requires-Dist: datacompy>=0.8.0; extra == "text2sql"
32
+ Requires-Dist: python-dotenv>=1.0.0; extra == "text2sql"
33
+ Dynamic: license-file
34
+
35
+ # Ragas Examples
36
+
37
+ Official examples demonstrating how to use Ragas for evaluating different types of AI applications including RAG systems, agents, prompts, workflows, and LLM benchmarking. These examples might be unstable and are subject to change.
38
+
39
+ ## Installation
40
+
41
+ ### From PyPI (after release)
42
+ ```bash
43
+ pip install "ragas[examples]"
44
+ ```
45
+
46
+ ### Local Development
47
+ Install both main ragas and examples packages in editable mode:
48
+
49
+ ```bash
50
+ cd /path/to/ragas
51
+ uv pip install -e . -e ./examples
52
+ ```
53
+
54
+ Or using regular pip:
55
+ ```bash
56
+ cd /path/to/ragas
57
+ pip install -e . -e ./examples
58
+ ```
59
+
60
+ ## Available Examples
61
+
62
+ - **`ragas_examples.agent_evals`** - Agent evaluation examples
63
+ - **`ragas_examples.benchmark_llm`** - LLM benchmarking and comparison examples
64
+ - **`ragas_examples.prompt_evals`** - Prompt evaluation examples
65
+ - **`ragas_examples.rag_eval`** - RAG system evaluation examples
66
+ - **`ragas_examples.workflow_eval`** - Workflow evaluation examples
67
+
68
+ ## Usage
69
+
70
+ ### Set Environment Variables
71
+
72
+ Most examples require API keys to be set:
73
+
74
+ ```bash
75
+ export OPENAI_API_KEY=your_key_here
76
+ ```
77
+
78
+ For Google Drive examples, also install the gdrive extra:
79
+ ```bash
80
+ pip install "ragas[examples,gdrive]"
81
+ ```
82
+
83
+ ### Running Examples as Modules
84
+
85
+ After installation, you can run examples directly:
86
+
87
+ ```bash
88
+ # Run benchmark LLM prompt example
89
+ python -m ragas_examples.benchmark_llm.prompt
90
+
91
+ # Run benchmark LLM evaluation
92
+ python -m ragas_examples.benchmark_llm.evals
93
+
94
+ # Run other examples
95
+ python -m ragas_examples.rag_eval.evals
96
+ python -m ragas_examples.agent_evals.evals
97
+ python -m ragas_examples.prompt_evals.evals
98
+ python -m ragas_examples.workflow_eval.evals
99
+ ```
100
+
101
+ ## Release process
102
+
103
+ - The examples package is versioned independently using Git tags with prefix `examples-v` (e.g., `examples-v0.1.0`).
104
+ - Publishing is handled by the GitHub Actions workflow `publish-examples.yml`, which builds from `examples/` and publishes to PyPI when such a tag is pushed.
105
+
106
+ ### Release Commands
107
+
108
+ To create and push a new release:
109
+
110
+ ```bash
111
+ # Create and push a new tag (replace X.Y.Z with actual version)
112
+ git tag examples-vX.Y.Z
113
+ git push origin examples-vX.Y.Z
114
+
115
+ # Example:
116
+ git tag examples-v0.1.0
117
+ git push origin examples-v0.1.0
118
+ ```
119
+
120
+ ## Local Development & Testing
121
+
122
+
123
+ ## Local Development & Testing
124
+
125
+ ### Verify Installation
126
+ ```bash
127
+
128
+ # Test module execution
129
+ python -m ragas_examples.benchmark_llm.prompt --help
130
+ ```
@@ -0,0 +1,96 @@
1
+ # Ragas Examples
2
+
3
+ Official examples demonstrating how to use Ragas for evaluating different types of AI applications including RAG systems, agents, prompts, workflows, and LLM benchmarking. These examples might be unstable and are subject to change.
4
+
5
+ ## Installation
6
+
7
+ ### From PyPI (after release)
8
+ ```bash
9
+ pip install "ragas[examples]"
10
+ ```
11
+
12
+ ### Local Development
13
+ Install both main ragas and examples packages in editable mode:
14
+
15
+ ```bash
16
+ cd /path/to/ragas
17
+ uv pip install -e . -e ./examples
18
+ ```
19
+
20
+ Or using regular pip:
21
+ ```bash
22
+ cd /path/to/ragas
23
+ pip install -e . -e ./examples
24
+ ```
25
+
26
+ ## Available Examples
27
+
28
+ - **`ragas_examples.agent_evals`** - Agent evaluation examples
29
+ - **`ragas_examples.benchmark_llm`** - LLM benchmarking and comparison examples
30
+ - **`ragas_examples.prompt_evals`** - Prompt evaluation examples
31
+ - **`ragas_examples.rag_eval`** - RAG system evaluation examples
32
+ - **`ragas_examples.workflow_eval`** - Workflow evaluation examples
33
+
34
+ ## Usage
35
+
36
+ ### Set Environment Variables
37
+
38
+ Most examples require API keys to be set:
39
+
40
+ ```bash
41
+ export OPENAI_API_KEY=your_key_here
42
+ ```
43
+
44
+ For Google Drive examples, also install the gdrive extra:
45
+ ```bash
46
+ pip install "ragas[examples,gdrive]"
47
+ ```
48
+
49
+ ### Running Examples as Modules
50
+
51
+ After installation, you can run examples directly:
52
+
53
+ ```bash
54
+ # Run benchmark LLM prompt example
55
+ python -m ragas_examples.benchmark_llm.prompt
56
+
57
+ # Run benchmark LLM evaluation
58
+ python -m ragas_examples.benchmark_llm.evals
59
+
60
+ # Run other examples
61
+ python -m ragas_examples.rag_eval.evals
62
+ python -m ragas_examples.agent_evals.evals
63
+ python -m ragas_examples.prompt_evals.evals
64
+ python -m ragas_examples.workflow_eval.evals
65
+ ```
66
+
67
+ ## Release process
68
+
69
+ - The examples package is versioned independently using Git tags with prefix `examples-v` (e.g., `examples-v0.1.0`).
70
+ - Publishing is handled by the GitHub Actions workflow `publish-examples.yml`, which builds from `examples/` and publishes to PyPI when such a tag is pushed.
71
+
72
+ ### Release Commands
73
+
74
+ To create and push a new release:
75
+
76
+ ```bash
77
+ # Create and push a new tag (replace X.Y.Z with actual version)
78
+ git tag examples-vX.Y.Z
79
+ git push origin examples-vX.Y.Z
80
+
81
+ # Example:
82
+ git tag examples-v0.1.0
83
+ git push origin examples-v0.1.0
84
+ ```
85
+
86
+ ## Local Development & Testing
87
+
88
+
89
+ ## Local Development & Testing
90
+
91
+ ### Verify Installation
92
+ ```bash
93
+
94
+ # Test module execution
95
+ python -m ragas_examples.benchmark_llm.prompt --help
96
+ ```
@@ -0,0 +1,177 @@
1
+ """Example showing how to append data to an existing Google Drive dataset.
2
+
3
+ This demonstrates the proper pattern for adding data to existing datasets
4
+ while preserving the existing records.
5
+ """
6
+
7
+ from pydantic import BaseModel
8
+
9
+ from ragas.dataset import Dataset
10
+
11
+
12
+ # Example data model
13
+ class EvaluationRecord(BaseModel):
14
+ question: str
15
+ answer: str
16
+ context: str
17
+ score: float
18
+ feedback: str
19
+
20
+
21
+ def append_to_existing_dataset():
22
+ """Example of appending to an existing dataset."""
23
+
24
+ folder_id = "folder_id_here" # Replace with your actual Google Drive folder ID
25
+
26
+ # Option 1: Load existing dataset and add more data
27
+ print("=== Appending to Existing Dataset ===")
28
+
29
+ try:
30
+ # Try to load existing dataset
31
+ dataset = Dataset.load(
32
+ name="evaluation_results",
33
+ backend="gdrive",
34
+ data_model=EvaluationRecord,
35
+ folder_id=folder_id,
36
+ credentials_path="credentials.json",
37
+ token_path="token.json",
38
+ )
39
+ print(f"Loaded existing dataset with {len(dataset)} records")
40
+
41
+ except FileNotFoundError:
42
+ # Dataset doesn't exist, create a new one
43
+ print("Dataset doesn't exist, creating new one")
44
+ dataset = Dataset(
45
+ name="evaluation_results",
46
+ backend="gdrive",
47
+ data_model=EvaluationRecord,
48
+ folder_id=folder_id,
49
+ credentials_path="credentials.json",
50
+ token_path="token.json",
51
+ )
52
+
53
+ # Show existing records
54
+ print("Existing records:")
55
+ for i, record in enumerate(dataset):
56
+ print(
57
+ f" {i + 1}. {record['question'] if isinstance(record, dict) else record.question}"
58
+ )
59
+
60
+ # Add new records
61
+ new_records = [
62
+ EvaluationRecord(
63
+ question="What is the largest planet in our solar system?",
64
+ answer="Jupiter",
65
+ context="Solar system knowledge question.",
66
+ score=0.9,
67
+ feedback="Correct answer",
68
+ ),
69
+ EvaluationRecord(
70
+ question="Who painted the Mona Lisa?",
71
+ answer="Leonardo da Vinci",
72
+ context="Art history question.",
73
+ score=1.0,
74
+ feedback="Perfect answer",
75
+ ),
76
+ ]
77
+
78
+ # Append new records
79
+ for record in new_records:
80
+ dataset.append(record)
81
+
82
+ print(f"\nAdded {len(new_records)} new records")
83
+
84
+ # Save the updated dataset (this replaces the sheet with all records)
85
+ dataset.save()
86
+ print(f"Saved updated dataset with {len(dataset)} total records")
87
+
88
+ # Verify by listing all records
89
+ print("\nAll records in dataset:")
90
+ for i, record in enumerate(dataset):
91
+ print(
92
+ f" {i + 1}. {record['question'] if isinstance(record, dict) else record.question} -> {record['answer'] if isinstance(record, dict) else record.answer}"
93
+ )
94
+
95
+ return dataset
96
+
97
+
98
+ def create_multiple_datasets():
99
+ """Example of creating separate datasets instead of appending."""
100
+
101
+ folder_id = "folder_id_here" # Replace with your actual Google Drive folder ID
102
+
103
+ print("\n=== Creating Multiple Datasets ===")
104
+
105
+ # Create different datasets for different evaluation runs
106
+ datasets = {}
107
+
108
+ for run_name, data in [
109
+ (
110
+ "basic_qa",
111
+ [
112
+ EvaluationRecord(
113
+ question="What is 1+1?",
114
+ answer="Two",
115
+ context="Basic math",
116
+ score=1.0,
117
+ feedback="Correct",
118
+ )
119
+ ],
120
+ ),
121
+ (
122
+ "advanced_qa",
123
+ [
124
+ EvaluationRecord(
125
+ question="Explain quantum entanglement",
126
+ answer="Quantum entanglement is a phenomenon...",
127
+ context="Advanced physics",
128
+ score=0.8,
129
+ feedback="Good explanation",
130
+ )
131
+ ],
132
+ ),
133
+ ]:
134
+ dataset = Dataset(
135
+ name=f"evaluation_{run_name}",
136
+ backend="gdrive",
137
+ data_model=EvaluationRecord,
138
+ folder_id=folder_id,
139
+ credentials_path="credentials.json",
140
+ token_path="token.json",
141
+ )
142
+
143
+ for record in data:
144
+ dataset.append(record)
145
+
146
+ dataset.save()
147
+ datasets[run_name] = dataset
148
+ print(f"Created dataset '{run_name}' with {len(dataset)} records")
149
+
150
+ # List all datasets
151
+ available_datasets = list(datasets.values())[0].backend.list_datasets()
152
+ print(f"\nAll available datasets: {available_datasets}")
153
+
154
+ return datasets
155
+
156
+
157
+ if __name__ == "__main__":
158
+ try:
159
+ # Method 1: Append to existing dataset
160
+ dataset = append_to_existing_dataset()
161
+
162
+ # Method 2: Create separate datasets
163
+ datasets = create_multiple_datasets()
164
+
165
+ print("\n✅ Append operations completed successfully!")
166
+ print("\nKey points:")
167
+ print(
168
+ "- dataset.save() replaces the entire sheet (this is the intended behavior)"
169
+ )
170
+ print("- To append: load existing data, add new records, then save")
171
+ print("- For different evaluation runs, consider separate datasets")
172
+
173
+ except Exception as e:
174
+ print(f"Error: {e}")
175
+ import traceback
176
+
177
+ traceback.print_exc()