-
-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #561 from betalgo/dev
8.2.2
- Loading branch information
Showing
85 changed files
with
3,324 additions
and
581 deletions.
There are no files selected for viewing
This file contains 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 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,17 @@ | ||
How Assistants work Beta | ||
The Assistants API is designed to help developers build powerful AI assistants capable of performing a variety of tasks. | ||
|
||
The Assistants API is in beta and we are actively working on adding more functionality. Share your feedback in our Developer Forum! | ||
Assistants can call OpenAI�s models with specific instructions to tune their personality and capabilities. | ||
Assistants can access multiple tools in parallel. These can be both OpenAI-hosted tools � like code_interpreter and file_search � or tools you build / host (via function calling). | ||
Assistants can access persistent Threads. Threads simplify AI application development by storing message history and truncating it when the conversation gets too long for the model�s context length. You create a Thread once, and simply append Messages to it as your users reply. | ||
Assistants can access files in several formats � either as part of their creation or as part of Threads between Assistants and users. When using tools, Assistants can also create files (e.g., images, spreadsheets, etc) and cite files they reference in the Messages they create. | ||
Objects | ||
Assistants object architecture diagram | ||
|
||
OBJECT WHAT IT REPRESENTS | ||
Assistant Purpose-built AI that uses OpenAI�s models and calls tools | ||
Thread A conversation session between an Assistant and a user. Threads store Messages and automatically handle truncation to fit content into a model�s context. | ||
Message A message created by an Assistant or a user. Messages can include text, images, and other files. Messages stored as a list on the Thread. | ||
Run An invocation of an Assistant on a Thread. The Assistant uses its configuration and the Thread�s Messages to perform tasks by calling models and tools. As part of a Run, the Assistant appends Messages to the Thread. | ||
Run Step A detailed list of steps the Assistant took as part of a Run. An Assistant can call tools or create Messages during its run. Examining Run Steps allows you to introspect how the Assistant is getting to its final results. |
175 changes: 175 additions & 0 deletions
175
OpenAI.Playground/TestHelpers/AssistantHelpers/AssistantTestHelper.cs
This file contains 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,175 @@ | ||
using OpenAI.Interfaces; | ||
using OpenAI.ObjectModels; | ||
using OpenAI.ObjectModels.RequestModels; | ||
using OpenAI.ObjectModels.SharedModels; | ||
using OpenAI.Playground.ExtensionsAndHelpers; | ||
|
||
namespace OpenAI.Playground.TestHelpers.AssistantHelpers; | ||
internal static partial class AssistantTestHelper | ||
{ | ||
internal static class BasicsTestHelper | ||
{ | ||
private const string Instruction = "You are a personal math tutor. When asked a question, write and run Python code to answer the question."; | ||
private const string Name = "Math Tutor"; | ||
private static string? CreatedAssistantId { get; set; } | ||
|
||
public static async Task RunTests(IOpenAIService openAI) | ||
{ | ||
ConsoleExtensions.WriteLine("Assistant Basics Testing is starting:", ConsoleColor.Blue); | ||
await CreateAssistant(openAI); | ||
await ListAssistants(openAI); | ||
await RetrieveAssistant(openAI); | ||
await ModifyAssistantTask(openAI); | ||
await DeleteAssistant(openAI); | ||
} | ||
|
||
public static async Task CreateAssistant(IOpenAIService openAI) | ||
{ | ||
ConsoleExtensions.WriteLine("Create Assistant Testing is starting:", ConsoleColor.Cyan); | ||
|
||
var result = await openAI.Beta.Assistants.AssistantCreate(new() | ||
{ | ||
Instructions = Instruction, | ||
Name = Name, | ||
Tools = [ToolDefinition.DefineCodeInterpreter()], | ||
Model = Models.Gpt_4_turbo | ||
}); | ||
|
||
if (result.Successful) | ||
{ | ||
CreatedAssistantId = result.Id; | ||
ConsoleExtensions.WriteLine($"Assistant Created Successfully with ID: {result.Id}", ConsoleColor.Green); | ||
} | ||
else | ||
{ | ||
ConsoleExtensions.WriteError(result.Error); | ||
} | ||
} | ||
|
||
public static async Task ListAssistants(IOpenAIService openAI) | ||
{ | ||
ConsoleExtensions.WriteLine("List Assistants Testing is starting:", ConsoleColor.Cyan); | ||
var allAssistants = new List<AssistantResponse>(); | ||
var hasMore = true; | ||
var lastId = string.Empty; | ||
while (hasMore) | ||
{ | ||
var result = await openAI.Beta.Assistants.AssistantList(new() { After = lastId, Limit = 5 }); | ||
if (result.Successful) | ||
{ | ||
if (result.Data != null) | ||
{ | ||
allAssistants.AddRange(result.Data); | ||
} | ||
|
||
hasMore = result.HasMore; | ||
lastId = result.LastId; | ||
} | ||
else | ||
{ | ||
ConsoleExtensions.WriteError(result.Error); | ||
return; | ||
} | ||
} | ||
|
||
foreach (var assistant in allAssistants) | ||
{ | ||
Console.WriteLine($"ID: {assistant.Id}, Name: {assistant.Name}"); | ||
} | ||
|
||
if (allAssistants.FirstOrDefault(r => r.Id == CreatedAssistantId) != null) | ||
{ | ||
ConsoleExtensions.WriteLine("List Assistants Test is successful.", ConsoleColor.Green); | ||
} | ||
else | ||
{ | ||
ConsoleExtensions.WriteLine("List Assistants Test is failed.", ConsoleColor.Red); | ||
} | ||
} | ||
|
||
public static async Task RetrieveAssistant(IOpenAIService openAI) | ||
{ | ||
ConsoleExtensions.WriteLine("Retrieve Assistant Testing is starting:", ConsoleColor.Cyan); | ||
if (string.IsNullOrWhiteSpace(CreatedAssistantId)) | ||
{ | ||
ConsoleExtensions.WriteLine("Assistant Id is not found. Please create an assistant first.", ConsoleColor.Red); | ||
return; | ||
} | ||
|
||
var result = await openAI.Beta.Assistants.AssistantRetrieve(CreatedAssistantId); | ||
if (result.Successful) | ||
{ | ||
ConsoleExtensions.WriteLine("Retrieve Assistant Test is successful.", ConsoleColor.Green); | ||
} | ||
else | ||
{ | ||
ConsoleExtensions.WriteError(result.Error); | ||
} | ||
} | ||
|
||
public static async Task ModifyAssistantTask(IOpenAIService openAI) | ||
{ | ||
ConsoleExtensions.WriteLine("Modify Assistant Testing is starting:", ConsoleColor.Cyan); | ||
if (string.IsNullOrWhiteSpace(CreatedAssistantId)) | ||
{ | ||
ConsoleExtensions.WriteLine("Assistant Id is not found. Please create an assistant first.", ConsoleColor.Red); | ||
return; | ||
} | ||
|
||
const string newName = Name + "2"; | ||
const string newInstructions = "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files."; | ||
var result = await openAI.Beta.Assistants.AssistantModify(CreatedAssistantId, new() | ||
{ | ||
Instructions = newInstructions, | ||
Name = newName, | ||
Tools = [ToolDefinition.DefineFileSearch()], | ||
Model = Models.Gpt_4_turbo | ||
}); | ||
|
||
if (result.Successful) | ||
{ | ||
if (result is { Name: newName, Instructions: newInstructions } && result.Tools.First() | ||
.Type == ToolDefinition.DefineFileSearch() | ||
.Type) | ||
{ | ||
ConsoleExtensions.WriteLine("Modify Assistant Test is successful.", ConsoleColor.Green); | ||
} | ||
else | ||
{ | ||
ConsoleExtensions.WriteLine("Modify Assistant Test is failed.", ConsoleColor.Red); | ||
} | ||
} | ||
else | ||
{ | ||
ConsoleExtensions.WriteError(result.Error); | ||
} | ||
} | ||
|
||
public static async Task DeleteAssistant(IOpenAIService openAI) | ||
{ | ||
ConsoleExtensions.WriteLine("Delete Assistant Testing is starting:", ConsoleColor.Cyan); | ||
if (string.IsNullOrWhiteSpace(CreatedAssistantId)) | ||
{ | ||
ConsoleExtensions.WriteLine("Assistant Id is not found. Please create an assistant first.", ConsoleColor.Red); | ||
return; | ||
} | ||
|
||
var result = await openAI.Beta.Assistants.AssistantDelete(CreatedAssistantId); | ||
if (result.Successful) | ||
{ | ||
if (result.IsDeleted) | ||
{ | ||
ConsoleExtensions.WriteLine("Delete Assistant Test is successful.", ConsoleColor.Green); | ||
} | ||
else | ||
{ | ||
ConsoleExtensions.WriteLine("Delete Assistant Test is failed.", ConsoleColor.Red); | ||
} | ||
} | ||
else | ||
{ | ||
ConsoleExtensions.WriteError(result.Error); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.