Skip to content

Commit

Permalink
groq: user agent (#29079)
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis authored Jan 7, 2025
1 parent c5bee0a commit 539ebd5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
6 changes: 5 additions & 1 deletion libs/partners/groq/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ all: help
TEST_FILE ?= tests/unit_tests/

integration_test integration_tests: TEST_FILE=tests/integration_tests/
test tests integration_test integration_tests:

test tests:
poetry run pytest --disable-socket --allow-unix-socket $(TEST_FILE)

integration_test integration_tests:
poetry run pytest $(TEST_FILE)

test_watch:
Expand Down
3 changes: 2 additions & 1 deletion libs/partners/groq/langchain_groq/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from langchain_groq.chat_models import ChatGroq
from langchain_groq.version import __version__

__all__ = ["ChatGroq"]
__all__ = ["ChatGroq", "__version__"]
8 changes: 7 additions & 1 deletion libs/partners/groq/langchain_groq/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
)
from typing_extensions import Self

from langchain_groq.version import __version__


class ChatGroq(BaseChatModel):
"""`Groq` Chat large language models API.
Expand Down Expand Up @@ -386,14 +388,18 @@ def validate_environment(self) -> Self:
if self.temperature == 0:
self.temperature = 1e-8

default_headers = {"User-Agent": f"langchain/{__version__}"} | dict(
self.default_headers or {}
)

client_params: Dict[str, Any] = {
"api_key": (
self.groq_api_key.get_secret_value() if self.groq_api_key else None
),
"base_url": self.groq_api_base,
"timeout": self.request_timeout,
"max_retries": self.max_retries,
"default_headers": self.default_headers,
"default_headers": default_headers,
"default_query": self.default_query,
}

Expand Down
9 changes: 9 additions & 0 deletions libs/partners/groq/langchain_groq/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Main entrypoint into package."""

from importlib import metadata

try:
__version__ = metadata.version(__package__)
except metadata.PackageNotFoundError:
# Case where package metadata is not available.
__version__ = ""
2 changes: 1 addition & 1 deletion libs/partners/groq/tests/unit_tests/test_imports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from langchain_groq import __all__

EXPECTED_ALL = ["ChatGroq"]
EXPECTED_ALL = ["ChatGroq", "__version__"]


def test_all_imports() -> None:
Expand Down

0 comments on commit 539ebd5

Please sign in to comment.