[PR #4096] [CLOSED] add _defaultApiClient in api/client.go for reuse #42628

Closed
opened 2026-04-24 22:22:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/4096
Author: @alwqx
Created: 5/2/2024
Status: Closed

Base: mainHead: feat/default-api-client-reuse


📝 Commits (1)

  • c55c01f api: add _defaultApiClient for resue and style fix

📊 Changes

2 files changed (+50 additions, -7 deletions)

View changed files

📝 api/client.go (+11 -2)
📝 api/client_test.go (+39 -5)

📄 Description

Hi, this pr mainly make following improvements:

  1. add _defaultApiClient for reuse
    I find that api.ClientFromEnvironment() is called more than one time by some functions in cmd/cmd.go (e.g. RunHandler() generateInteractive). So I add _defaultApiClient for reuse and to reduce memory alloc.
  2. update tests and split TestClientFromEnvironment to TestClientFromEnvironment and TestGetOllamaHost

I hope these improvements are helpful. @jmorganca @dhiltgen Please feel free to provide feedback if you have any suggestions. And if you think this pr is not needed, I will close it.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/4096 **Author:** [@alwqx](https://github.com/alwqx) **Created:** 5/2/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/default-api-client-reuse` --- ### 📝 Commits (1) - [`c55c01f`](https://github.com/ollama/ollama/commit/c55c01f6e974e6105c97f20d5475ead01c0a4191) api: add _defaultApiClient for resue and style fix ### 📊 Changes **2 files changed** (+50 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `api/client.go` (+11 -2) 📝 `api/client_test.go` (+39 -5) </details> ### 📄 Description Hi, this pr mainly make following improvements: 1. add _defaultApiClient for reuse I find that `api.ClientFromEnvironment()` is called more than one time by some functions in `cmd/cmd.go` (e.g. `RunHandler()` `generateInteractive`). So I add **_defaultApiClient** for reuse and to reduce memory alloc. 2. update tests and split `TestClientFromEnvironment` to `TestClientFromEnvironment` and `TestGetOllamaHost` I hope these improvements are helpful. @jmorganca @dhiltgen Please feel free to provide feedback if you have any suggestions. And if you think this pr is not needed, I will close it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-24 22:22:56 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#42628