Skip to content

Commit d9ebff3

Browse files
committed
some tests
1 parent c60f3f8 commit d9ebff3

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ jobs:
3535
mkdir -p artifacts/packages
3636
mkdir -p artifacts/native
3737
38-
- name: Build native wrapper
38+
- name: Install dependencies
39+
run: brew install cmake
40+
41+
- name: Build native stub library
3942
run: |
4043
cmake -S native -B native/build -DCMAKE_BUILD_TYPE=Release
41-
cmake --build native/build --target mlxsharp
44+
cmake --build native/build --target mlxsharp --config Release
4245
cp native/build/libmlxsharp.dylib artifacts/native/
46+
cp native/build/libmlxsharp.dylib src/MLXSharp.Native/runtimes/osx-arm64/native/
4347
4448
- name: Run tests
4549
run: dotnet test MLXSharp.sln --configuration Release --no-build --logger "trx;LogFileName=TestResults.trx" --results-directory artifacts/test-results

TESTING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Testing MLXSharp
2+
3+
## Quick Tests
4+
5+
MLXSharp використовує managed backend з мок-даними для швидкого тестування:
6+
7+
```bash
8+
dotnet test
9+
```
10+
11+
## Native Library Build
12+
13+
Зібрати stub бібліотеку для локальної розробки (macOS):
14+
15+
```bash
16+
brew install cmake
17+
cmake -S native -B native/build -DCMAKE_BUILD_TYPE=Release
18+
cmake --build native/build --target mlxsharp
19+
cp native/build/libmlxsharp.dylib src/MLXSharp.Native/runtimes/osx-arm64/native/
20+
```
21+
22+
Stub версія лінкується з MLX але повертає тестові дані замість реальних результатів моделі.
23+
24+
## GitHub Actions
25+
26+
CI автоматично:
27+
- Встановлює CMake
28+
- Компілює native stub бібліотеку
29+
- Запускає всі тести (managed + native stub)
30+
- Публікує артефакти (native libs, packages, test results)
31+
32+
## Майбутня робота
33+
34+
Для справжньої інтеграції з MLX треба:
35+
- Імплементувати завантаження safetensors моделей через MLX C++ API
36+
- Додати tokenization
37+
- Реалізувати text generation loop
38+
- Або використати mlx-lm через Python.NET або InProc Python embedding

native/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ endif()
1515

1616
add_subdirectory(${CMAKE_SOURCE_DIR}/../extern/mlx ${CMAKE_BINARY_DIR}/extern/mlx EXCLUDE_FROM_ALL)
1717

18+
# Stub implementation for testing and development
1819
add_library(mlxsharp SHARED src/mlxsharp.cpp)
1920

2021
target_link_libraries(mlxsharp PRIVATE mlx)

src/MLXSharp.Tests/MlxIntegrationTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,44 @@ public async Task SemanticKernelExtensionAddsChatService()
9191
Assert.Contains("mlx", result[0].Content, StringComparison.OrdinalIgnoreCase);
9292
}
9393

94+
[Fact(Skip = "Requires real MLX model and native library")]
95+
public async Task RealModelGeneratesText()
96+
{
97+
var modelPath = Environment.GetEnvironmentVariable("MLXSHARP_MODEL_PATH");
98+
if (string.IsNullOrEmpty(modelPath) || !Directory.Exists(modelPath))
99+
{
100+
// Skip if model not available
101+
return;
102+
}
103+
104+
var services = new ServiceCollection();
105+
services.AddMlx(builder =>
106+
{
107+
builder.Configure(options =>
108+
{
109+
options.ChatModelId = modelPath;
110+
options.LibraryPath = ResolveNativeLibraryPath();
111+
});
112+
builder.UseNativeBackend();
113+
});
114+
115+
await using var provider = services.BuildServiceProvider();
116+
var chatClient = provider.GetRequiredService<IChatClient>();
117+
118+
var response = await chatClient.GetResponseAsync(
119+
new[] { new ChatMessage(ChatRole.User, "Say hello in Ukrainian") },
120+
new ChatOptions { MaxOutputTokens = 50 },
121+
CancellationToken.None);
122+
123+
Assert.NotEmpty(response.Messages);
124+
Assert.NotEmpty(response.Messages[0].Text);
125+
// Should contain Ukrainian greeting
126+
Assert.True(response.Messages[0].Text.Contains("Привіт", StringComparison.OrdinalIgnoreCase) ||
127+
response.Messages[0].Text.Contains("Вітаю", StringComparison.OrdinalIgnoreCase) ||
128+
response.Messages[0].Text.Contains("Здрастуйте", StringComparison.OrdinalIgnoreCase),
129+
$"Expected Ukrainian greeting but got: {response.Messages[0].Text}");
130+
}
131+
94132
private static string? ResolveNativeLibraryPath()
95133
{
96134
var baseDirectory = AppContext.BaseDirectory;

0 commit comments

Comments
 (0)