Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/cs/samples/TestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TestApp
{
public static async Task Main(string[] args)
{
var app = new TestApp(); // Create an instance of TestApp
var app = new TestApp(); // Create an instance of TestApp

Console.WriteLine(new string('=', 80)); // Separator for clarity
Console.WriteLine("Testing catalog integration...");
Expand Down Expand Up @@ -84,7 +84,7 @@ private async Task TestService()
}

private async Task TestCatalog()
// First test catalog listing
// First test catalog listing
{
using var manager = new FoundryLocalManager();
foreach (var m in await manager.ListCatalogModelsAsync())
Expand Down
4 changes: 4 additions & 0 deletions sdk/cs/src/FoundryLocalManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Microsoft.AI.Foundry.Local;
using System.Linq;
using System.Net.Http.Json;
using System.Net.Mime;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
Expand Down Expand Up @@ -47,6 +48,7 @@ public partial class FoundryLocalManager : IDisposable, IAsyncDisposable
private List<ModelInfo>? _catalogModels;
private Dictionary<string, ModelInfo>? _catalogDictionary;
private readonly Dictionary<ExecutionProvider, int> _priorityMap;
private static readonly string AssemblyVersion = typeof(FoundryLocalManager).Assembly.GetName().Version?.ToString() ?? "unknown";

// Gets the service URI
public Uri ServiceUri => _serviceUri ?? throw new InvalidOperationException("Service URI is not set. Call StartServiceAsync() first.");
Expand Down Expand Up @@ -111,6 +113,8 @@ public async Task StartServiceAsync(CancellationToken ct = default)
// set the timeout to 2 hours (for downloading large models)
Timeout = TimeSpan.FromSeconds(7200)
};

_serviceClient.DefaultRequestHeaders.UserAgent.ParseAdd($"foundry-local-cs-sdk/{AssemblyVersion}");
}
}

Expand Down
127 changes: 127 additions & 0 deletions sdk/js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion sdk/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"types": "dist/index.d.ts",
"license": "MIT",
"scripts": {
"build": "unbuild",
"build": "npx genversion -e src/version.ts && unbuild",
"format": "prettier --write .",
"format:check": "prettier --check .",
"lint": "eslint ./src/*",
Expand Down Expand Up @@ -42,6 +42,7 @@
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsdoc": "^46.8.2",
"genversion": "^3.2.0",
"prettier": "^3.2.4",
"typescript": "^5.2.2",
"unbuild": "^3.5.0",
Expand Down
3 changes: 2 additions & 1 deletion sdk/js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

import type { Fetch } from './types.js'
import { version } from './version.js'

/**
* Handles fetch requests with error handling.
Expand Down Expand Up @@ -71,7 +72,7 @@ export const postWithProgress = async (
// Sending a POST request and getting a streamable response
const response = await fetchWithErrorHandling(fetch, host, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', 'User-Agent': `foundry-local-js-sdk/${version}` },
body: body ? JSON.stringify(body) : undefined,
})

Expand Down
2 changes: 2 additions & 0 deletions sdk/js/src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Generated by genversion.
export const version = '0.4.0'
6 changes: 5 additions & 1 deletion sdk/js/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { describe, expect, it, vi, beforeEach } from 'vitest'
import * as client from '../src/client'
import type { Fetch } from '../src/types'
import { version } from '../src/version'

describe('Client', () => {
const mockFetch = vi.fn() as unknown as Fetch
Expand Down Expand Up @@ -60,7 +61,10 @@ describe('Client', () => {
expect(result).toEqual({ ok: true })
expect(mockFetch).toHaveBeenCalledWith('http://example.com', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: {
'Content-Type': 'application/json',
'User-Agent': `foundry-local-js-sdk/${version}`,
},
body: JSON.stringify(body),
})
})
Expand Down
2 changes: 0 additions & 2 deletions sdk/python/foundry_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@
_logger.propagate = False

__all__ = ["FoundryLocalManager"]

__version__ = "0.4.0"
5 changes: 4 additions & 1 deletion sdk/python/foundry_local/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import httpx
from tqdm import tqdm

from foundry_local.version import __version__ as sdk_version

logger = logging.getLogger(__name__)


Expand All @@ -34,7 +36,8 @@ def __init__(self, host: str, timeout: float | httpx.Timeout | None = None) -> N
host (str): Base URL of the host.
timeout (float | httpx.Timeout | None): Timeout for the HTTP client.
"""
self._client = httpx.Client(base_url=host, timeout=timeout)
headers = {"user-agent": f"foundry-local-python-sdk/{sdk_version}"}
self._client = httpx.Client(base_url=host, timeout=timeout, headers=headers)

def _request(self, *args, **kwargs) -> httpx.Response:
"""
Expand Down
1 change: 1 addition & 0 deletions sdk/python/foundry_local/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.4.0"
1 change: 1 addition & 0 deletions sdk/python/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from unittest import mock

import pytest

from foundry_local.api import FoundryLocalManager
from foundry_local.client import HttpResponseError
from foundry_local.models import FoundryModelInfo
Expand Down
14 changes: 12 additions & 2 deletions sdk/python/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@

import httpx
import pytest

from foundry_local.client import HttpResponseError, HttpxClient
from foundry_local.version import __version__ as sdk_version


def test_initialization():
"""Test initialization of HttpxClient."""
with mock.patch("httpx.Client") as mock_client:
HttpxClient("http://localhost:5273")
mock_client.assert_called_once_with(base_url="http://localhost:5273", timeout=None)
mock_client.assert_called_once_with(
base_url="http://localhost:5273",
timeout=None,
headers={"user-agent": f"foundry-local-python-sdk/{sdk_version}"},
)

# Test with timeout
HttpxClient("http://localhost:5273", timeout=30.0)
mock_client.assert_called_with(base_url="http://localhost:5273", timeout=30.0)
mock_client.assert_called_with(
base_url="http://localhost:5273",
timeout=30.0,
headers={"user-agent": f"foundry-local-python-sdk/{sdk_version}"},
)


# pylint: disable=protected-access
Expand Down
1 change: 1 addition & 0 deletions sdk/python/test/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest import mock

import pytest

from foundry_local.service import assert_foundry_installed, get_service_uri, start_service


Expand Down
4 changes: 3 additions & 1 deletion sdk/rust/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ impl HttpClient {
/// A new HttpClient instance.
pub fn new(host: &str, timeout_secs: Option<u64>) -> Self {
let timeout = timeout_secs.map(Duration::from_secs);
let mut client_builder = Client::builder().user_agent("foundry-local-rust-sdk/0.2.0");
const VERSION: &str = env!("CARGO_PKG_VERSION");
let mut client_builder =
Client::builder().user_agent(&format!("foundry-local-rust-sdk/{}", VERSION));

if let Some(timeout) = timeout {
client_builder = client_builder.timeout(timeout);
Expand Down