-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Readme + Docs #10
Merged
Readme + Docs #10
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
61d87f2
readme take one
axl1313 e71f89f
docs update wip
axl1313 31488ca
temp update codex-sdk dependency
axl1313 0feb579
update codex sdk dependency
axl1313 4a9d455
Merge branch 'main' into readme
axl1313 48dd421
fix format
axl1313 42b40d3
fix tests
axl1313 f3210fe
remove extra brackets
axl1313 c72b432
Merge branch 'main' into readme
axl1313 3ccdbcf
update docstrings
axl1313 0973608
address comments
axl1313 627fd55
add docstrings for types
axl1313 d24cd4d
link to web app tutorial
axl1313 8fbbec8
fix links, typo
axl1313 1f68520
update smolagents link
axl1313 ae9a6d2
remove readme todos
axl1313 ed2b8ed
Merge branch 'main' into readme
axl1313 395d036
generate class type annotations for docstrings
axl1313 93e49d9
Merge branch 'main' into readme
axl1313 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,66 @@ | ||
# Cleanlab Codex [](https://github.com/cleanlab/cleanlab-codex/actions/workflows/ci.yml) [](https://pypi.org/project/cleanlab-codex) [](https://pypi.org/project/cleanlab-codex) | ||
# Cleanlab Codex - Closing the AI Knowledge Gap | ||
|
||
## Table of Contents | ||
[](https://github.com/cleanlab/cleanlab-codex/actions/workflows/ci.yml) [](https://pypi.org/project/cleanlab-codex) [](https://pypi.org/project/cleanlab-codex) | ||
|
||
- [Installation](#installation) | ||
- [License](#license) | ||
Codex enables you to seamlessly leverage knowledge from Subject Matter Experts (SMEs) to improve your RAG/Agentic applications. | ||
|
||
## Installation | ||
The `cleanlab-codex` library provides a simple interface to integrate Codex's capabilities into your RAG application. | ||
See immediate impact with just a few lines of code! | ||
|
||
## Demo | ||
|
||
Install the package: | ||
|
||
```console | ||
pip install cleanlab-codex | ||
``` | ||
|
||
Integrating Codex into your RAG application as a tool is as simple as: | ||
|
||
```python | ||
from cleanlab_codex import CodexTool | ||
|
||
def rag(question, system_prompt, tools) -> str: | ||
"""Your RAG/Agentic code here""" | ||
... | ||
|
||
# Initialize the Codex tool | ||
codex_tool = CodexTool.from_access_key("your-access-key") | ||
|
||
# Update your system prompt to include information on how to use the Codex tool | ||
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.""" | ||
|
||
# Convert the Codex tool to a framework-specific tool | ||
framework_specific_codex_tool = codex_tool.to_<framework_name>_tool() # i.e. codex_tool.to_llamaindex_tool(), codex_tool.to_openai_tool(), etc. | ||
|
||
# Pass the Codex tool to your RAG/Agentic framework | ||
response = rag(question, system_prompt, [framework_specific_codex_tool]) | ||
``` | ||
|
||
(Note: exact code will depend on the RAG/Agentic framework you are using) | ||
<!-- TODO: add demo video --> | ||
<!-- 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 --> | ||
|
||
## Why Codex? | ||
- **Identify Knowledge Gaps**: Codex captures knowledge gaps in your application so that you can easily identify which questions require expert input. | ||
- **Efficiently Leverage SMEs**: Codex ensures the SMEs see the most critical knowledge gaps first. <!-- not sure if we should include this rn since it's not implemented yet --> | ||
- **Easy Integration**: Integrate Codex into your RAG/Agentic application with just a few lines of code. | ||
- **Immediate Impact**: SME responses instantly enhance your AI applications. | ||
|
||
## How does Codex interact with my AI application? | ||
<!-- TODO: add architecture diagram w/ brief explanation --> | ||
|
||
|
||
## What impact will I see? | ||
<!-- TODO: benchmarks --> | ||
|
||
## Documentation | ||
|
||
Comprehensive documentation along with tutorials and examples can be found [here](https://help.cleanlab.ai/codex). | ||
|
||
## Contributing | ||
<!-- TODO: add contributing section or consider leaving out for now --> | ||
|
||
## License | ||
|
||
`cleanlab-codex` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,3 +1,5 @@ | ||||||
"""Tool abstraction for Cleanlab Codex.""" | ||||||
|
||||||
from __future__ import annotations | ||||||
|
||||||
from typing import Any, ClassVar, Optional | ||||||
|
@@ -38,7 +40,16 @@ def from_access_key( | |||||
project_id: Optional[str] = None, | ||||||
fallback_answer: Optional[str] = DEFAULT_FALLBACK_ANSWER, | ||||||
) -> CodexTool: | ||||||
"""Creates a CodexTool from an access key. The project ID that the CodexTool will use is the one that is associated with the access key.""" | ||||||
"""Creates a CodexTool from an access key. The project ID that the CodexTool will use is the one that is associated with the access key. | ||||||
|
||||||
Args: | ||||||
access_key (str): The access key for the Codex project. | ||||||
project_id (str, optional): The ID of the project to use. If not provided, the project ID will be inferred from the access key. If provided, the project ID must be the ID of the project that the access key is associated with. | ||||||
fallback_answer (str, optional): The fallback answer to use if the Codex project cannot answer the question. | ||||||
|
||||||
Returns: | ||||||
CodexTool: The CodexTool. | ||||||
""" | ||||||
return cls( | ||||||
codex_client=Codex(key=access_key), | ||||||
project_id=project_id, | ||||||
|
@@ -56,6 +67,14 @@ def from_client( | |||||
"""Creates a CodexTool from a Codex client. | ||||||
If the Codex client is initialized with a project access key, the CodexTool will use the project ID that is associated with the access key. | ||||||
If the Codex client is initialized with a user API key, a project ID must be provided. | ||||||
|
||||||
Args: | ||||||
codex_client (Codex): The Codex client to use. | ||||||
project_id (str, optional): The ID of the project to use. If not provided and the Codex client is authenticated with a project-level access key, the project ID will be inferred from the access key. | ||||||
fallback_answer (str, optional): The fallback answer to use if the Codex project cannot answer the question. | ||||||
|
||||||
Returns: | ||||||
CodexTool: The CodexTool. | ||||||
""" | ||||||
return cls( | ||||||
codex_client=codex_client, | ||||||
|
@@ -65,17 +84,31 @@ def from_client( | |||||
|
||||||
@property | ||||||
def tool_name(self) -> str: | ||||||
"""The name to use for the tool when passing to an LLM.""" | ||||||
"""The name to use for the tool when passing to an LLM. This is the name the LLM will use when determining whether to call the tool. | ||||||
|
||||||
Note: We recommend using the default tool name which we've benchmarked. Only override this if you have a specific reason.""" | ||||||
return self._tool_name | ||||||
|
||||||
@tool_name.setter | ||||||
def tool_name(self, value: str) -> None: | ||||||
"""Sets the name to use for the tool when passing to an LLM.""" | ||||||
elisno marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
self._tool_name = value | ||||||
|
||||||
@property | ||||||
def tool_description(self) -> str: | ||||||
"""The description to use for the tool when passing to an LLM.""" | ||||||
"""The description to use for the tool when passing to an LLM. This is the description that the LLM will see when determining whether to call the tool. | ||||||
|
||||||
Note: We recommend using the default tool description which we've benchmarked. Only override this if you have a specific reason.""" | ||||||
return self._tool_description | ||||||
|
||||||
@tool_description.setter | ||||||
def tool_description(self, value: str) -> None: | ||||||
"""Sets the description to use for the tool when passing to an LLM.""" | ||||||
self._tool_description = value | ||||||
|
||||||
@property | ||||||
def fallback_answer(self) -> Optional[str]: | ||||||
"""The fallback answer to use if the Codex project cannot answer the question.""" | ||||||
"""The fallback answer to use if the Codex project cannot answer the question. This will be returned by the tool if the Codex project does not have an answer to the question.""" | ||||||
return self._fallback_answer | ||||||
|
||||||
@fallback_answer.setter | ||||||
|
@@ -90,12 +123,13 @@ def query(self, question: str) -> Optional[str]: | |||||
question: The question to ask the advisor. This should be the same as the original user question, except in cases where the user question is missing information that could be additionally clarified. | ||||||
|
||||||
Returns: | ||||||
The answer to the question, or None if the answer is not available. | ||||||
The answer to the question if available. If no answer is available, the fallback answer is returned if provided, otherwise None is returned. | ||||||
""" | ||||||
return self._codex_client.query(question, project_id=self._project_id, fallback_answer=self._fallback_answer)[0] | ||||||
|
||||||
def to_openai_tool(self) -> dict[str, Any]: | ||||||
"""Converts the tool to an OpenAI tool.""" | ||||||
"""Converts the tool to the expected format for an [OpenAI function tool](https://platform.openai.com/docs/guides/function-calling). | ||||||
See more information on defining functions for OpenAI tool calls [here](https://platform.openai.com/docs/guides/function-calling#defining-functions).""" | ||||||
from cleanlab_codex.utils import format_as_openai_tool | ||||||
|
||||||
return format_as_openai_tool( | ||||||
|
@@ -106,7 +140,10 @@ def to_openai_tool(self) -> dict[str, Any]: | |||||
) | ||||||
|
||||||
def to_smolagents_tool(self) -> Any: | ||||||
"""Converts the tool to a smolagents tool.""" | ||||||
"""Converts the tool to a [smolagents tool](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool). | ||||||
|
||||||
Note: You must have the [`smolagents` library installed](https://github.com/huggingface/smolagents/tree/main?tab=readme-ov-file#quick-demo) to use this method. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" | ||||||
from cleanlab_codex.utils.smolagents import CodexTool as SmolagentsCodexTool | ||||||
|
||||||
return SmolagentsCodexTool( | ||||||
|
@@ -117,7 +154,10 @@ def to_smolagents_tool(self) -> Any: | |||||
) | ||||||
|
||||||
def to_llamaindex_tool(self) -> Any: | ||||||
"""Converts the tool to a LlamaIndex FunctionTool.""" | ||||||
"""Converts the tool to a [LlamaIndex FunctionTool](https://docs.llamaindex.ai/en/stable/module_guides/deploying/agents/tools/#functiontool). | ||||||
|
||||||
Note: You must have the [`llama-index` library installed](https://docs.llamaindex.ai/en/stable/getting_started/installation/) to use this method. | ||||||
""" | ||||||
from llama_index.core.tools import FunctionTool | ||||||
|
||||||
from cleanlab_codex.utils.llamaindex import get_function_schema | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid duplication with (planned/WIP) docs, and leave these TODO sections out of the README.