Basic example showing how to create a client and make a request.
1
usingvarclient=newWriterClient(apiKey);
Chat Client Get Response
1 2 3 4 5 6 7 8 9101112
usingvarclient=newWriterClient(apiKey);Meai.IChatClientchatClient=client;// Use the MEAI IChatClient interface for chat completions.varresponse=awaitchatClient.GetResponseAsync(messages:[newMeai.ChatMessage(Meai.ChatRole.User,"Generate 5 random words.")],newMeai.ChatOptions{ModelId="palmyra-x-004",});Console.WriteLine(response.Text);
Chat Client Streaming
1 2 3 4 5 6 7 8 91011121314151617
usingvarclient=newWriterClient(apiKey);Meai.IChatClientchatClient=client;// Stream chat responses using the MEAI IChatClient interface.varenumerable=chatClient.GetStreamingResponseAsync(messages:[newMeai.ChatMessage(Meai.ChatRole.User,"Generate 5 random words.")],newMeai.ChatOptions{ModelId="palmyra-x-004",});vardeltas=newList<string>();awaitforeach(varupdateinenumerable){Console.Write(update.Text);deltas.Add(update.Text??string.Empty);}
Chat Client Get Service Metadata
12345
usingvarclient=newWriterClient("test-api-key");Meai.IChatClientchatClient=client;// Retrieve metadata about the chat provider.varmetadata=Meai.ChatClientExtensions.GetService<Meai.ChatClientMetadata>(chatClient);
usingvarclient=newWriterClient(apiKey);Meai.IChatClientchatClient=client;// Stream chat responses with tool calling using the MEAI IChatClient interface.// Define a simple tool that returns the current weather.vartool=Meai.AIFunctionFactory.Create((stringlocation)=>$"The weather in {location} is sunny, 72°F.","get_weather","Gets the current weather for a location.");varenumerable=chatClient.GetStreamingResponseAsync(messages:[newMeai.ChatMessage(Meai.ChatRole.User,"What's the weather in San Francisco?")],newMeai.ChatOptions{ModelId="palmyra-x-004",Tools=[tool],});varhasContent=false;Meai.ChatFinishReason?finishReason=null;awaitforeach(varupdateinenumerable){if(update.Textis{Length:>0}){Console.Write(update.Text);hasContent=true;}if(update.FinishReasonisnotnull){finishReason=update.FinishReason;}}// The model should either respond with tool calls or text content.