Skip to content

Conversation

qoweh
Copy link
Contributor

@qoweh qoweh commented Oct 14, 2025

Purpose

Does this introduce a breaking change?

[ ] Yes
[x] No

Pull Request Type

What kind of change does this Pull Request introduce?

[ ] Bugfix
[x] New feature
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

README updated?

The top-level readme for this repo contains a link to each sample in the repo. If you're adding a new sample did you update the readme?

[x] Yes
[ ] No
[ ] N/A

How to Test

  • Get the code
git clone https://github.com/qoweh/open-chat-playground.git
cd open-chat-playground
git checkout feat/261-ConnectorImplementation-Inheritance-AnthropicClaude
  • Test the code
dotnet test test/OpenChat.PlaygroundApp.Tests/OpenChat.PlaygroundApp.Tests.csproj --filter FullyQualifiedName~AnthropicConnectorTests

What to Check

  • Default model and token configuration applied correctly
  • Exception handling for invalid settings
  • Inheritance and type casting behavior validation
  • All related unit tests pass successfully
  • Docs updated and consistent with Anthropic connector section

Other Information about AnthropicConnectorTests.cs

생성/타입 관련

  • Given_Null_Settings_When_Instantiated_Then_It_Should_Throw()
  • Given_Settings_When_Instantiated_Then_It_Should_Return()
  • Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType()

EnsureLanguageModelSettingsValid()

  • Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw()
  • Given_Invalid_ApiKey_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw()
  • Given_Invalid_Model_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw()
  • Given_Valid_Settings_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Return_True()

GetChatClientAsync()

  • Given_Valid_Settings_When_GetChatClientAsync_Invoked_Then_It_Should_Return_ChatClient()
  • Given_Settings_Is_Null_When_GetChatClientAsync_Invoked_Then_It_Should_Throw()
  • Given_Missing_ApiKey_When_GetChatClientAsync_Invoked_Then_It_Should_Throw()

CreateChatClientAsync()

  • Given_Valid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Return_ChatClient()
  • Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw()

Adds links to the documentation for the Anthropic connector in the README, covering local machine, local container, and Azure deployments.

Addresses the need to provide clear instructions for utilizing the new Anthropic connector.

Related to aliencube#261
Updates the documentation to refer to Anthropic models instead of the specific Claude model, reflecting the broader range of models now supported.

Relates to aliencube#261
Comment on lines +49 to +60
var client = new AnthropicClient() { Auth = new APIAuthentication(apiKey) };

var chatClient = client.Messages
.AsBuilder()
.UseFunctionInvocation()
.Use((messages, options, next, cancellationToken) =>
{
options!.ModelId = settings!.Model;
options.MaxOutputTokens ??= 1000;
return next(messages, options, cancellationToken);
})
.Build();
Copy link
Contributor Author

@qoweh qoweh Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 해보다가, anthropic sdk의 api 호출이 잘 안 되어서 우리 프로젝트의 파일들을 살펴봤습니다.

  1. ChatInput.razor.cs 파일에서

private async Task SendMessageAsync()await OnSend.InvokeAsync(new ChatMessage(ChatRole.User, trimmedText)); 호출

  1. Chat.razor.cs 파일에서

private async Task AddUserMessageAsync(ChatMessage userMessage)ChatService.GetStreamingResponseAsync([.. messages], chatOptions, currentResponseCancellation.Token) 호출

  1. ChatService.cs 파일에서

public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync() → return this._chatClient.GetStreamingResponseAsync(chats, options, cancellationToken); 호출

이쪽 부분에서 token 수를 지정해야 호출이 되어서 임의로 토큰수를 1000으로 지정했습니다. 혹시 어떻게 하면 좋을지 궁금합니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 해보다가, anthropic sdk의 api 호출이 잘 안 되어서 우리 프로젝트의 파일들을 살펴봤습니다.

호출이 잘 안 됐다는 게 정확히 어떤 의미죠? Exception이 발생했다는 건가요?

Copy link
Contributor Author

@qoweh qoweh Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 네 만약 57번을 주석처리하면
"message":"max_tokens: must be greater than or equal to 1"
이런 식으로 예외가 뜹니다

fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'F9Rlr3x3VTCcGA5lnf-m5VlCqoos2nCX63LAzBhR2Ow'.
System.Net.Http.HttpRequestException: {"type":"error","error":{"type":"invalid_request_error","message":"max_tokens: must be greater than or equal to 1"},"request_id":"req_011CU7LZEatnHLLUn6kkH2h7"}
at Anthropic.SDK.BaseEndpoint.HttpRequestRaw(String url, HttpMethod verb, Object postData, Boolean streaming, CancellationToken ctx)
at Anthropic.SDK.EndpointBase.HttpStreamingRequestMessages(String url, HttpMethod verb, Object postData, CancellationToken ctx)+MoveNext()
at Anthropic.SDK.EndpointBase.HttpStreamingRequestMessages(String url, HttpMethod verb, Object postData, CancellationToken ctx)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaxToken 값이 필수인 것으로 보이는데, appsettings.json 부터 차근차근 추가할 필요가 있어 보이는데요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaxToken 값이 필수인 것으로 보이는데, appsettings.json 부터 차근차근 추가할 필요가 있어 보이는데요?

@sikutisa 아하.. 그러면 필요한 부분 살펴보고 정리해서 말씀드리겠습니다!

@justinyoo
Copy link
Contributor

@qoweh #494 PR이 머지가 됐으므로 테스트 코드는 이를 참고해서 작성해 주세욥! 촘촘하게 작성하셔야 합니다.

qoweh added 7 commits October 16, 2025 10:41
Related to : aliencube#342

* Add `MaxTokens` parameter to the Anthropic section in appsettings.json (Microsoft.Extensions.Configuration.Binder automatically converts string values to integers when binding configuration)
Relate to : aliencube#258

* Add`MaxTokens` property to AnthropicSettings
* update LanguageModelConnector to include Anthropic in unsupported list
* will be re-enabled when Anthropic PR is merged
* mark all AnthropicConnectorTests as skipped to avoid CI failures while connector is unsupported
{
/// <summary>
/// Gets or sets the API key for Anthropic Claude.
/// Gets or sets the API key for Anthropic.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20번, 25번, 30번 라인에서 Calude를 뺏다가 다시 넣었는데요, (20번줄은 다시 안 넣었네요)
Anthropic Claude 라고 하는 것보다 Anthropic으로 넣는 게 맞는 것 같은데 어떤 식으로 할까요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빼시죠!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connector Implementation & Inheritance: Anthropic Claude

3 participants