mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-08 14:31:55 +00:00
community[patch]: OllamaEmbeddings - Pass headers to post request (#16880)
## Feature - Set additional headers in constructor - Headers will be sent in post request This feature is useful if deploying Ollama on a cloud service such as hugging face, which requires authentication tokens to be passed in the request header. ## Tests - Test if header is passed - Test if header is not passed Similar to https://github.com/langchain-ai/langchain/pull/15881 --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
@@ -105,6 +105,12 @@ class OllamaEmbeddings(BaseModel, Embeddings):
|
||||
show_progress: bool = False
|
||||
"""Whether to show a tqdm progress bar. Must have `tqdm` installed."""
|
||||
|
||||
headers: Optional[dict] = None
|
||||
"""Additional headers to pass to endpoint (e.g. Authorization, Referer).
|
||||
This is useful when Ollama is hosted on cloud services that require
|
||||
tokens for authentication.
|
||||
"""
|
||||
|
||||
@property
|
||||
def _default_params(self) -> Dict[str, Any]:
|
||||
"""Get the default parameters for calling Ollama."""
|
||||
@@ -151,6 +157,7 @@ class OllamaEmbeddings(BaseModel, Embeddings):
|
||||
"""
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
**(self.headers or {}),
|
||||
}
|
||||
|
||||
try:
|
||||
|
Reference in New Issue
Block a user