Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dotnet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

### Bugs Fixed

- Fixed a newly introduced bug ([#185](https://github.com/openai/openai-dotnet/pull/185)) where providing `OpenAIClientOptions` to a top-level `OpenAIClient` did not carry over to scenario clients (e.g. `ChatClient`) created via that top-level client

### Other Changes

- Removed the version path parameter "v1" from the default endpoint URL. (commit_hash)
Expand Down
1 change: 1 addition & 0 deletions .dotnet/src/Custom/OpenAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public OpenAIClient(ApiKeyCredential credential, OpenAIClientOptions options)

_pipeline = OpenAIClient.CreatePipeline(credential, options);
_endpoint = OpenAIClient.GetEndpoint(options);
_options = options;
}

// CUSTOM: Added protected internal constructor that takes a ClientPipeline.
Expand Down
25 changes: 25 additions & 0 deletions .dotnet/tests/Chat/ChatSmokeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,29 @@ public void SerializeMessagesWithNullProperties()
FunctionChatMessage deserializedMessage = ModelReaderWriter.Read<FunctionChatMessage>(serializedMessage);
#pragma warning restore
}

[Test]
public void TopLevelClientOptionsPersistence()
{
MockPipelineTransport mockTransport = new(BinaryData.FromString("{}"), BinaryData.FromString("{}"));
OpenAIClientOptions options = new()
{
Transport = mockTransport,
Endpoint = new Uri("https://api.openai.com/expected/test/endpoint"),
};
Uri observedEndpoint = null;
options.AddPolicy(new TestPipelinePolicy(message =>
{
observedEndpoint = message?.Request?.Uri;
Console.WriteLine($"foo: {message.Request.Uri.AbsoluteUri}");
}),
PipelinePosition.PerCall);

OpenAIClient topLevelClient = new(new("mock-credential"), options);
ChatClient firstClient = topLevelClient.GetChatClient("mock-model");
ClientResult first = firstClient.CompleteChat("Hello, world");

Assert.That(observedEndpoint, Is.Not.Null);
Assert.That(observedEndpoint.AbsoluteUri, Does.Contain("expected/test/endpoint"));
}
}