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

Add auth options for RemoteRunnable #46

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Changes from all commits
Commits
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
38 changes: 36 additions & 2 deletions langserve/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import (
Any,
AsyncIterator,
Dict,
Iterator,
List,
Optional,
Expand All @@ -15,6 +16,7 @@
from urllib.parse import urljoin

import httpx
from httpx._types import AuthTypes, CertTypes, CookieTypes, HeaderTypes, VerifyTypes
from langchain.callbacks.tracers.log_stream import RunLog, RunLogPatch
from langchain.load.dump import dumpd
from langchain.schema.runnable import Runnable
Expand Down Expand Up @@ -110,16 +112,48 @@ def __init__(
url: str,
*,
timeout: Optional[float] = None,
auth: Optional[AuthTypes] = None,
headers: Optional[HeaderTypes] = None,
cookies: Optional[CookieTypes] = None,
verify: VerifyTypes = True,
cert: Optional[CertTypes] = None,
client_kwargs: Optional[Dict[str, Any]] = None,
) -> None:
"""Initialize the client.

Args:
url: The url of the server
timeout: The timeout for requests
auth: Authentication class for requests
headers: Headers to send with requests
cookies: Cookies to send with requests
verify: Whether to verify SSL certificates
cert: SSL certificate to use for requests
client_kwargs: If provided will be unpacked as kwargs to both the sync
and async httpx clients
"""
_client_kwargs = client_kwargs or {}
self.url = url
self.sync_client = httpx.Client(base_url=url, timeout=timeout)
self.async_client = httpx.AsyncClient(base_url=url, timeout=timeout)
self.sync_client = httpx.Client(
base_url=url,
timeout=timeout,
auth=auth,
headers=headers,
cookies=cookies,
verify=verify,
cert=cert,
**_client_kwargs,
)
self.async_client = httpx.AsyncClient(
base_url=url,
timeout=timeout,
auth=auth,
headers=headers,
cookies=cookies,
verify=verify,
cert=cert,
**_client_kwargs,
)

# Register cleanup handler once RemoteRunnable is garbage collected
weakref.finalize(self, _close_clients, self.sync_client, self.async_client)
Expand Down