1+ //<chat_completion>
12using Azure ;
23using Azure . Identity ;
4+ using Azure . AI . Projects ;
35using Azure . AI . Inference ;
4- using Azure . Core ;
5- using Azure . Core . Pipeline ;
66
7+ var projectEndpoint = Evironment . GetEnvironmentVariable ( "AZURE_AI_ENDPOINT" ) ;
8+ var modelDeploymentName = Evironment . GetEnvironmentVariable ( "AZURE_AI_MODEL" ) ;
9+ var credential = new DefaultAzureCredential ( ) ;
710
8- namespace AiAgentsTests
9- {
10- //<chat_completion>
11- public class SimpleInference
12- {
13- public static void Main ( string [ ] args )
14- {
15-
16- var endpointUrl = Evironment . GetEnvironmentVariable ( "AZURE_OPENAI_ENDPOINT" ) ;
17- var modelName = Evironment . GetEnvironmentVariable ( "AZURE_OPENAI_MODEL_NAME" ) ;
18-
19- var endpoint = new Uri ( endpointUrl ) ;
20- var credential = new DefaultAzureCredential ( ) ;
21- var model = modelName ;
22-
23- AzureAIInferenceClientOptions clientOptions = new AzureAIInferenceClientOptions ( ) ;
24- BearerTokenAuthenticationPolicy tokenPolicy = new BearerTokenAuthenticationPolicy ( credential , new string [ ] { "https://cognitiveservices.azure.com/.default" } ) ;
25- clientOptions . AddPolicy ( tokenPolicy , HttpPipelinePosition . PerRetry ) ;
11+ AIProjectClient client = new AIProjectClient ( projectEndpoint , credential ) ;
2612
13+ ChatCompletionsClient chatClient = client . GetChatCompletionsClient ( ) ;
2714
28- var client = new ChatCompletionsClient (
29- endpoint ,
30- credential ,
31- clientOptions
32- ) ;
33-
34- var requestOptions = new ChatCompletionsOptions ( )
35- {
36- Messages =
37- {
38- new ChatRequestSystemMessage ( "You are a helpful assistant." ) ,
39- new ChatRequestUserMessage ( "How many feet are in a mile?" ) ,
40- } ,
41- } ;
42-
43- Response < ChatCompletions > response = client . Complete ( requestOptions ) ;
44- Console . WriteLine ( response . Value . Content ) ;
45-
46- }
47- }
48- // </chat_completion>
49- }
15+ var requestOptions = new ChatCompletionsOptions ( )
16+ {
17+ Messages =
18+ {
19+ new ChatRequestSystemMessage ( "You are a helpful assistant." ) ,
20+ new ChatRequestUserMessage ( "How many feet are in a mile?" ) ,
21+ } ,
22+ Model = modelDeploymentName
23+ } ;
24+ Response < ChatCompletions > response = chatClient . Complete ( requestOptions ) ;
25+ Console . WriteLine ( response . Value . Content ) ;
26+ // </chat_completion>
0 commit comments