Skip to content

Commit

Permalink
Expose httpx auth kwargs to RemoteRunnable to support most authentica…
Browse files Browse the repository at this point in the history
…tion methods.
  • Loading branch information
kreneskyp committed Oct 16, 2023
1 parent 3819dfb commit 69342ab
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions langserve/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from urllib.parse import urljoin

import httpx
from httpx._types import CertTypes, CookieTypes, HeaderTypes, VerifyTypes, AuthTypes

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,42 @@ 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,
) -> 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
"""
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,
)
self.async_client = httpx.AsyncClient(
base_url=url,
timeout=timeout,
auth=auth,
headers=headers,
cookies=cookies,
verify=verify,
cert=cert
)

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

0 comments on commit 69342ab

Please sign in to comment.