-
Notifications
You must be signed in to change notification settings - Fork 23
Connector Implementation & Inheritance: Foundry Local #497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
name-of-okja
wants to merge
14
commits into
aliencube:main
Choose a base branch
from
name-of-okja:feat/214-connector-foundry-local
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+385
−3
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a493758
feat: Add Foundry Local connector implementation
name-of-okja d9732ca
feat: Add unit and integration tests for FoundryLocalConnector
name-of-okja 6c33f5c
feat: Add Foundry Local documentation and update README
name-of-okja 7b61de6
fix: Reorder using directives in FoundryLocalConnector for consistency
name-of-okja 5bafb4d
fix: Add ConfigureAwait(false) to asynchronous calls in FoundryLocalC…
name-of-okja d398f2c
refactor: Simplify asynchronous call handling in FoundryLocalConnecto…
name-of-okja 97c294e
Merge branch 'main' into feat/214-connector-foundry-local
name-of-okja 4f35029
test: Enable FoundryLocalConnector test case in LanguageModelConnecto…
name-of-okja 1f071c5
Merge branch 'main' into feat/214-connector-foundry-local
name-of-okja d5c0837
enhance unit tests
name-of-okja c72c575
test: Remove FoundryLocal connector type from unsupported connectors …
name-of-okja 31bf1bf
fix: Update alias in FoundryLocalConnectorTests to match expected value
name-of-okja 63f1126
fix: Correct alias variable name in FoundryLocalConnectorTests
name-of-okja 8c259ce
fix: Mark Foundry Local as supported in README
name-of-okja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# OpenChat Playground with Foundry Local | ||
|
||
This page describes how to run OpenChat Playground (OCP) with Foundry Local models integration. | ||
|
||
## Get the repository root | ||
|
||
1. Get the repository root. | ||
|
||
```bash | ||
# bash/zsh | ||
REPOSITORY_ROOT=$(git rev-parse --show-toplevel) | ||
``` | ||
|
||
```powershell | ||
# PowerShell | ||
$REPOSITORY_ROOT = git rev-parse --show-toplevel | ||
``` | ||
|
||
## Run on local machine | ||
|
||
1. Make sure the Foundry Local server is up and running. | ||
|
||
```bash | ||
foundry service start | ||
``` | ||
|
||
1. Download the Foundry Local model. The default model OCP uses is `phi-4-mini`. | ||
|
||
```bash | ||
foundry model download phi-4-mini | ||
``` | ||
|
||
Alternatively, if you want to run with a different model, say `qwen2.5-7b`, other than the default one, download it first by running the following command. | ||
|
||
```bash | ||
foundry model download qwen2.5-7b | ||
``` | ||
|
||
Make sure to follow the model MUST be selected from the CLI output of `foundry model list`. | ||
|
||
1. Make sure you are at the repository root. | ||
|
||
```bash | ||
cd $REPOSITORY_ROOT | ||
``` | ||
|
||
1. Run the app. | ||
|
||
```bash | ||
# bash/zsh | ||
dotnet run --project $REPOSITORY_ROOT/src/OpenChat.PlaygroundApp -- \ | ||
--connector-type FoundryLocal | ||
``` | ||
|
||
```powershell | ||
# PowerShell | ||
dotnet run --project $REPOSITORY_ROOT\src\OpenChat.PlaygroundApp -- ` | ||
--connector-type FoundryLocal | ||
``` | ||
|
||
Alternatively, if you want to run with a different model, say `qwen2.5-7b`, make sure you've already downloaded the model by running the `foundry model download qwen2.5-7b` command. | ||
|
||
```bash | ||
# bash/zsh | ||
dotnet run --project $REPOSITORY_ROOT/src/OpenChat.PlaygroundApp -- \ | ||
--connector-type FoundryLocal \ | ||
--alias qwen2.5-7b | ||
``` | ||
|
||
```powershell | ||
# PowerShell | ||
dotnet run --project $REPOSITORY_ROOT\src\OpenChat.PlaygroundApp -- ` | ||
--connector-type FoundryLocal ` | ||
--alias qwen2.5-7b | ||
``` | ||
|
||
1. Open your web browser, navigate to `http://localhost:5280`, and enter prompts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/OpenChat.PlaygroundApp/Connectors/FoundryLocalConnector.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.ClientModel; | ||
|
||
using Microsoft.AI.Foundry.Local; | ||
using Microsoft.Extensions.AI; | ||
|
||
using OpenAI; | ||
|
||
using OpenChat.PlaygroundApp.Abstractions; | ||
using OpenChat.PlaygroundApp.Configurations; | ||
|
||
namespace OpenChat.PlaygroundApp.Connectors; | ||
|
||
/// <summary> | ||
/// This represents the connector entity for Foundry Local. | ||
/// </summary> | ||
/// <param name="settings"><see cref="AppSettings"/> instance.</param> | ||
public class FoundryLocalConnector(AppSettings settings) : LanguageModelConnector(settings.FoundryLocal) | ||
{ | ||
private readonly AppSettings _appSettings = settings ?? throw new ArgumentNullException(nameof(settings)); | ||
|
||
/// <inheritdoc/> | ||
public override bool EnsureLanguageModelSettingsValid() | ||
{ | ||
if (this.Settings is not FoundryLocalSettings settings) | ||
{ | ||
throw new InvalidOperationException("Missing configuration: FoundryLocal."); | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(settings.Alias!.Trim())) | ||
{ | ||
throw new InvalidOperationException("Missing configuration: FoundryLocal:Alias."); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override async Task<IChatClient> GetChatClientAsync() | ||
{ | ||
var settings = this.Settings as FoundryLocalSettings; | ||
var alias = settings!.Alias!; | ||
|
||
var manager = await FoundryLocalManager.StartModelAsync(aliasOrModelId: alias).ConfigureAwait(false); | ||
var model = await manager.GetModelInfoAsync(aliasOrModelId: alias).ConfigureAwait(false); | ||
|
||
var credential = new ApiKeyCredential(manager.ApiKey); | ||
var options = new OpenAIClientOptions() | ||
{ | ||
Endpoint = manager.Endpoint, | ||
}; | ||
|
||
var client = new OpenAIClient(credential, options); | ||
var chatClient = client.GetChatClient(model?.ModelId) | ||
.AsIChatClient(); | ||
|
||
Console.WriteLine($"The {this._appSettings.ConnectorType} connector created with model: {settings.Alias}"); | ||
|
||
return chatClient; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,6 @@ public void Given_Null_Settings_When_CreateChatClient_Invoked_Then_It_Should_Thr | |
[InlineData(ConnectorType.AmazonBedrock)] | ||
[InlineData(ConnectorType.GoogleVertexAI)] | ||
[InlineData(ConnectorType.DockerModelRunner)] | ||
[InlineData(ConnectorType.FoundryLocal)] | ||
[InlineData(ConnectorType.Ollama)] | ||
[InlineData(ConnectorType.Anthropic)] | ||
[InlineData(ConnectorType.Naver)] | ||
|
@@ -93,4 +92,31 @@ public void Given_Unsupported_ConnectorType_When_CreateChatClient_Invoked_Then_I | |
func.ShouldThrow<NotSupportedException>() | ||
.Message.ShouldContain($"Connector type '{connectorType}'"); | ||
} | ||
} | ||
|
||
[Trait("Category", "UnitTest")] | ||
[Theory] | ||
// [InlineData(typeof(AmazonBedrockConnector))] | ||
// [InlineData(typeof(AzureAIFoundryConnector))] | ||
[InlineData(typeof(GitHubModelsConnector))] | ||
// [InlineData(typeof(GoogleVertexAIConnector))] | ||
// [InlineData(typeof(DockerModelRunnerConnector))] | ||
[InlineData(typeof(FoundryLocalConnector))] | ||
[InlineData(typeof(HuggingFaceConnector))] | ||
// [InlineData(typeof(OllamaConnector))] | ||
// [InlineData(typeof(AnthropicConnector))] | ||
// [InlineData(typeof(LGConnector))] | ||
// [InlineData(typeof(NaverConnector))] | ||
[InlineData(typeof(OpenAIConnector))] | ||
// [InlineData(typeof(UpstageConnector))] | ||
public void Given_Concrete_Connectors_When_Checking_Inheritance_Then_Should_Inherit_From_LanguageModelConnector(Type derivedType) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오.. 이 테스트 메서드가 없었나요? |
||
{ | ||
// Arrange | ||
var baseType = typeof(LanguageModelConnector); | ||
|
||
// Act | ||
var result = baseType.IsAssignableFrom(derivedType); | ||
|
||
// Assert | ||
result.ShouldBeTrue(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.