Skip to content
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

Deprecate direct access to globals like debug and verbose. #11311

Merged
merged 29 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6a928c4
Move globals like `debug` and `verbose` to their own module.
obi1kenobi Oct 2, 2023
eaacf21
Fix lint.
obi1kenobi Oct 2, 2023
0769605
Fix function name.
obi1kenobi Oct 2, 2023
c45c367
Delint.
obi1kenobi Oct 2, 2023
30d8b4f
Delint, take two.
obi1kenobi Oct 2, 2023
f266fba
Workaround for duplicated attributes depending on how they are imported.
obi1kenobi Oct 2, 2023
bbb9987
Merge branch 'master' into pg/move_globals_to_own_module
obi1kenobi Oct 2, 2023
e4e3371
Update state-resetting code.
obi1kenobi Oct 2, 2023
c238b02
Delint.
obi1kenobi Oct 2, 2023
30f8dbc
Add warnings to the repo.
obi1kenobi Oct 2, 2023
d0a28ab
Merge branch 'master' into pg/move_globals_to_own_module
obi1kenobi Oct 3, 2023
7ed2616
Merge branch 'master' into pg/move_globals_to_own_module
obi1kenobi Oct 4, 2023
8154f48
Add explicit `get_<X>()` functions.
obi1kenobi Oct 9, 2023
454c0c8
Update docs to point to new locations.
obi1kenobi Oct 9, 2023
c7b5abf
Remove type hints since type checkers seem to read `__getattr__()`.
obi1kenobi Oct 9, 2023
39baef0
Remove unused imports.
obi1kenobi Oct 9, 2023
6888c55
Import the underscored values in the top level `__init__`.
obi1kenobi Oct 9, 2023
0fbda65
Do not report warnings when using deprecated code internally.
obi1kenobi Oct 9, 2023
4596710
Move `globals` to be a top-level `langchain` namespace.
obi1kenobi Oct 9, 2023
97e398e
Fix test imports.
obi1kenobi Oct 9, 2023
1af7da5
Fix type hint.
obi1kenobi Oct 9, 2023
ef840a1
Use underscored underlying values in tests.
obi1kenobi Oct 9, 2023
41f2e31
Ruff lint.
obi1kenobi Oct 9, 2023
a6260b7
Fix type hint.
obi1kenobi Oct 9, 2023
42c8a9f
Merge branch 'master' into pg/move_globals_to_own_module
hwchase17 Oct 11, 2023
0c55aa1
Merge branch 'pg/move_globals_to_own_module' of github.com:hwchase17/…
hwchase17 Oct 11, 2023
5560519
cr
hwchase17 Oct 11, 2023
c0562d4
cr
hwchase17 Oct 12, 2023
c780715
Merge branch 'master' into pg/move_globals_to_own_module
hwchase17 Oct 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cookbook/forward_looking_retrieval_augmented_generation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@
"outputs": [],
"source": [
"# We set this so we can see what exactly is going on\n",
"import langchain\n",
"from langchain.globals import set_verbose\n",
"\n",
"langchain.verbose = True"
"set_verbose(True)"
]
},
{
Expand Down Expand Up @@ -489,7 +489,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
13 changes: 7 additions & 6 deletions cookbook/learned_prompt_optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
"\n",
"The way the chain is learning that Tom prefers veggetarian meals is via an AutoSelectionScorer that is built into the chain. The scorer will call the LLM again and ask it to evaluate the selection (`ToSelectFrom`) using the information wrapped in (`BasedOn`).\n",
"\n",
"You can set `langchain.debug=True` if you want to see the details of the auto-scorer, but you can also define the scoring prompt yourself."
"You can set `set_debug(True)` if you want to see the details of the auto-scorer, but you can also define the scoring prompt yourself."
]
},
{
Expand Down Expand Up @@ -778,8 +778,9 @@
],
"source": [
"from langchain.prompts.prompt import PromptTemplate\n",
"import langchain\n",
"langchain.debug = True\n",
"from langchain.globals import set_debug\n",
"\n",
"set_debug(True)\n",
"\n",
"REWARD_PROMPT_TEMPLATE = \"\"\"\n",
"\n",
Expand Down Expand Up @@ -812,9 +813,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "poetry-venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "poetry-venv"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -826,7 +827,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
14 changes: 7 additions & 7 deletions docs/docs/guides/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ For anyone building production-grade LLM applications, we highly recommend using

![LangSmith run](/img/run_details.png)

## `langchain.debug` and `langchain.verbose`
## `set_debug` and `set_verbose`

If you're prototyping in Jupyter Notebooks or running Python scripts, it can be helpful to print out the intermediate steps of a Chain run.

Expand Down Expand Up @@ -45,15 +45,15 @@ agent.run("Who directed the 2023 film Oppenheimer and what is their age? What is

</CodeOutputBlock>

### `langchain.debug = True`
### `set_debug(True)`

Setting the global `debug` flag will cause all LangChain components with callback support (chains, models, agents, tools, retrievers) to print the inputs they receive and outputs they generate. This is the most verbose setting and will fully log raw inputs and outputs.


```python
import langchain
from langchain.globals import set_debug

langchain.debug = True
set_debug(True)

agent.run("Who directed the 2023 film Oppenheimer and what is their age? What is their age in days (assume 365 days per year)?")
```
Expand Down Expand Up @@ -376,15 +376,15 @@ agent.run("Who directed the 2023 film Oppenheimer and what is their age? What is

</details>

### `langchain.verbose = True`
### `set_vebose(True)`

Setting the `verbose` flag will print out inputs and outputs in a slightly more readable format and will skip logging certain raw outputs (like the token usage stats for an LLM call) so that you can focus on application logic.


```python
import langchain
from langchain.globals import set_verbose

langchain.verbose = True
set_verbose(True)

agent.run("Who directed the 2023 film Oppenheimer and what is their age? What is their age in days (assume 365 days per year)?")
```
Expand Down
18 changes: 11 additions & 7 deletions docs/docs/integrations/llms/bittensor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
"metadata": {},
"outputs": [],
"source": [
"import langchain\n",
"from langchain.llms import NIBittensorLLM\n",
"import json\n",
"from pprint import pprint\n",
"\n",
"langchain.debug = True\n",
"from langchain.globals import set_debug\n",
"\n",
"set_debug(True)\n",
"\n",
"# System parameter in NIBittensorLLM is optional but you can set whatever you want to perform with model\n",
"llm_sys = NIBittensorLLM(\n",
Expand Down Expand Up @@ -79,11 +80,13 @@
"metadata": {},
"outputs": [],
"source": [
"import langchain\n",
"from langchain.prompts import PromptTemplate\nfrom langchain.chains import LLMChain\n",
"from langchain.prompts import PromptTemplate\n",
"from langchain.chains import LLMChain\n",
"from langchain.llms import NIBittensorLLM\n",
"\n",
"langchain.debug = True\n",
"from langchain.globals import set_debug\n",
"\n",
"set_debug(True)\n",
"\n",
"template = \"\"\"Question: {question}\n",
"\n",
Expand Down Expand Up @@ -123,7 +126,8 @@
" AgentExecutor,\n",
")\n",
"from langchain.memory import ConversationBufferMemory\n",
"from langchain.chains import LLMChain\nfrom langchain.prompts import PromptTemplate\n",
"from langchain.chains import LLMChain\n",
"from langchain.prompts import PromptTemplate\n",
"from langchain.utilities import GoogleSearchAPIWrapper, SerpAPIWrapper\n",
"from langchain.llms import NIBittensorLLM\n",
"\n",
Expand Down Expand Up @@ -174,7 +178,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.1"
}
},
"nbformat": 4,
Expand Down
Loading