Skip to content

Add bearer token support to API requests #46

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gromer
Copy link

@gromer gromer commented Feb 26, 2025

This pull request introduces the use of bearer tokens for authentication in the OllamaKit API requests. The changes include adding a new bearerToken property to the OllamaKit struct and updating various methods to include this token when making API requests.

Key changes include:

Authentication Enhancement

  • Added a bearerToken property to the OllamaKit struct and updated the initializer to accept this token. (Sources/OllamaKit/OllamaKit.swift) [1] [2]
  • Updated the asURLRequest method in OKRouter to include the bearer token in the request headers if provided. (Sources/OllamaKit/Utils/OKRouter.swift)

API Request Updates

  • Modified methods in various files to include the bearer token when creating URL requests:
    • chat method in OllamaKit+Chat.swift [1] [2]
    • copyModel method in OllamaKit+CopyModel.swift [1] [2]
    • deleteModel method in OllamaKit+DeleteModel.swift [1] [2]
    • embeddings method in OllamaKit+Embeddings.swift [1] [2]
    • generate method in OllamaKit+Generate.swift [1] [2]
    • modelInfo method in OllamaKit+ModelInfo.swift [1] [2]
    • models method in OllamaKit+Models.swift [1] [2]
    • pullModel method in OllamaKit+PullModel.swift [1] [2]
    • reachable method in OllamaKit+Reachable.swift [1] [2]

I'm still looking at this, and working on testing it, just wanted to get the initial code into PR form.

@gromer gromer marked this pull request as draft February 26, 2025 00:06
@gromer gromer closed this Feb 27, 2025
@gromer gromer reopened this Feb 27, 2025
@kevinhermawan
Copy link
Owner

Suggestion, instead of creating a specific header for the bearer token, we can implement custom HTTP headers. You can check my implementation at swift-llm-chat-openai or swift-llm-chat-anthropic

@gromer
Copy link
Author

gromer commented Mar 12, 2025

Suggestion, instead of creating a specific header for the bearer token, we can implement custom HTTP headers. You can check my implementation at swift-llm-chat-openai or swift-llm-chat-anthropic

I agree. After making this PR, I got thinking about it. Since Ollama doesn't natively support an auth header, a more general header solution does seem the best route. I'll poke around at your other repos, and update this PR soon 🤘

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.

2 participants