Skip to content

DI with IChatCompletionService with multiple providers #9493

Answered by saroshwadia
saroshwadia asked this question in Q&A
Discussion options

You must be logged in to vote

Finally used (DI) keyed services and did the following: (serviceId:)

builder.Services.AddAzureOpenAIChatCompletion(
    deploymentName: builder.Configuration["AzureOpenAI:DeploymentName"]!, 
    endpoint: builder.Configuration["AzureOpenAI:Endpoint"]!,  
    apiKey: builder.Configuration["AzureOpenAI:ApiKey"]!, 
    serviceId: "Azure");
    
builder.Services.AddOpenAIChatCompletion(
    modelId: builder.Configuration["OpenAI:ChatModel"]!, 
    apiKey: builder.Configuration["OpenAI:ApiKey"]!, 
    serviceId: "OpenAI");
    
builder.Services.AddOllamaChatCompletion(
    modelId: builder.Configuration["OllamaAI:ChatModel"]!, 
    endpoint: new Uri(builder.Configuration["OllamaAI:Endpoint"]!),

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@saroshwadia
Comment options

Comment options

You must be logged in to vote
1 reply
@saroshwadia
Comment options

Comment options

You must be logged in to vote
1 reply
@RogerBarreto
Comment options

Answer selected by RogerBarreto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants