# langchain-chain-of-verification
Based off CoVe CLI at https://github.com/ritun16/chain-of-verification , packaged (with `uv`) and updated for newer langchain versions for easier consumption.
`langchain-chain-of-verification` Can be used as CLI or library.
CoVe: https://arxiv.org/pdf/2309.11495
Enhanced by DuckDuckGo search (by ritun16)
- [langchain-chain-of-verification](#langchain-chain-of-verification)
- [Usage](#usage)
- [CLI](#cli)
- [Library](#library)
- [Examples](#examples)
- [Installation](#installation)
- [pipx](#pipx)
- [pip](#pip)
- [Screenshots](#screenshots)
- [LangSmith](#langsmith)
## Usage
### CLI
```plain
# uvx --from langchain-chain-of-verification cove --help
$ cove --help
usage: cove [-h] --question QUESTION [--llm-name LLM_NAME] [--temperature TEMPERATURE] [--max-tokens MAX_TOKENS] [--show-intermediate-steps SHOW_INTERMEDIATE_STEPS]
Chain of Verification (CoVE) parser.
options:
-h, --help show this help message and exit
--question QUESTION The original question user wants to ask
--llm-name LLM_NAME The openai llm name
--temperature TEMPERATURE
The temperature of the llm
--max-tokens MAX_TOKENS
The max_tokens of the llm
--show-intermediate-steps SHOW_INTERMEDIATE_STEPS
The max_tokens of the llm
```
### Library
```python
from langchain_chain_of_verification import create_cove_chain
def create_cove_chain(
original_query: str,
llm_name="gpt-4o",
temperature=0.1,
router_max_tokens=500,
show_intermediate_steps=True,
) -> dict:
"""
Creates a Chain of Verification (CoVE) using specified language models.
Args:
original_query (str): The original question to be processed.
llm_name (str, optional): The name of the language model to use. Defaults to "gpt-4o".
temperature (float, optional): The temperature setting for the language model. Defaults to 0.1.
router_max_tokens (int, optional): The maximum number of tokens for the language model. Defaults to 500.
show_intermediate_steps (bool, optional): Whether to show intermediate steps. Defaults to True.
Returns:
dict: The result (final answer) of the CoVE chain processing. See the example below, the dict between '###'s.
Example:
>>> result = create_cove_chain("What is the capital of France?")
>>> print(result)
"""
...
```
## Examples
```plain
cove --question 'name athletes born in raleigh'
Chain selected: WIKI_CHAIN
################################################################################
{'baseline_response': '1. Chasity Melvin\n'
'2. Ryan Jeffers\n'
"3. Devonte' Graham\n"
'4. Trea Turner',
'final_answer': 'Based on the verification questions and answers, the refined '
'answer should only include athletes who were confirmed to be '
'born in Raleigh. Therefore, the final refined answer is:\n'
'\n'
'1. Ryan Jeffers\n'
"2. Devonte' Graham",
'original_question': 'name athletes born in raleigh',
'verification_answers': 'Question: 1. Was Chasity Melvin born in Raleigh? '
'Answer: No, Chasity Melvin was not born in Raleigh. '
'She was born in Roseboro, North Carolina.\n'
'Question: 2. Was Ryan Jeffers born in Raleigh? '
'Answer: Yes, Ryan Jeffers was born in Raleigh, North '
'Carolina.\n'
"Question: 3. Was Devonte' Graham born in Raleigh? "
"Answer: Yes, Devonte' Graham was born in Raleigh, "
'North Carolina.\n'
'Question: 4. Was Trea Turner born in Raleigh? '
'Answer: No, Trea Turner was not born in Raleigh. '
'According to the provided context, Trea Turner was '
'born on June 30, 1993, in Boynton Beach, Florida.\n',
'verification_question_template': 'Was [athlete] born in [Raleigh]?',
'verification_questions': '1. Was Chasity Melvin born in Raleigh?\n'
'2. Was Ryan Jeffers born in Raleigh?\n'
"3. Was Devonte' Graham born in Raleigh?\n"
'4. Was Trea Turner born in Raleigh?'}
################################################################################
Final Answer: Based on the verification questions and answers, the refined answer should only include athletes who were confirmed to be born in Raleigh. Therefore, the final refined answer is:
1. Ryan Jeffers
2. Devonte' Graham
```
## Installation
To run without installing with `uv`, try `uvx --from langchain-chain-of-verification cove --help`.
### pipx
This is the recommended installation method.
```
$ pipx install langchain-chain-of-verification
```
### [pip](https://pypi.org/project/langchain-chain-of-verification/)
```
$ pip install langchain-chain-of-verification
```
## Screenshots
### LangSmith
<figure>
<img src="https://github.com/user-attachments/assets/39326eb4-b5bc-4fbb-b035-2e330b06cbf0" alt="">
<figcaption>See the example above</figcaption>
</figure>
Raw data
{
"_id": null,
"home_page": null,
"name": "langchain-chain-of-verification",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "cli, langchain, prompt-engineering",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/19/34/683eab77fb39f834270d6366ca2d7e3726e4f09cf2eb2ed5a0d50b3a0d70/langchain_chain_of_verification-0.1.11.tar.gz",
"platform": null,
"description": "# langchain-chain-of-verification \n\nBased off CoVe CLI at https://github.com/ritun16/chain-of-verification , packaged (with `uv`) and updated for newer langchain versions for easier consumption.\n\n`langchain-chain-of-verification` Can be used as CLI or library.\n\nCoVe: https://arxiv.org/pdf/2309.11495\n\nEnhanced by DuckDuckGo search (by ritun16)\n\n- [langchain-chain-of-verification](#langchain-chain-of-verification)\n - [Usage](#usage)\n - [CLI](#cli)\n - [Library](#library)\n - [Examples](#examples)\n - [Installation](#installation)\n - [pipx](#pipx)\n - [pip](#pip)\n - [Screenshots](#screenshots)\n - [LangSmith](#langsmith)\n\n## Usage\n\n\n### CLI\n\n```plain\n# uvx --from langchain-chain-of-verification cove --help\n$ cove --help\n\nusage: cove [-h] --question QUESTION [--llm-name LLM_NAME] [--temperature TEMPERATURE] [--max-tokens MAX_TOKENS] [--show-intermediate-steps SHOW_INTERMEDIATE_STEPS]\n\nChain of Verification (CoVE) parser.\n\noptions:\n -h, --help show this help message and exit\n --question QUESTION The original question user wants to ask\n --llm-name LLM_NAME The openai llm name\n --temperature TEMPERATURE\n The temperature of the llm\n --max-tokens MAX_TOKENS\n The max_tokens of the llm\n --show-intermediate-steps SHOW_INTERMEDIATE_STEPS\n The max_tokens of the llm\n```\n\n### Library\n\n```python\nfrom langchain_chain_of_verification import create_cove_chain\n\ndef create_cove_chain(\n original_query: str,\n llm_name=\"gpt-4o\",\n temperature=0.1,\n router_max_tokens=500,\n show_intermediate_steps=True,\n) -> dict:\n \"\"\"\n Creates a Chain of Verification (CoVE) using specified language models.\n\n Args:\n original_query (str): The original question to be processed.\n llm_name (str, optional): The name of the language model to use. Defaults to \"gpt-4o\".\n temperature (float, optional): The temperature setting for the language model. Defaults to 0.1.\n router_max_tokens (int, optional): The maximum number of tokens for the language model. Defaults to 500.\n show_intermediate_steps (bool, optional): Whether to show intermediate steps. Defaults to True.\n\n Returns:\n dict: The result (final answer) of the CoVE chain processing. See the example below, the dict between '###'s.\n\n Example:\n >>> result = create_cove_chain(\"What is the capital of France?\")\n >>> print(result)\n \"\"\"\n ...\n```\n\n## Examples\n\n```plain\ncove --question 'name athletes born in raleigh'\nChain selected: WIKI_CHAIN\n\n################################################################################\n\n{'baseline_response': '1. Chasity Melvin\\n'\n '2. Ryan Jeffers\\n'\n \"3. Devonte' Graham\\n\"\n '4. Trea Turner',\n 'final_answer': 'Based on the verification questions and answers, the refined '\n 'answer should only include athletes who were confirmed to be '\n 'born in Raleigh. Therefore, the final refined answer is:\\n'\n '\\n'\n '1. Ryan Jeffers\\n'\n \"2. Devonte' Graham\",\n 'original_question': 'name athletes born in raleigh',\n 'verification_answers': 'Question: 1. Was Chasity Melvin born in Raleigh? '\n 'Answer: No, Chasity Melvin was not born in Raleigh. '\n 'She was born in Roseboro, North Carolina.\\n'\n 'Question: 2. Was Ryan Jeffers born in Raleigh? '\n 'Answer: Yes, Ryan Jeffers was born in Raleigh, North '\n 'Carolina.\\n'\n \"Question: 3. Was Devonte' Graham born in Raleigh? \"\n \"Answer: Yes, Devonte' Graham was born in Raleigh, \"\n 'North Carolina.\\n'\n 'Question: 4. Was Trea Turner born in Raleigh? '\n 'Answer: No, Trea Turner was not born in Raleigh. '\n 'According to the provided context, Trea Turner was '\n 'born on June 30, 1993, in Boynton Beach, Florida.\\n',\n 'verification_question_template': 'Was [athlete] born in [Raleigh]?',\n 'verification_questions': '1. Was Chasity Melvin born in Raleigh?\\n'\n '2. Was Ryan Jeffers born in Raleigh?\\n'\n \"3. Was Devonte' Graham born in Raleigh?\\n\"\n '4. Was Trea Turner born in Raleigh?'}\n\n################################################################################\n\nFinal Answer: Based on the verification questions and answers, the refined answer should only include athletes who were confirmed to be born in Raleigh. Therefore, the final refined answer is:\n\n1. Ryan Jeffers\n2. Devonte' Graham\n```\n\n## Installation\n\nTo run without installing with `uv`, try `uvx --from langchain-chain-of-verification cove --help`.\n\n### pipx\n\nThis is the recommended installation method.\n\n```\n$ pipx install langchain-chain-of-verification\n```\n\n### [pip](https://pypi.org/project/langchain-chain-of-verification/)\n\n```\n$ pip install langchain-chain-of-verification\n```\n\n## Screenshots\n\n### LangSmith\n\n<figure>\n <img src=\"https://github.com/user-attachments/assets/39326eb4-b5bc-4fbb-b035-2e330b06cbf0\" alt=\"\">\n <figcaption>See the example above</figcaption>\n</figure>",
"bugtrack_url": null,
"license": null,
"summary": "Add your description here",
"version": "0.1.11",
"project_urls": null,
"split_keywords": [
"cli",
" langchain",
" prompt-engineering"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "65ea9eeb4037b37803a9b2d09dedd0b1e49d62dd1bae00ed0c9a08646edaeca5",
"md5": "1cb39129a8020ac71adcdd5a7b171911",
"sha256": "eb875d286999873f9f7d2750c220e433579b6a1052199af942dc6923eaf7a1e9"
},
"downloads": -1,
"filename": "langchain_chain_of_verification-0.1.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1cb39129a8020ac71adcdd5a7b171911",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 11610,
"upload_time": "2024-09-24T19:04:53",
"upload_time_iso_8601": "2024-09-24T19:04:53.372810Z",
"url": "https://files.pythonhosted.org/packages/65/ea/9eeb4037b37803a9b2d09dedd0b1e49d62dd1bae00ed0c9a08646edaeca5/langchain_chain_of_verification-0.1.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1934683eab77fb39f834270d6366ca2d7e3726e4f09cf2eb2ed5a0d50b3a0d70",
"md5": "d82ece4334b40ee54497e50e0fc38a56",
"sha256": "e45e788c58c4a30326b6686a7f8632a946dc0dd8f5ebde593d93a8a661e95ac8"
},
"downloads": -1,
"filename": "langchain_chain_of_verification-0.1.11.tar.gz",
"has_sig": false,
"md5_digest": "d82ece4334b40ee54497e50e0fc38a56",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 70460,
"upload_time": "2024-09-24T19:04:56",
"upload_time_iso_8601": "2024-09-24T19:04:56.319377Z",
"url": "https://files.pythonhosted.org/packages/19/34/683eab77fb39f834270d6366ca2d7e3726e4f09cf2eb2ed5a0d50b3a0d70/langchain_chain_of_verification-0.1.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-24 19:04:56",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "langchain-chain-of-verification"
}