Skip to content

Commit ca7e949

Browse files
authored
Merge pull request #30 from filipw/microsoft.extensions.ai
added AsChatClient to C# package + some clean up
2 parents faa6208 + 3c42185 commit ca7e949

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ${{ matrix.os }}
1616
strategy:
1717
matrix:
18-
os: [ubuntu-latest, macos-14, windows-latest]
18+
os: [ubuntu-latest, macos-15, windows-latest]
1919

2020
steps:
2121
- uses: actions/checkout@v3
@@ -75,6 +75,9 @@ jobs:
7575

7676
steps:
7777
- uses: actions/checkout@v3
78+
- uses: actions/setup-dotnet@v4
79+
with:
80+
dotnet-version: '9.0.x'
7881
- name: Download Linux artifacts
7982
uses: actions/download-artifact@v3
8083
with:
@@ -83,7 +86,7 @@ jobs:
8386
- name: Download macOS artifacts
8487
uses: actions/download-artifact@v3
8588
with:
86-
name: native-library-macos-14
89+
name: native-library-macos-15
8790
path: artifacts/macos
8891
- name: Download Windows artifacts
8992
uses: actions/download-artifact@v3

packages/csharp/Strathweb.Phi.Engine.Microsoft.Extensions.AI/PhiEngineChatClient.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,9 @@ private ConversationContext GetConversationContext(IList<ChatMessage> messages)
9494
var phiEngineMessages = head.Where(m => m.Role != ChatRole.System && m.Role != ChatRole.Tool)
9595
.Select(m => m.ToConversationMessage()).ToList();
9696
var systemInstruction = head.LastOrDefault(m => m.Role == ChatRole.System)?.Text ?? _systemInstruction;
97-
98-
Console.WriteLine($"Using system instruction: {systemInstruction}");
9997
return new ConversationContext(phiEngineMessages, systemInstruction);
10098
}
10199

102-
Console.WriteLine($"Using default system instruction: {_systemInstruction}");
103100
return new ConversationContext([], _systemInstruction);
104101
}
105102

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Strathweb.Phi.Engine.Microsoft.Extensions.AI;
2+
3+
public static class PhiEngineExtensions
4+
{
5+
public static PhiEngineChatClient AsChatClient(this PhiEngine engine, string id, StreamingEventHandler handler, string systemInstruction = null, InferenceOptions inferenceOptions = null) =>
6+
new(id, engine, handler, systemInstruction, inferenceOptions);
7+
}

samples/csharp/chatclient/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
modelBuilder.WithEventHandler(new BoxedPhiEventHandler(handler));
1111
var model = modelBuilder.Build(cacheDir);
1212

13-
var chatClient = new PhiEngineChatClient("Local Phi-3 Demo", model, handler, systemInstruction: "You convert what user said to all uppercase.");
13+
var chatClient = model.AsChatClient("Local Phi-3 Demo", handler,
14+
systemInstruction: "You convert what user said to all uppercase.");
15+
// or alternatively
16+
//var chatClient = new PhiEngineChatClient("Local Phi-3 Demo", model, handler, systemInstruction: "You convert what user said to all uppercase.");
1417

1518
var message = new ChatMessage(ChatRole.User, "hello world");
1619
var response = await chatClient.CompleteAsync([message]);

samples/csharp/chatclient/chatclient.console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<ItemGroup>
1010
<!-- note: this is intentionally referencing the library via the nuget package: to test it, and to take advantage of the native assets there -->
11-
<PackageReference Include="Strathweb.Phi.Engine.Microsoft.Extensions.AI" Version="0.1.3" />
11+
<PackageReference Include="Strathweb.Phi.Engine.Microsoft.Extensions.AI" Version="0.1.2" />
1212
</ItemGroup>
1313

1414
<!-- only use the below if you know what you are doing (e.g. the native assets have to provided by hand or by extra copy task) -->

0 commit comments

Comments
 (0)