Skip to content

Commit 8865481

Browse files
Merge branch 'master' into feat/anthropic_max_tokens
2 parents 59d429a + ba83f58 commit 8865481

File tree

5 files changed

+208
-77
lines changed

5 files changed

+208
-77
lines changed

docs/docs/contributing/how_to/code/setup.mdx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ This project utilizes [uv](https://docs.astral.sh/uv/) v0.5+ as a dependency man
99

1010
Install `uv`: **[documentation on how to install it](https://docs.astral.sh/uv/getting-started/installation/)**.
1111

12+
### Windows Users
13+
14+
If you're on Windows and don't have `make` installed, you can install it via:
15+
- **Option 1**: Install via [Chocolatey](https://chocolatey.org/): `choco install make`
16+
- **Option 2**: Install via [Scoop](https://scoop.sh/): `scoop install make`
17+
- **Option 3**: Use [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/)
18+
- **Option 4**: Use the direct `uv` commands shown in the sections below
19+
1220
## Different packages
1321

1422
This repository contains multiple packages:
@@ -48,7 +56,11 @@ uv sync
4856
Then verify dependency installation:
4957

5058
```bash
59+
# If you have `make` installed:
5160
make test
61+
62+
# If you don't have `make` (Windows alternative):
63+
uv run --group test pytest -n auto --disable-socket --allow-unix-socket tests/unit_tests
5264
```
5365

5466
## Testing
@@ -61,7 +73,11 @@ If you add new logic, please add a unit test.
6173
To run unit tests:
6274

6375
```bash
76+
# If you have `make` installed:
6477
make test
78+
79+
# If you don't have make (Windows alternative):
80+
uv run --group test pytest -n auto --disable-socket --allow-unix-socket tests/unit_tests
6581
```
6682

6783
There are also [integration tests and code-coverage](../testing.mdx) available.
@@ -72,7 +88,12 @@ If you are only developing `langchain_core`, you can simply install the dependen
7288

7389
```bash
7490
cd libs/core
91+
92+
# If you have `make` installed:
7593
make test
94+
95+
# If you don't have `make` (Windows alternative):
96+
uv run --group test pytest -n auto --disable-socket --allow-unix-socket tests/unit_tests
7697
```
7798

7899
## Formatting and linting
@@ -86,20 +107,37 @@ Formatting for this project is done via [ruff](https://docs.astral.sh/ruff/rules
86107
To run formatting for docs, cookbook and templates:
87108

88109
```bash
110+
# If you have `make` installed:
89111
make format
112+
113+
# If you don't have make (Windows alternative):
114+
uv run --all-groups ruff format .
115+
uv run --all-groups ruff check --fix .
90116
```
91117

92118
To run formatting for a library, run the same command from the relevant library directory:
93119

94120
```bash
95121
cd libs/{LIBRARY}
122+
123+
# If you have `make` installed:
96124
make format
125+
126+
# If you don't have make (Windows alternative):
127+
uv run --all-groups ruff format .
128+
uv run --all-groups ruff check --fix .
97129
```
98130

99131
Additionally, you can run the formatter only on the files that have been modified in your current branch as compared to the master branch using the format_diff command:
100132

101133
```bash
134+
# If you have `make` installed:
102135
make format_diff
136+
137+
# If you don't have `make` (Windows alternative):
138+
# First, get the list of modified files:
139+
git diff --relative=libs/langchain --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$' | xargs uv run --all-groups ruff format
140+
git diff --relative=libs/langchain --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$' | xargs uv run --all-groups ruff check --fix
103141
```
104142

105143
This is especially useful when you have made changes to a subset of the project and want to ensure your changes are properly formatted without affecting the rest of the codebase.
@@ -111,20 +149,40 @@ Linting for this project is done via a combination of [ruff](https://docs.astral
111149
To run linting for docs, cookbook and templates:
112150

113151
```bash
152+
# If you have `make` installed:
114153
make lint
154+
155+
# If you don't have `make` (Windows alternative):
156+
uv run --all-groups ruff check .
157+
uv run --all-groups ruff format . --diff
158+
uv run --all-groups mypy . --cache-dir .mypy_cache
115159
```
116160

117161
To run linting for a library, run the same command from the relevant library directory:
118162

119163
```bash
120164
cd libs/{LIBRARY}
165+
166+
# If you have `make` installed:
121167
make lint
168+
169+
# If you don't have `make` (Windows alternative):
170+
uv run --all-groups ruff check .
171+
uv run --all-groups ruff format . --diff
172+
uv run --all-groups mypy . --cache-dir .mypy_cache
122173
```
123174

124175
In addition, you can run the linter only on the files that have been modified in your current branch as compared to the master branch using the lint_diff command:
125176

126177
```bash
178+
# If you have `make` installed:
127179
make lint_diff
180+
181+
# If you don't have `make` (Windows alternative):
182+
# First, get the list of modified files:
183+
git diff --relative=libs/langchain --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$' | xargs uv run --all-groups ruff check
184+
git diff --relative=libs/langchain --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$' | xargs uv run --all-groups ruff format --diff
185+
git diff --relative=libs/langchain --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$' | xargs uv run --all-groups mypy --cache-dir .mypy_cache
128186
```
129187

130188
This can be very helpful when you've made changes to only certain parts of the project and want to ensure your changes meet the linting standards without having to check the entire codebase.
@@ -139,13 +197,21 @@ Note that `codespell` finds common typos, so it could have false-positive (corre
139197
To check spelling for this project:
140198

141199
```bash
200+
# If you have `make` installed:
142201
make spell_check
202+
203+
# If you don't have `make` (Windows alternative):
204+
uv run --all-groups codespell --toml pyproject.toml
143205
```
144206

145207
To fix spelling in place:
146208

147209
```bash
210+
# If you have `make` installed:
148211
make spell_fix
212+
213+
# If you don't have `make` (Windows alternative):
214+
uv run --all-groups codespell --toml pyproject.toml -w
149215
```
150216

151217
If codespell is incorrectly flagging a word, you can skip spellcheck for that word by adding it to the codespell config in the `pyproject.toml` file.

libs/partners/groq/langchain_groq/chat_models.py

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@
66
import warnings
77
from collections.abc import AsyncIterator, Iterator, Mapping, Sequence
88
from operator import itemgetter
9-
from typing import (
10-
Any,
11-
Callable,
12-
Literal,
13-
Optional,
14-
TypedDict,
15-
Union,
16-
cast,
17-
)
9+
from typing import Any, Callable, Literal, Optional, TypedDict, Union, cast
1810

1911
from langchain_core._api import deprecated
2012
from langchain_core.callbacks import (
@@ -46,10 +38,7 @@
4638
ToolMessage,
4739
ToolMessageChunk,
4840
)
49-
from langchain_core.output_parsers import (
50-
JsonOutputParser,
51-
PydanticOutputParser,
52-
)
41+
from langchain_core.output_parsers import JsonOutputParser, PydanticOutputParser
5342
from langchain_core.output_parsers.base import OutputParserLike
5443
from langchain_core.output_parsers.openai_tools import (
5544
JsonOutputKeyToolsParser,
@@ -60,23 +49,13 @@
6049
from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult
6150
from langchain_core.runnables import Runnable, RunnableMap, RunnablePassthrough
6251
from langchain_core.tools import BaseTool
63-
from langchain_core.utils import (
64-
from_env,
65-
get_pydantic_field_names,
66-
secret_from_env,
67-
)
52+
from langchain_core.utils import from_env, get_pydantic_field_names, secret_from_env
6853
from langchain_core.utils.function_calling import (
6954
convert_to_openai_function,
7055
convert_to_openai_tool,
7156
)
7257
from langchain_core.utils.pydantic import is_basemodel_subclass
73-
from pydantic import (
74-
BaseModel,
75-
ConfigDict,
76-
Field,
77-
SecretStr,
78-
model_validator,
79-
)
58+
from pydantic import BaseModel, ConfigDict, Field, SecretStr, model_validator
8059
from typing_extensions import Self
8160

8261
from langchain_groq.version import __version__
@@ -122,7 +101,7 @@ class ChatGroq(BaseChatModel):
122101
123102
See the `Groq documentation
124103
<https://console.groq.com/docs/reasoning#reasoning>`__ for more
125-
details and a list of supported reasoning models.
104+
details and a list of supported models.
126105
model_kwargs: Dict[str, Any]
127106
Holds any model parameters valid for create call not
128107
explicitly specified.
@@ -328,20 +307,15 @@ class Joke(BaseModel):
328307
overridden in ``reasoning_effort``.
329308
330309
See the `Groq documentation <https://console.groq.com/docs/reasoning#reasoning>`__
331-
for more details and a list of supported reasoning models.
310+
for more details and a list of supported models.
332311
"""
333-
reasoning_effort: Optional[Literal["none", "default"]] = Field(default=None)
312+
reasoning_effort: Optional[str] = Field(default=None)
334313
"""The level of effort the model will put into reasoning. Groq will default to
335-
enabling reasoning if left undefined. If set to ``none``, ``reasoning_format`` will
336-
not apply and ``reasoning_content`` will not be returned.
337-
338-
- ``'none'``: Disable reasoning. The model will not use any reasoning tokens when
339-
generating a response.
340-
- ``'default'``: Enable reasoning.
314+
enabling reasoning if left undefined.
341315
342316
See the `Groq documentation
343317
<https://console.groq.com/docs/reasoning#options-for-reasoning-effort>`__ for more
344-
details and a list of models that support setting a reasoning effort.
318+
details and a list of options and models that support setting a reasoning effort.
345319
"""
346320
model_kwargs: dict[str, Any] = Field(default_factory=dict)
347321
"""Holds any model parameters valid for `create` call not explicitly specified."""
@@ -601,6 +575,11 @@ def _stream(
601575
generation_info["system_fingerprint"] = system_fingerprint
602576
service_tier = params.get("service_tier") or self.service_tier
603577
generation_info["service_tier"] = service_tier
578+
reasoning_effort = (
579+
params.get("reasoning_effort") or self.reasoning_effort
580+
)
581+
if reasoning_effort:
582+
generation_info["reasoning_effort"] = reasoning_effort
604583
logprobs = choice.get("logprobs")
605584
if logprobs:
606585
generation_info["logprobs"] = logprobs
@@ -644,6 +623,11 @@ async def _astream(
644623
generation_info["system_fingerprint"] = system_fingerprint
645624
service_tier = params.get("service_tier") or self.service_tier
646625
generation_info["service_tier"] = service_tier
626+
reasoning_effort = (
627+
params.get("reasoning_effort") or self.reasoning_effort
628+
)
629+
if reasoning_effort:
630+
generation_info["reasoning_effort"] = reasoning_effort
647631
logprobs = choice.get("logprobs")
648632
if logprobs:
649633
generation_info["logprobs"] = logprobs
@@ -714,6 +698,9 @@ def _create_chat_result(
714698
"system_fingerprint": response.get("system_fingerprint", ""),
715699
}
716700
llm_output["service_tier"] = params.get("service_tier") or self.service_tier
701+
reasoning_effort = params.get("reasoning_effort") or self.reasoning_effort
702+
if reasoning_effort:
703+
llm_output["reasoning_effort"] = reasoning_effort
717704
return ChatResult(generations=generations, llm_output=llm_output)
718705

719706
def _create_message_dicts(

libs/partners/groq/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ build-backend = "pdm.backend"
66
authors = []
77
license = { text = "MIT" }
88
requires-python = ">=3.9"
9-
dependencies = ["langchain-core<1.0.0,>=0.3.68", "groq<1,>=0.29.0"]
9+
dependencies = ["langchain-core<1.0.0,>=0.3.72", "groq<1,>=0.30.0"]
1010
name = "langchain-groq"
11-
version = "0.3.6"
11+
version = "0.3.7"
1212
description = "An integration package connecting Groq and LangChain"
1313
readme = "README.md"
1414

@@ -114,4 +114,4 @@ asyncio_mode = "auto"
114114
"tests/**/*.py" = [
115115
"S101", # Tests need assertions
116116
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
117-
]
117+
]

0 commit comments

Comments
 (0)