Skip to content

Pass down base URL and API key to completion handler #1002

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

Merged
merged 5 commits into from
Feb 11, 2025
Merged

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Feb 10, 2025

In order to make Ollama work with API Keys, I needed to change the
completion handler to take a base URL and also leverage a given API key
(if available).

Signed-off-by: Juan Antonio Osorio [email protected]
Co-Authored-by: Alejandro Ponce de Leon [email protected]

@JAORMX JAORMX requested a review from rdimitrov February 10, 2025 16:06
api_key: Optional[str],
stream: bool = False,
is_fim_request: bool = False,
) -> Union[ChatResponse, GenerateResponse]:
"""Stream response directly from Ollama API."""

if not base_url:
raise ValueError("base_url is required for Ollama")
Copy link
Contributor

Choose a reason for hiding this comment

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

could we default to localhost:11434 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should already get this default frm the caller.

# TODO: Add CodeGate user agent.
headers = dict()
if api_key:
headers["Authorization"] = f"Bearer {api_key}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the bearer token get forwarded or does it have some other meaning later on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gets set so we can forward it

Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

The PR needs a rebase but in general the code looks good and I tested Ollama chat in continue which still works great.

@JAORMX JAORMX force-pushed the ollama-api-key branch 2 times, most recently from 222d2f3 to dd3db9f Compare February 11, 2025 08:52
JAORMX and others added 4 commits February 11, 2025 11:47
In order to make Ollama work with API Keys, I needed to change the
completion handler to take a base URL and also leverage a given API key
(if available).

Signed-off-by: Juan Antonio Osorio <[email protected]>
Co-Authored-by: Alejandro Ponce de Leon <[email protected]>
Signed-off-by: Juan Antonio Osorio <[email protected]>
@JAORMX JAORMX force-pushed the ollama-api-key branch 2 times, most recently from 5b8a04e to d5281d2 Compare February 11, 2025 10:44
Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

I kicked the tests, that looked like a transient error

@JAORMX JAORMX merged commit 6938347 into main Feb 11, 2025
9 checks passed
@JAORMX JAORMX deleted the ollama-api-key branch February 11, 2025 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants