Skip to content

Commit 37234a2

Browse files
Remove Codex-as-a-tool (#90)
* Remove Codex-as-a-tool * increase code coverage * run hatch fmt * update readme to use Validator API * remove extra line
1 parent bdedb48 commit 37234a2

File tree

13 files changed

+58
-484
lines changed

13 files changed

+58
-484
lines changed

DEVELOPMENT.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can run the tests on your local machine with:
1616
hatch test
1717
```
1818

19-
The [`test` command][hatch-test] supports options such as `-c` for measuring test coverage, `-a` for testing with a matrix of Python versions, and appending an argument like `tests/test_codex_tool.py::test_to_llamaindex_tool` for running a single test.
19+
The [`test` command][hatch-test] supports options such as `-c` for measuring test coverage, `-a` for testing with a matrix of Python versions, and appending an argument like `tests/test_validator.py::test_validate_expert_answer` for running a single test.
2020

2121
[hatch-test]: https://hatch.pypa.io/latest/tutorials/testing/overview/
2222

@@ -79,8 +79,8 @@ Automated releases are handled by the [release workflow][release-workflow] which
7979

8080
1. Bump the version in `src/cleanlab_codex/__about__.py`. You can use the [`hatch version`][hatch-version] command to do this.
8181
2. Ensure that the release notes are updated in [`CHANGELOG.md`][changelog]:
82-
- You should update the `[Unreleased]` header to the new version and add a new `[Unreleased]` section at the top of the file.
83-
- You should update the link for the `[Unreleased]` code and add a new link to the code diff for the new version.
82+
- You should update the `[Unreleased]` header to the new version and add a new `[Unreleased]` section at the top of the file.
83+
- You should update the link for the `[Unreleased]` code and add a new link to the code diff for the new version.
8484
3. Create a PR and merge these changes into the `main` branch.
8585
4. After the PR is merged into `main`, create a new release tag by running `git tag v<output of hatch version>` (i.e. `git tag v0.0.1`).
8686
5. Push the tag to the repository by running `git push origin <tag>`.
@@ -90,7 +90,6 @@ Automated releases are handled by the [release workflow][release-workflow] which
9090
[hatch-version]: https://hatch.pypa.io/latest/version/#updating
9191
[changelog]: CHANGELOG.md
9292

93-
9493
### How to build and install the package locally
9594

9695
You may want to build and install the package locally - for example, to see how your changes affect other Python code in a script or Jupyter notebook.
@@ -110,14 +109,3 @@ Testing, type checking, and formatting/linting is [checked in CI][ci].
110109
To target a different Codex backend environment (i.e. staging or local), set the `CODEX_BASE_URL` environment variable. Example: `export CODEX_BASE_URL=http://localhost:8080`.
111110

112111
## Style guide
113-
114-
### Adding integrations with external libraries
115-
116-
When adding integrations with external libraries, always use a lazy import. The external dependency should not be required to use the `cleanlab-codex` library. Wrap the lazy import in a `try`/`except` block to catch the `ImportError` and raise a `MissingDependencyError` with a helpful message. See [codex_tool.py](src/cleanlab_codex/codex_tool.py) file for examples one of which is shown below:
117-
118-
```python
119-
try:
120-
from cleanlab_codex.utils.smolagents import CodexTool as SmolagentsCodexTool
121-
except ImportError as e:
122-
raise MissingDependencyError("smolagents", "https://github.com/huggingface/smolagents") from e
123-
```

README.md

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

55
Codex enables you to seamlessly leverage knowledge from Subject Matter Experts (SMEs) to improve your RAG/Agentic applications.
66

7-
The `cleanlab-codex` library provides a simple interface to integrate Codex's capabilities into your RAG application.
7+
The `cleanlab-codex` library provides a simple interface to integrate Codex's capabilities into your RAG application.
88
See immediate impact with just a few lines of code!
99

1010
## Demo
@@ -15,31 +15,30 @@ Install the package:
1515
pip install cleanlab-codex
1616
```
1717

18-
Integrating Codex into your RAG application as a tool is as simple as:
18+
Integrating Codex into your RAG application is as simple as:
1919

2020
```python
21-
from cleanlab_codex import CodexTool
22-
23-
def rag(question, system_prompt, tools) -> str:
24-
"""Your RAG/Agentic code here"""
25-
...
26-
27-
# Initialize the Codex tool
28-
codex_tool = CodexTool.from_access_key("your-access-key")
29-
30-
# Update your system prompt to include information on how to use the Codex tool
31-
system_prompt = f"""Answer the user's Question based on the following Context. If the Context doesn't adequately address the Question, use the {codex_tool.tool_name} tool to ask an outside expert."""
32-
33-
# Convert the Codex tool to a framework-specific tool
34-
framework_specific_codex_tool = codex_tool.to_<framework_name>_tool() # i.e. codex_tool.to_llamaindex_tool(), codex_tool.to_openai_tool(), etc.
35-
36-
# Pass the Codex tool to your RAG/Agentic framework
37-
response = rag(question, system_prompt, [framework_specific_codex_tool])
21+
from cleanlab_codex import Validator
22+
validator = Validator(codex_access_key=...) # optional configurations can improve accuracy/latency
23+
24+
# Your existing RAG code:
25+
context = rag_retrieve_context(user_query)
26+
prompt = rag_form_prompt(user_query, retrieved_context)
27+
response = rag_generate_response(prompt)
28+
29+
# Detect bad responses and remediate with Cleanlab
30+
results = validator.validate(query=query, context=context, response=response,
31+
form_prompt=rag_form_prompt)
32+
33+
final_response = (
34+
results["expert_answer"] # Codex's answer
35+
if results["is_bad_response"] and results["expert_answer"]
36+
else response # Your RAG system's initial response
37+
)
3838
```
3939

40-
(Note: Exact code will depend on the RAG/Agentic framework you are using. [Other integrations](https://help.cleanlab.ai/codex/concepts/integrations/) are available if you prefer to avoid Tool Calls.)
4140
<!-- TODO: add demo video -->
42-
<!-- Video should show Codex tool added to a RAG system, question asked that requires knowledge from an outside expert, Codex tool used to ask an outside expert, and expert response returned to the user -->
41+
<!-- Video should show Codex added to a RAG system, question asked that requires knowledge from an outside expert, Codex used to ask an outside expert, and expert response returned to the user -->
4342

4443
## Why Codex?
4544
- **Detect Knowledge Gaps and Hallucinations**: Codex identifies knowledge gaps and incorrect/untrustworthy responses in your AI application, to help you know which questions require expert input.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ exclude_lines = [
9696
"if TYPE_CHECKING:",
9797
"if _TYPE_CHECKING:",
9898
]
99+
show_missing = true
99100

100101
[tool.hatch.envs.coverage]
101102
detached = true

src/cleanlab_codex/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: MIT
22
from cleanlab_codex.client import Client
3-
from cleanlab_codex.codex_tool import CodexTool
43
from cleanlab_codex.project import Project
54
from cleanlab_codex.validator import Validator
65

7-
__all__ = ["Client", "CodexTool", "Project", "Validator"]
6+
__all__ = ["Client", "Project", "Validator"]

src/cleanlab_codex/codex_tool.py

Lines changed: 0 additions & 209 deletions
This file was deleted.

src/cleanlab_codex/internal/analytics.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class IntegrationType(str, Enum):
99
"""Supported methods for integrating Codex into a RAG system using this library."""
1010

1111
BACKUP = "backup"
12-
TOOL = "tool"
1312

1413

1514
class _AnalyticsMetadata:

src/cleanlab_codex/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __str__(self) -> str:
3737
class Project:
3838
"""Represents a Codex project.
3939
40-
To integrate a Codex project into your RAG/Agentic system, we recommend using one of our abstractions such as [`CodexTool`](/codex/api/python/codex_tool).
40+
To integrate a Codex project into your RAG/Agentic system, we recommend using one of our abstractions such as [`Validator`](/codex/api/python/validator).
4141
"""
4242

4343
def __init__(self, sdk_client: _Codex, project_id: str, *, verify_existence: bool = True):
Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
from cleanlab_codex.utils.aws import Tool as AWSConverseTool
2-
from cleanlab_codex.utils.aws import ToolSpec as AWSToolSpec
3-
from cleanlab_codex.utils.aws import format_as_aws_converse_tool
41
from cleanlab_codex.utils.function import FunctionParameters
5-
from cleanlab_codex.utils.openai import Function as OpenAIFunction
6-
from cleanlab_codex.utils.openai import Tool as OpenAITool
7-
from cleanlab_codex.utils.openai import format_as_openai_tool
82

93
__all__ = [
104
"FunctionParameters",
11-
"OpenAIFunction",
12-
"OpenAITool",
13-
"AWSConverseTool",
14-
"AWSToolSpec",
15-
"format_as_openai_tool",
16-
"format_as_aws_converse_tool",
175
]

0 commit comments

Comments
 (0)