Skip to content
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

Added helper APIs for chat function/tool calls #42

Closed
wants to merge 45 commits into from

Conversation

KrzysztofCwalina
Copy link
Collaborator

@KrzysztofCwalina KrzysztofCwalina commented Jun 11, 2024

  1. Added ChatTool[] ChatTool.CreateFunctionTools(Type functionHolder) method. The method reflects on the functionHolder and builds an array of ChatTool instances corresponding to the reflected on methods.
  2. Added ChatToolCall.GetFunctionArgument, which helps with parsing function call arguments.

Users can now do:

ChatCompletionOptions options = new() {
    Tools = ChatTool.CreateFunctionTools(typeof(MyFunctions))
};

internal static class MyFunctions {
    [Description("Get the user's current location")]
    public static string GetCurrentLocation() => "San Francisco";

    [Description("Get the current weather in a given location")]
    public static string GetCurrentWeather([Description("The city and state, e.g. Boston, MA")] string location, TemperatureUnit unit) => "31 {unit}";
}

...
case nameof(MyFunctions.GetCurrentWeather): 
        var location = toolCall.GetFunctionArgument<string>("location");
        var unit = toolCall.GetFunctionArgument("unit", defaultValue: MyFunctions.TemperatureUnit.Celsius);
        string toolResult = MyFunctions.GetCurrentWeather(location, unit);
        messages.Add(new ToolChatMessage(toolCall.Id, toolResult));
        break;

stephentoub and others added 14 commits June 11, 2024 17:19
More meaningful warnings were being obscured by 1334 warnings being triggered during build. This gets it to 0 and sets TreatWarningsAsErrors. Most of getting to 0 was just via broad suppression.
* Added sample showing how to do cancellations

* fixed a bug
…verloads. (#53)

* added CancellationToken parameters to the ChatClient

* cleaned up RO extension

* added CTs to AudioClient

* added CTs to EmbeddingClient

* added CTs to FileClient

* added CTs to ModeriationClient

* added CTs to ImageClient

* added CTs to VectorStoreClient

* added CTs to AssistantClient

* fixed test sources as the callsite become ambiguous

* fixed formatting in one file

* PR feedback

* removed back the special CT overload
link to latest version package
…#33)

* Replace custom SSE reader with source for System.Net.ServerSentEvents

A stable package for the new System.Net.ServerSentEvents library isn't yet available, but until one is we can switch the code over to using a source copy.

* Add comment to csproj

* Fix NRT handling in ServerSentEvents.cs to account for lack of NRT at project level
)

* Fix non-thread-safe use of Random in MultipartFormDataBinaryContent

MultipartFormDataBinaryContent has a static Random instance that's being used without a lock. This locks around each access (an alternative would be to use and lazily-initialize on each access a [ThreadStatic] Random).

While fixing that, also improved a few things:
- We don't need to create a char[] for the boundary values; the const string can be used directly.
- For netstandard2.0, we don't need to allocate a char[]; a stackalloc'd span can be used directly.
- For .NET, we don't need a stackalloc, either; we can use string.Create and write directly into the new string instance.
- For .NET, we don't need a dedicated Random instance, either; we can use Random.Shared.
- For .NET, Random allows writing into a byte span, so we don't need the byte[] allocation either and can stackalloc it.
- For .NET, just %'ing by the string length produces as good or better code than using a manually-computed mask.

* Address PR feedback
* allow filename* use in multipart/form-data

* remove unwarranted breaking change description

* minor: align filename->fileName
KrzysztofCwalina and others added 9 commits June 21, 2024 08:47
* added support for OrganizationId and ProjectId

* changed header names to consts
…n OpenAIClientOptions is null (#85)

* Fix NullReferenceException thrown when adding the custom headers policy while OpenAIClientOptions is null

* .csproj version increment

---------

Co-authored-by: Travis Wilson <[email protected]>
Uses CodeGen version 3.0.0-beta.20240529.3
* Add 'smoke' category and parallelism to tests

* Filter in smoke tests in workflow

* Add API key check to AssistantTests cleanup

* Add 'skipInCI' test category

* Fix file tests
The current NuGet package icon has a transparent background, which makes the logo almost invisible in NuGet.org's brand new dark mode. This new icon has a white background instead.
* Update generated code (3.0.0-beta.20240628.1)

* Edit CHANGELOG
* Add simple embedding example using protocol method

* Edit CHANGELOG
annelo-msft and others added 18 commits July 16, 2024 17:17
* Add test categories per feature area
* Switch to gpt-4o-mini
* Improve reliability of a few tests
* Refactor
In [System.ClientModel 1.1.0-beta.5](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/System.ClientModel/CHANGELOG.md#110-beta5-2024-07-11), `PageableCollection<T>` was changed to `PageCollection<T>` to better align convenience and protocol methods.

This PR upgrades the OpenAI library to SCM 1.1.0-beta.5, and manually implements internal types that will be generated from TypeSpec API specification in the future.  Specifically, it:

- Updates return types that have been renamed for streaming service methods
- For service methods corresponding to paginated-collection endpoints
  - Returns `PageCollection<T>` or `AsyncPageCollection<T>` from convenience methods
  - Takes `XxCollectionOptions` types that describe the paginated collection to be returned
  - Adds "rehydration" methods that return a collection that starts where another collection type left off via a persisted rehydration token
  - Returns `IEnumerable<ClientResult>` or `IAsyncEnumerable<ClientResult>` from protocol methods, representing a collection of service responses, where each corresponds to a page of results returned from the paginated endpoint
  - Implements internal page enumerator and page token types for each paginated-endpoint operation

Types that are intended to be output by the generator have been added in a temporary folder called `To.Be.Generated`.
This PR updates the init to set.

The API will be updated in the following PR.
… very close to the issue templates found in the other repos, like openai-python. (#146)

Co-authored-by: Angelos Petropoulos <[email protected]>
@KrzysztofCwalina
Copy link
Collaborator Author

closing this for now. I will reopen a new pr totally redone for the new APIs.

@KrzysztofCwalina KrzysztofCwalina deleted the functions branch August 7, 2024 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants