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 to simplify the basic getting-started usage #17

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
added similar helpers for assistants
  • Loading branch information
KrzysztofCwalina committed Jun 10, 2024
commit 5c30ea2c1a4b68c4f142f6b1f5c06c4a906a4d2e
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,7 @@ Next, create a new thread. For illustrative purposes, you could include an initi
```csharp
ThreadCreationOptions threadOptions = new()
{
InitialMessages =
{
new ThreadInitializationMessage(new List<MessageContent>()
{
MessageContent.FromText("How well did product 113045 sell in February? Graph its trend over time."),
}),
},
InitialMessages = { "How well did product 113045 sell in February? Graph its trend over time." }
};

ThreadRun threadRun = assistantClient.CreateThreadAndRun(assistant.Id, threadOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,7 @@ public void Example01_RetrievalAugmentedGeneration()
// Now we'll create a thread with a user query about the data already associated with the assistant, then run it
ThreadCreationOptions threadOptions = new()
{
InitialMessages =
{
new ThreadInitializationMessage(new List<MessageContent>()
{
MessageContent.FromText("How well did product 113045 sell in February? Graph its trend over time."),
}),
},
InitialMessages = { "How well did product 113045 sell in February? Graph its trend over time." }
};

ThreadRun threadRun = assistantClient.CreateThreadAndRun(assistant.Id, threadOptions);
Expand Down
2 changes: 1 addition & 1 deletion examples/Assistants/Example02_FunctionCalling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ string GetCurrentWeather(string location, string unit = "celsius")
// Create a thread with an initial user message and run it.
ThreadCreationOptions threadOptions = new()
{
InitialMessages = { new ThreadInitializationMessage(["What's the weather like today?"]), },
InitialMessages = { "What's the weather like today?" }
};

ThreadRun run = client.CreateThreadAndRun(assistant.Id, threadOptions);
Expand Down
2 changes: 1 addition & 1 deletion examples/Assistants/Example02_FunctionCallingAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ string GetCurrentWeather(string location, string unit = "celsius")
// Create a thread with an initial user message and run it.
ThreadCreationOptions threadOptions = new()
{
InitialMessages = { new ThreadInitializationMessage(["What's the weather like today?"]), },
InitialMessages = { "What's the weather like today?" }
};

ThreadRun run = await client.CreateThreadAndRunAsync(assistant.Id, threadOptions);
Expand Down
11 changes: 4 additions & 7 deletions examples/Assistants/Example04_AllTheTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,10 @@ static string GetNameOfFamilyMember(string relation)
{
InitialMessages =
{
new ThreadInitializationMessage(
[
"Create a graph of a line with a slope that's my father's favorite number "
+ "and an offset that's my mother's favorite number.",
"Include people's names in your response and cite where you found them."
]),
},
"Create a graph of a line with a slope that's my father's favorite number "
+ "and an offset that's my mother's favorite number.",
"Include people's names in your response and cite where you found them."
}
});

ThreadRun run = client.CreateRun(thread, assistant);
Expand Down
11 changes: 11 additions & 0 deletions src/Custom/Assistants/ThreadInitializationMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public ThreadInitializationMessage(IEnumerable<MessageContent> content) : base(c
internal ThreadInitializationMessage(MessageCreationOptions baseOptions)
: base(baseOptions.Role, baseOptions.Content, baseOptions.Attachments, baseOptions.Metadata, null)
{ }

/// <summary>
/// Implicitly creates a new instance of <see cref="ThreadInitializationMessage"/> from a single item of plain text
/// content.
/// </summary>
/// <remarks>
/// Using a <see cref="string"/> in the position of a <see cref="ThreadInitializationMessage"/> is equivalent to
/// using the <see cref="ThreadInitializationMessage(IEnumerable{MessageContent})"/> constructor with a single
/// <see cref="MessageContent.FromText(string)"/> content instance.
/// </remarks>
public static implicit operator ThreadInitializationMessage(string initializationMessage) => new([initializationMessage]);
}
10 changes: 10 additions & 0 deletions src/Custom/Chat/ChatMessageContentPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,14 @@ public static ChatMessageContentPart CreateImageMessageContentPart(BinaryData im
/// </summary>
/// <returns></returns>
public override string ToString() => Text;

/// <summary>
/// Implicitly creates a new <see cref="ChatMessageContentPart"/> instance from an item of plain text.
/// </summary>
/// <remarks>
/// Using a <see cref="string"/> in the position of a <see cref="ChatMessageContentPart"/> is equivalent to
/// calling the <see cref="CreateTextMessageContentPart(string)"/> method.
/// </remarks>
/// <param name="content"> The text content to use as this content part. </param>
public static implicit operator ChatMessageContentPart(string content) => new(content);
}
Loading