Skip to content

Commit 3837cc0

Browse files
committed
Add connectivity tests
1 parent da35e17 commit 3837cc0

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

AiServer.ServiceInterface/OpenAiChatServices.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ public static async Task<OpenAiChatResponse> ProcessSync(this QueueOpenAiChatCom
465465
throw new Exception(job.Failed.Error!.Message);
466466
}
467467

468-
// Wait for the job to complete max 1 minute
469-
var timeout = DateTime.UtcNow.AddMinutes(1);
468+
// Wait for the job to complete max 2 minutes
469+
var timeout = DateTime.UtcNow.AddMinutes(2);
470470
while (queuedJob?.Job?.State is not (BackgroundJobState.Completed or BackgroundJobState.Cancelled
471471
or BackgroundJobState.Failed) && DateTime.UtcNow < timeout)
472472
{

AiServer.Tests/ConnectivityTests.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System.Net.Http.Headers;
2+
using System.Text;
3+
using NUnit.Framework;
4+
5+
namespace AiServer.Tests;
6+
7+
public class ConnectivityTests
8+
{
9+
[Test, Explicit("Integration test")]
10+
public async Task Can_call_supermicro()
11+
{
12+
// Environment.SetEnvironmentVariable("DOTNET_SYSTEM_NET_DISABLEIPV6", "1");
13+
// var url = "http://192.168.4.200:11434/api/tags";
14+
var url = "https://supermicro.pvq.app/api/tags";
15+
using var client = new HttpClient();
16+
var res = await client.GetAsync(url);
17+
res.EnsureSuccessStatusCode();
18+
var json = await res.Content.ReadAsStringAsync();
19+
Console.WriteLine(json);
20+
}
21+
22+
[Test, Explicit("Integration test")]
23+
public async Task Can_call_GetOllamaModels()
24+
{
25+
// Environment.SetEnvironmentVariable("DOTNET_SYSTEM_NET_DISABLEIPV6", "1");
26+
// var url = "https://openai.servicestack.net/api/GetOllamaModels"
27+
// .AddQueryParam("ApiBaseUrl", "https://supermicro.pvq.app");
28+
var url = "https://okai.servicestack.com/models/gist?prompt=1735872878252";
29+
using var client = new HttpClient();
30+
var res = await client.GetAsync(url);
31+
res.EnsureSuccessStatusCode();
32+
var json = await res.Content.ReadAsStringAsync();
33+
Console.WriteLine(json);
34+
}
35+
36+
[Test, Explicit("Integration test")]
37+
public async Task Can_call_groq()
38+
{
39+
var url = "https://api.groq.com/openai/v1/chat/completions";
40+
using var client = new HttpClient();
41+
var content = new StringContent(
42+
"""
43+
{
44+
"messages": [{
45+
"role": "user",
46+
"content": "Capital of France?"
47+
}],
48+
"model": "qwen-qwq-32b",
49+
"max_tokens": 2048,
50+
"temperature": 0.7,
51+
"stream": false
52+
}
53+
""",
54+
Encoding.UTF8, "application/json");
55+
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("GROQ_API_KEY"));
56+
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
57+
58+
var res = await client.PostAsync(url, content);
59+
res.EnsureSuccessStatusCode();
60+
var json = await res.Content.ReadAsStringAsync();
61+
Console.WriteLine(json);
62+
}
63+
}

AiServer/Configure.AppHost.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public class AppHost() : AppHostBase("AI Server"), IHostingStartup
1818
{
1919
public void Configure(IWebHostBuilder builder) => builder
2020
.ConfigureServices((context,services) => {
21+
#if DEBUG
22+
// Fixes HttpClient hanging to groq.com and cloudflare worker
23+
Environment.SetEnvironmentVariable("DOTNET_SYSTEM_NET_DISABLEIPV6", "1");
24+
#endif
25+
2126
// Configure ASP.NET Core IOC Dependencies
2227
context.Configuration.GetSection(nameof(AppConfig)).Bind(AppConfig.Instance);
2328
var appConfig = AppConfig.Instance;

0 commit comments

Comments
 (0)