Skip to content

Commit e33123f

Browse files
authored
add ability to create remediations through client (#92)
1 parent 1a79a6a commit e33123f

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.0.21] 2025-06-22
11+
12+
- Support adding remediations to a project
13+
- Docstring updates
14+
1015
## [1.0.20] 2025-06-17
1116

1217
- Remove Codex-as-a-tool
@@ -99,8 +104,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99104

100105
- Initial release of the `cleanlab-codex` client library.
101106

102-
[Unreleased]: https://github.com/cleanlab/cleanlab-codex/compare/v1.0.20...HEAD
103-
[1.0.19]: https://github.com/cleanlab/cleanlab-codex/compare/v1.0.19...v1.0.20
107+
[Unreleased]: https://github.com/cleanlab/cleanlab-codex/compare/v1.0.21...HEAD
108+
[1.0.21]: https://github.com/cleanlab/cleanlab-codex/compare/v1.0.20...v1.0.21
109+
[1.0.20]: https://github.com/cleanlab/cleanlab-codex/compare/v1.0.19...v1.0.20
104110
[1.0.19]: https://github.com/cleanlab/cleanlab-codex/compare/v1.0.18...v1.0.19
105111
[1.0.18]: https://github.com/cleanlab/cleanlab-codex/compare/v1.0.17...v1.0.18
106112
[1.0.17]: https://github.com/cleanlab/cleanlab-codex/compare/v1.0.16...v1.0.17

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ classifiers = [
2626
]
2727
dependencies = [
2828
"cleanlab-tlm~=1.1",
29-
"codex-sdk==0.1.0a20",
29+
"codex-sdk==0.1.0a21",
3030
"pydantic>=2.0.0, <3",
3131
]
3232

src/cleanlab_codex/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# SPDX-License-Identifier: MIT
2-
__version__ = "1.0.20"
2+
__version__ = "1.0.21"

src/cleanlab_codex/project.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from datetime import datetime
66
from typing import TYPE_CHECKING as _TYPE_CHECKING
7-
from typing import Dict, List, Literal, Optional
7+
from typing import Dict, Literal, Optional
88

99
from codex import AuthenticationError
1010

@@ -16,7 +16,6 @@
1616
from datetime import datetime
1717

1818
from codex import Codex as _Codex
19-
from codex.types.project_validate_params import Options as ProjectValidateOptions
2019
from codex.types.project_validate_response import ProjectValidateResponse
2120

2221

@@ -151,23 +150,49 @@ def validate(
151150
query: str,
152151
response: str,
153152
*,
154-
constrain_outputs: Optional[List[str]] = None,
155153
custom_metadata: Optional[object] = None,
156154
eval_scores: Optional[Dict[str, float]] = None,
157155
eval_thresholds: Optional[Dict[str, float]] = None,
158-
options: Optional[ProjectValidateOptions] = None,
159156
quality_preset: Literal["best", "high", "medium", "low", "base"] = "medium",
160157
) -> ProjectValidateResponse:
158+
"""Run validation on a query to an AI system.
159+
160+
Args:
161+
context (str): The context used by the AI system to generate a response for the query.
162+
prompt (str): The full prompt (including system instructions, context, and the original query) used by the AI system to generate a response for the query.
163+
query (str): The original user input to the AI system.
164+
response (str): The response generated by the AI system for the query.
165+
custom_metadata (object, optional): Custom metadata to log in Codex for the query.
166+
eval_scores (Dict[str, float], optional): Optional scores to use for the query. When provided, Codex will skip running TrustworthyRAG evaluations on the query and use the provided scores instead.
167+
eval_thresholds (Dict[str, float], optional): Optional thresholds to use for evaluating the query. We recommend configuring thresholds on the Project instead and using the same thresholds for all queries.
168+
quality_preset (Literal["best", "high", "medium", "low", "base"], optional): The quality preset to use for the query.
169+
170+
Returns:
171+
ProjectValidateResponse: The response from the validation.
172+
"""
161173
return self._sdk_client.projects.validate(
162174
self._id,
163175
context=context,
164176
prompt=prompt,
165177
query=query,
166178
response=response,
167-
constrain_outputs=constrain_outputs,
168179
custom_eval_thresholds=eval_thresholds,
169180
custom_metadata=custom_metadata,
170181
eval_scores=eval_scores,
171-
options=options,
172182
quality_preset=quality_preset,
173183
)
184+
185+
def add_remediation(self, question: str, answer: str | None = None) -> None:
186+
"""Add a remediation to the project. A remediation represents a question and answer pair that is expert verified
187+
and should be used to answer future queries to the AI system that are similar to the question.
188+
189+
Args:
190+
question (str): The question to add to the project.
191+
answer (str, optional): The expert answer for the question. If not provided, the question will be added to the project without an expert answer.
192+
"""
193+
self._sdk_client.projects.remediations.create(
194+
project_id=self.id,
195+
question=question,
196+
answer=answer,
197+
extra_headers=_AnalyticsMetadata().to_headers(),
198+
)

src/cleanlab_codex/validator.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from cleanlab_codex.project import Project
1414

1515
if _TYPE_CHECKING:
16-
from codex.types.project_validate_params import Options as ProjectValidateOptions
1716
from codex.types.project_validate_response import ProjectValidateResponse
1817

1918

@@ -60,7 +59,6 @@ def validate(
6059
form_prompt: Optional[Callable[[str, str], str]] = None,
6160
metadata: Optional[dict[str, Any]] = None,
6261
eval_scores: Optional[dict[str, float]] = None,
63-
options: Optional[ProjectValidateOptions] = None,
6462
quality_preset: Literal["best", "high", "medium", "low", "base"] = "medium",
6563
) -> ProjectValidateResponse:
6664
"""Evaluate whether the AI-generated response is bad, and if so, request an alternate expert answer.
@@ -105,6 +103,5 @@ def validate(
105103
custom_metadata=metadata,
106104
eval_scores=eval_scores,
107105
eval_thresholds=self._eval_thresholds,
108-
options=options,
109106
quality_preset=quality_preset,
110107
)

0 commit comments

Comments
 (0)