Skip to content

Commit

Permalink
+ Assistants:
Browse files Browse the repository at this point in the history
- renamed ToolCallType.Retrieval to FileSearch to match API update
+ RunSteps:
- added to IBetaService
- Status: noted in comment that may return "incomplete"
- RunStepList() - request param to optional
- RunStepResponse: changed to original StepDetails (with MessageCreation.MessageId) to match API responses
- NOTE: removed previous StepDetails, but could add back in commented out
  • Loading branch information
Denis Papp committed May 2, 2024
1 parent 9ef1395 commit 792e171
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 30 deletions.
4 changes: 2 additions & 2 deletions OpenAI.Playground/TestHelpers/AssistantTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static async Task RunAssistantApiTest(IOpenAIService sdk)
{
Instructions = "You are a professional assistant who provides company information. Company-related data comes from uploaded questions and does not provide vague answers, only clear answers.",
Name = "Qicha",
Tools = new List<ToolDefinition>() { ToolDefinition.DefineCodeInterpreter(), ToolDefinition.DefineRetrieval(), ToolDefinition.DefineFunction(func) },
Tools = new List<ToolDefinition>() { ToolDefinition.DefineCodeInterpreter(), ToolDefinition.DefineFileSearch(), ToolDefinition.DefineFunction(func) },
Model = Models.Gpt_3_5_Turbo_1106
});
if (assistantResult.Successful)
Expand Down Expand Up @@ -162,7 +162,7 @@ public static async Task RunHowAssistantsWorkTest(IOpenAIService sdk)
Instructions = "You are a professional assistant who provides company information. Company-related data comes from uploaded questions and does not provide vague answers, only clear answers.",
Name = "Qicha",
Model = Models.Gpt_3_5_Turbo_1106,
Tools = new List<ToolDefinition>() { ToolDefinition.DefineCodeInterpreter(), ToolDefinition.DefineRetrieval(), ToolDefinition.DefineFunction(func) },
Tools = new List<ToolDefinition>() { ToolDefinition.DefineCodeInterpreter(), ToolDefinition.DefineFileSearch(), ToolDefinition.DefineFunction(func) },
FileIds = new List<string>() { uplaodFileId }
});

Expand Down
4 changes: 2 additions & 2 deletions OpenAI.Playground/TestHelpers/RunTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static async Task RunRunCreateTest(IOpenAIService sdk)
{
Instructions = "You are a professional assistant who provides company information. Company-related data comes from uploaded questions and does not provide vague answers, only clear answers.",
Name = "Qicha",
Tools = new List<ToolDefinition>() { ToolDefinition.DefineCodeInterpreter(), ToolDefinition.DefineRetrieval(), ToolDefinition.DefineFunction(func) },
Tools = new List<ToolDefinition>() { ToolDefinition.DefineCodeInterpreter(), ToolDefinition.DefineFileSearch(), ToolDefinition.DefineFunction(func) },
Model = Models.Gpt_3_5_Turbo_1106
});
var runResult = await sdk.Beta.Runs.RunCreate(threadId, new RunCreateRequest()
Expand Down Expand Up @@ -110,7 +110,7 @@ public static async Task RunRunCancelTest(IOpenAIService sdk)
{
Instructions = "You are a professional assistant who provides company information. Company-related data comes from uploaded questions and does not provide vague answers, only clear answers.",
Name = "Qicha",
Tools = new List<ToolDefinition>() { ToolDefinition.DefineCodeInterpreter(), ToolDefinition.DefineRetrieval(), ToolDefinition.DefineFunction(func) },
Tools = new List<ToolDefinition>() { ToolDefinition.DefineCodeInterpreter(), ToolDefinition.DefineFileSearch(), ToolDefinition.DefineFunction(func) },
Model = Models.Gpt_3_5_Turbo_1106
});
var runCreateResult = await sdk.Beta.Runs.RunCreate(threadId, new RunCreateRequest()
Expand Down
2 changes: 2 additions & 0 deletions OpenAI.SDK/Interfaces/IBetaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface IBetaService
public IThreadService Threads { get; }

public IRunService Runs { get; }

public IRunStepService RunSteps { get; }
}
2 changes: 1 addition & 1 deletion OpenAI.SDK/Interfaces/IRunStepService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IRunStepService
/// <param name="request">Paging</param>
/// <param name="cancellationToken"></param>
/// <returns>A list of [run step](/docs/api-reference/runs/step-object) objects.</returns>
Task<RunStepListResponse> RunStepsList(string threadId, string runId, RunStepListRequest request, CancellationToken cancellationToken = default);
Task<RunStepListResponse> RunStepsList(string threadId, string runId, RunStepListRequest? request = null, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves a run step.
Expand Down
2 changes: 2 additions & 0 deletions OpenAI.SDK/Managers/OpenAIBetaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public partial class OpenAIService : IBetaService
public IThreadService Threads => this;

public IRunService Runs => this;

public IRunStepService RunSteps => this;
}
2 changes: 1 addition & 1 deletion OpenAI.SDK/Managers/OpenAIRunStepService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OpenAI.Managers;
public partial class OpenAIService : IRunStepService
{
/// <inheritdoc />
public async Task<RunStepListResponse> RunStepsList(string threadId, string runId, RunStepListRequest request, CancellationToken cancellationToken = default)
public async Task<RunStepListResponse> RunStepsList(string threadId, string runId, RunStepListRequest? request = null, CancellationToken cancellationToken = default)
{
return await _httpClient.GetReadAsAsync<RunStepListResponse>(_endpointProvider.RunStepList(threadId, runId,request), cancellationToken);
}
Expand Down
10 changes: 9 additions & 1 deletion OpenAI.SDK/ObjectModels/RequestModels/ToolDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,16 @@ public object? FunctionCalculated
{
Type = StaticValues.AssistantsStatics.ToolCallTypes.CodeInterpreter,
};

[Obsolete("Retrieval is now called FileSearch")]
public static ToolDefinition DefineRetrieval() => new()
{
Type = StaticValues.AssistantsStatics.ToolCallTypes.Retrieval,
Type = StaticValues.AssistantsStatics.ToolCallTypes.FileSearch,
};

public static ToolDefinition DefineFileSearch() => new()
{
Type = StaticValues.AssistantsStatics.ToolCallTypes.FileSearch,
};

}
39 changes: 17 additions & 22 deletions OpenAI.SDK/ObjectModels/ResponseModels/RunStepListResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,13 @@ public record RunStepResponse : BaseResponse, IOpenAiModels.IId, IOpenAiModels.I
public string Type { get; set; }

/// <summary>
/// The status of the run step, which can be either `in_progress`, `cancelled`, `failed`, `completed`, or `expired`.
/// The status of the run step, which can be either `in_progress`, `cancelled`, `failed`, `completed`, `expired`, or 'incomplete'.
/// </summary>
[JsonPropertyName("status")]
public string Status { get; set; }

public class StepDetailsComplexType
{
[JsonIgnore]
public StepDetails StepDetails1 { get; set; }

[JsonIgnore]
public StepDetails StepDetails2 { get; set; }
}

/// <summary>
/// The details of the run step.
/// </summary>
[JsonConverter(typeof(ComplexTypeConverter<StepDetailsComplexType>))]
[JsonPropertyName("step_details")]
public StepDetailsComplexType StepDetails { get; set; }
public RunStepDetails? StepDetails { get; set; }

/// <summary>
/// The last error associated with this run step. Will be `null` if there are no errors.
Expand Down Expand Up @@ -127,17 +114,25 @@ public class StepDetailsComplexType
[JsonPropertyName("usage")]
public UsageResponse? Usage { get; set; }
}
public record StepDetails

public record RunStepDetails
{
/// <summary>
/// Always `tool_calls`.
/// Always message_creation.
/// </summary>
[JsonPropertyName("type")]
public string Type { get; set; }

/// <summary>
/// An array of tool calls the run step was involved in. These can be associated with one of three types of tools: `code_interpreter`, `file_search`, or `function`.
/// </summary>
[JsonPropertyName("tool_calls")]
public List<ToolCall> ToolCalls { get; set; }
[JsonPropertyName("message_creation")]
public RunStepMessageCreation MessageCreation { get; set; }

public class RunStepMessageCreation
{
[JsonPropertyName("message_id")]
public string MessageId { get; set; }
}
}




2 changes: 1 addition & 1 deletion OpenAI.SDK/ObjectModels/StaticValueHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static class AssistantsStatics
public static class ToolCallTypes
{
public static string CodeInterpreter => "code_interpreter";
public static string Retrieval => "retrieval";
public static string FileSearch => "file_search";
public static string Function => "function";
}

Expand Down

0 comments on commit 792e171

Please sign in to comment.