Skip to content

Commit

Permalink
fix: ai chat bot template (#10510)
Browse files Browse the repository at this point in the history
* fix: ai chat bot template

* refactor: bump sdk version
  • Loading branch information
swatDong committed Dec 12, 2023
1 parent 8740978 commit b364db1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder" Version="4.21.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.21.1" />
<PackageReference Include="Microsoft.Teams.AI" Version="1.0.0-preview-6" />
<PackageReference Include="Microsoft.Teams.AI" Version="1.0.0" />
</ItemGroup>
</Project>
29 changes: 20 additions & 9 deletions templates/csharp/ai-bot/Program.cs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,32 @@ builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<Clou
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<CloudAdapter>());

builder.Services.AddSingleton<IStorage, MemoryStorage>();
OpenAIModel model = null;

if (!string.IsNullOrWhiteSpace(config.OpenAI?.ApiKey))
{
model = new(new OpenAIModelOptions(config.OpenAI.ApiKey, "gpt-3.5-turbo"));
builder.Services.AddSingleton<OpenAIModel>(sp => new(
new OpenAIModelOptions(config.OpenAI.ApiKey, "gpt-3.5-turbo")
{
LogRequests = true
},
sp.GetService<ILoggerFactory>()
));
}
else if (!string.IsNullOrWhiteSpace(config.Azure?.OpenAIApiKey) && !string.IsNullOrWhiteSpace(config.Azure.OpenAIEndpoint))
{
model = new(new AzureOpenAIModelOptions(
config.Azure.OpenAIApiKey,
"gpt-35-turbo",
config.Azure.OpenAIEndpoint
builder.Services.AddSingleton<OpenAIModel>(sp => new(
new AzureOpenAIModelOptions(
config.Azure.OpenAIApiKey,
"gpt-35-turbo",
config.Azure.OpenAIEndpoint
)
{
LogRequests = true
},
sp.GetService<ILoggerFactory>()
));
}

if (model == null)
else
{
throw new Exception("Missing configuration, please configure settings for either OpenAI or Azure");
}
Expand All @@ -65,7 +76,7 @@ builder.Services.AddTransient<IBot>(sp =>
// Create ActionPlanner
ActionPlanner<TurnState> planner = new(
options: new(
model: model,
model: sp.GetService<OpenAIModel>(),
prompts: prompts,
defaultPrompt: async (context, state, planner) =>
{
Expand Down
3 changes: 2 additions & 1 deletion templates/csharp/ai-bot/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"LogLevel": {
"Default": "Information",
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information"
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft.Teams.AI": "Trace"
}
},
"AllowedHosts": "*",
Expand Down
2 changes: 1 addition & 1 deletion templates/csharp/ai-bot/{{ProjectName}}.csproj.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Bot.Builder" Version="4.21.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.21.1" />
<PackageReference Include="Microsoft.Teams.AI" Version="1.0.0-preview-3" />
<PackageReference Include="Microsoft.Teams.AI" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit b364db1

Please sign in to comment.