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

community[minor]: passthrough auth parameter on requests to Ollama-LLMs #24068

Merged
merged 15 commits into from
Jul 25, 2024

Conversation

rick-soptim
Copy link
Contributor

Thank you for contributing to LangChain!

Description:
This PR allows users of langchain_community.llms.ollama.Ollama to specify the auth parameter, which is then forwarded to all internal calls of requests.request. This works in the same way as the existing headers parameters. The auth parameter enables the usage of the given class with Ollama instances, which are secured by more complex authentication mechanisms, that do not only rely on static headers. An example are AWS API Gateways secured by the IAM authorizer, which expects signatures dynamically calculated on the specific HTTP request.

Issue:

Integrating a remote LLM running through Ollama using langchain_community.llms.ollama.Ollama only allows setting static HTTP headers with the parameter headers. This does not work, if the given instance of Ollama is secured with an authentication mechanism that makes use of dynamically created HTTP headers which for example may depend on the content of a given request.

Dependencies:

None

Twitter handle:

None

Copy link

vercel bot commented Jul 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2024 8:46am

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. community Related to langchain-community 🤖:improvement Medium size change to existing code to handle new use-cases labels Jul 10, 2024
@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Jul 11, 2024
Copy link
Collaborator

@eyurtsev eyurtsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a suggestion in case unit tests fail

@@ -130,6 +130,10 @@ class _OllamaCommon(BaseLanguageModel):
tokens for authentication.
"""

auth: Callable | tuple | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll need to import

from __future__ import annotations

@@ -1,5 +1,5 @@
import json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import json
from __future__ import annotations
import json

@eyurtsev eyurtsev self-assigned this Jul 11, 2024
@eyurtsev eyurtsev changed the title community: passthrough auth parameter on requests to Ollama-LLMs community[minor]: passthrough auth parameter on requests to Ollama-LLMs Jul 11, 2024
@eyurtsev eyurtsev enabled auto-merge (squash) July 11, 2024 15:17
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jul 12, 2024
@eyurtsev
Copy link
Collaborator

There are some broken unit tests. Are you able to resolve those?

auto-merge was automatically disabled July 23, 2024 08:29

Head branch was pushed to by a user without write access

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jul 23, 2024
@rick-soptim
Copy link
Contributor Author

I think I fixed the broken unit tests, but I'm not sure, because I'm having trouble running them locally.

@rick-soptim
Copy link
Contributor Author

I fixed the remaining problem found by the linter.

@eyurtsev eyurtsev enabled auto-merge (squash) July 25, 2024 15:26
@eyurtsev eyurtsev merged commit cd563fb into langchain-ai:master Jul 25, 2024
42 checks passed
olgamurraft pushed a commit to olgamurraft/langchain that referenced this pull request Aug 16, 2024
…Ms (langchain-ai#24068)

Thank you for contributing to LangChain!

**Description:**
This PR allows users of `langchain_community.llms.ollama.Ollama` to
specify the `auth` parameter, which is then forwarded to all internal
calls of `requests.request`. This works in the same way as the existing
`headers` parameters. The auth parameter enables the usage of the given
class with Ollama instances, which are secured by more complex
authentication mechanisms, that do not only rely on static headers. An
example are AWS API Gateways secured by the IAM authorizer, which
expects signatures dynamically calculated on the specific HTTP request.

**Issue:**

Integrating a remote LLM running through Ollama using
`langchain_community.llms.ollama.Ollama` only allows setting static HTTP
headers with the parameter `headers`. This does not work, if the given
instance of Ollama is secured with an authentication mechanism that
makes use of dynamically created HTTP headers which for example may
depend on the content of a given request.

**Dependencies:**

None

**Twitter handle:**

None

---------

Co-authored-by: Eugene Yurtsev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Related to langchain-community 🤖:improvement Medium size change to existing code to handle new use-cases lgtm PR looks good. Use to confirm that a PR is ready for merging. size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants