96 lines
2.9 KiB
C#
96 lines
2.9 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using OpenAI;
|
|
using OpenAI.Chat;
|
|
using OpenAI.Audio;
|
|
|
|
class uncloseai
|
|
{
|
|
static async Task Main(string[] args)
|
|
{
|
|
Console.WriteLine("=== UncloseAI C# Client (Official OpenAI SDK) ===\n");
|
|
|
|
// Non-streaming chat with Hermes
|
|
Console.WriteLine("=== Non-Streaming Chat (Hermes) ===");
|
|
var hermesClient = new ChatClient(
|
|
model: "adamo1139/Hermes-3-Llama-3.1-8B-FP8-Dynamic",
|
|
apiKey: "dummy-key",
|
|
new OpenAIClientOptions
|
|
{
|
|
Endpoint = new Uri("https://hermes.ai.unturf.com/v1")
|
|
}
|
|
);
|
|
|
|
var hermesResponse = await hermesClient.CompleteChatAsync(
|
|
new[]
|
|
{
|
|
new UserChatMessage("Give a Python Fizzbuzz solution in one line of code?")
|
|
},
|
|
new ChatCompletionOptions
|
|
{
|
|
Temperature = 0.5f,
|
|
MaxOutputTokenCount = 150
|
|
}
|
|
);
|
|
|
|
Console.WriteLine($"Response: {hermesResponse.Value.Content[0].Text}\n");
|
|
|
|
// Streaming chat with Qwen
|
|
Console.WriteLine("=== Streaming Chat (Qwen) ===");
|
|
var qwenClient = new ChatClient(
|
|
model: "hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:Q4_K_M",
|
|
apiKey: "dummy-key",
|
|
new OpenAIClientOptions
|
|
{
|
|
Endpoint = new Uri("https://qwen.ai.unturf.com/v1")
|
|
}
|
|
);
|
|
|
|
Console.Write("Response: ");
|
|
await foreach (var update in qwenClient.CompleteChatStreamingAsync(
|
|
new[]
|
|
{
|
|
new UserChatMessage("Give a Python Fizzbuzz solution in one line of code?")
|
|
},
|
|
new ChatCompletionOptions
|
|
{
|
|
Temperature = 0.5f,
|
|
MaxOutputTokenCount = 150
|
|
}
|
|
))
|
|
{
|
|
foreach (var contentPart in update.ContentUpdate)
|
|
{
|
|
Console.Write(contentPart.Text);
|
|
}
|
|
}
|
|
Console.WriteLine("\n");
|
|
|
|
// TTS example
|
|
Console.WriteLine("=== TTS Speech Generation ===");
|
|
var ttsClient = new AudioClient(
|
|
model: "tts-1",
|
|
apiKey: "YOLO",
|
|
new OpenAIClientOptions
|
|
{
|
|
Endpoint = new Uri("https://speech.ai.unturf.com/v1")
|
|
}
|
|
);
|
|
|
|
var speech = await ttsClient.GenerateSpeechAsync(
|
|
"I think so therefore, Today is a wonderful day to grow something people love!",
|
|
GeneratedSpeechVoice.Alloy,
|
|
new SpeechGenerationOptions
|
|
{
|
|
Speed = 0.9f
|
|
}
|
|
);
|
|
|
|
await File.WriteAllBytesAsync("speech.mp3", speech.Value.ToArray());
|
|
var fileInfo = new FileInfo("speech.mp3");
|
|
Console.WriteLine($"[OK] Speech file created: speech.mp3 ({fileInfo.Length} bytes)\n");
|
|
|
|
Console.WriteLine("=== Examples Complete ===");
|
|
}
|
|
}
|