Send a chat message to a HuggingFace-hosted model using the Microsoft.Extensions.AI IChatClient interface.
This example assumes using HuggingFace; is in scope and apiKey contains your HuggingFace API key.
1 2 3 4 5 6 7 8 9101112
usingvarclient=newHuggingFaceInferenceClient(apiKey);IChatClientchatClient=client;varresponse=awaitchatClient.GetResponseAsync([new ChatMessage(ChatRole.User, "Say hello in one word.")],newChatOptions{ModelId="Qwen/Qwen2.5-Coder-32B-Instruct",MaxOutputTokens=32,});Console.WriteLine(response.Text);