Skip to content

Commit

Permalink
Merge pull request #120 from Jithesh-poojary/main
Browse files Browse the repository at this point in the history
[NEW] Environment Resource API
  • Loading branch information
v1r3n authored Jun 4, 2024
2 parents 87af751 + c649dff commit bb3dddf
Show file tree
Hide file tree
Showing 23 changed files with 1,584 additions and 172 deletions.
671 changes: 671 additions & 0 deletions Conductor/Api/EnvironmentResourceApi.cs

Large diffs are not rendered by default.

197 changes: 197 additions & 0 deletions Conductor/Api/IEnvironmentResourceApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
* Copyright 2024 Conductor Authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
using Conductor.Client;
using System;
using System.Collections.Generic;

namespace Conductor.Api
{
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public interface IEnvironmentResourceApi : IApiAccessor
{
#region Synchronous Operations
/// <summary>
/// Create or update an environment variable (requires metadata or admin role)
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body"></param>
/// <param name="key"></param>
/// <returns></returns>
void CreateOrUpdateEnvVariable(string body, string key);

/// <summary>
/// Create or update an environment variable (requires metadata or admin role)
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body"></param>
/// <param name="key"></param>
/// <returns>ApiResponse of Object(void)</returns>
ApiResponse<Object> CreateOrUpdateEnvVariableWithHttpInfo(string body, string key);
/// <summary>
/// Delete an environment variable (requires metadata or admin role)
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="key"></param>
/// <returns>string</returns>
string DeleteEnvVariable(string key);

/// <summary>
/// Delete an environment variable (requires metadata or admin role)
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="key"></param>
/// <returns>ApiResponse of string</returns>
ApiResponse<string> DeleteEnvVariableWithHttpInfo(string key);
/// <summary>
/// Get the environment value by key
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="key"></param>
/// <returns>string</returns>
string Get1(string key);

/// <summary>
/// Get the environment value by key
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="key"></param>
/// <returns>ApiResponse of string</returns>
ApiResponse<string> Get1WithHttpInfo(string key);
/// <summary>
/// List all the environment variables
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <returns>Dictionary&lt;string, string&gt;</returns>
Dictionary<string, string> GetAll();

/// <summary>
/// List all the environment variables
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <returns>ApiResponse of Dictionary&lt;string, string&gt;</returns>
ApiResponse<Dictionary<string, string>> GetAllWithHttpInfo();
#endregion Synchronous Operations
#region Asynchronous Operations
/// <summary>
/// Create or update an environment variable (requires metadata or admin role)
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body"></param>
/// <param name="key"></param>
/// <returns>Task of void</returns>
System.Threading.Tasks.Task CreateOrUpdateEnvVariableAsync(string body, string key);

/// <summary>
/// Create or update an environment variable (requires metadata or admin role)
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body"></param>
/// <param name="key"></param>
/// <returns>Task of ApiResponse</returns>
System.Threading.Tasks.Task<ApiResponse<Object>> CreateOrUpdateEnvVariableAsyncWithHttpInfo(string body, string key);
/// <summary>
/// Delete an environment variable (requires metadata or admin role)
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="key"></param>
/// <returns>Task of string</returns>
System.Threading.Tasks.Task<string> DeleteEnvVariableAsync(string key);

/// <summary>
/// Delete an environment variable (requires metadata or admin role)
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="key"></param>
/// <returns>Task of ApiResponse (string)</returns>
System.Threading.Tasks.Task<ApiResponse<string>> DeleteEnvVariableAsyncWithHttpInfo(string key);
/// <summary>
/// Get the environment value by key
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="key"></param>
/// <returns>Task of string</returns>
System.Threading.Tasks.Task<string> Get1Async(string key);

/// <summary>
/// Get the environment value by key
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="key"></param>
/// <returns>Task of ApiResponse (string)</returns>
System.Threading.Tasks.Task<ApiResponse<string>> Get1AsyncWithHttpInfo(string key);
/// <summary>
/// List all the environment variables
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <returns>Task of Dictionary&lt;string, string&gt;</returns>
System.Threading.Tasks.Task<Dictionary<string, string>> GetAllAsync();

/// <summary>
/// List all the environment variables
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
/// <returns>Task of ApiResponse (Dictionary&lt;string, string&gt;)</returns>
System.Threading.Tasks.Task<ApiResponse<Dictionary<string, string>>> GetAllAsyncWithHttpInfo();
#endregion Asynchronous Operations
}
}
12 changes: 12 additions & 0 deletions Conductor/Client/Models/Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,18 @@ public override int GetHashCode()
}
}

// Method to convert Task to TaskResult
public TaskResult ToTaskResult(TaskResult.StatusEnum status = TaskResult.StatusEnum.COMPLETED)
{
return new TaskResult
{
TaskId = this.TaskId,
WorkflowInstanceId = this.WorkflowInstanceId,
WorkerId = this.WorkerId,
Status = status
};
}

/// <summary>
/// To validate all properties of the instance
/// </summary>
Expand Down
35 changes: 17 additions & 18 deletions Conductor/Examples/Copilot/OpenAICopilot.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
* Copyright 2024 Conductor Authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
* Copyright 2024 Conductor Authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
using conductor.csharp.Client.Extensions;
using conductor.Examples;
using Conductor.Api;
Expand All @@ -33,6 +33,7 @@

namespace Conductor.Examples.Copilot
{
[WorkerTask]
public class OpenAICopilot
{
private readonly WorkflowResourceApi _workflowClient;
Expand All @@ -42,7 +43,6 @@ public class OpenAICopilot
private readonly ILogger _logger;

//consts

public const string FUNCTIONCHATBOX = "my_function_chatbot";
public const string FUNCTIONCHATBOXDESCRIPTION = "test_function_chatbot";

Expand All @@ -60,7 +60,7 @@ public OpenAICopilot()
//_metaDataClient = _orkesApiClient.GetClient<MetadataResourceApi>();
}

[WorkerTask("get_customer_list", 5, "taskDomain", 200, "workerId")]
[WorkerTask(taskType: "get_customer_list", batchSize: 5, pollIntervalMs: 200, workerId: "workerId")]
public List<Customer> GetCustomerList()
{
var customers = new List<Customer>();
Expand All @@ -80,29 +80,29 @@ public List<Customer> GetCustomerList()
return customers;
}

[WorkerTask("get_top_n", 5, "taskDomain", 200, "workerId")]
[WorkerTask(taskType: "get_top_n", batchSize: 5, pollIntervalMs: 200, workerId: "workerId")]
public List<Customer> GetTopNCustomers(int n, List<Customer> customers)
{
var sortedCustomers = customers.OrderByDescending(c => c.AnnualSpend).ToList();
var end = Math.Min(n + 1, sortedCustomers.Count);
return sortedCustomers.GetRange(1, end - 1);
}

[WorkerTask("generate_promo_code", 5, "taskDomain", 200, "workerId")]
[WorkerTask(taskType: "generate_promo_code", batchSize: 5, pollIntervalMs: 200, workerId: "workerId")]
public string GeneratePromoCode()
{
var random = new Random();
var promoCode = GenerateRandomString(random, ExampleConstants.RANDOMCHARACTERS, 5);
return promoCode;
}

[WorkerTask("send_email", 5, "taskDomain", 200, "workerId")]
[WorkerTask(taskType: "send_email", batchSize: 5, pollIntervalMs: 200, workerId: "workerId")]
public string SendEmail(List<Customer> customers, string promoCode)
{
return $"Sent {promoCode} to {customers.Count} customers";
}

[WorkerTask(taskType: "create_workflow", 5, "taskDomain", 520, "workerId")]
[WorkerTask(taskType: "create_workflow", batchSize: 5, pollIntervalMs: 520, workerId: "workerId")]
public Dictionary<string, object> CreateWorkflow(List<string> steps, Dictionary<string, object> inputs)
{
var workflow = new ConductorWorkflow()
Expand Down Expand Up @@ -169,7 +169,6 @@ public void OpenAICopilotTest()

Tasks subWorkFlow = new SubWorkflowTask("execute_workflow", new SubWorkflowParams(ExampleConstants.COPILOTEXECUTION));

//Pass task reference name once the annotation is in place
var registerWorkFlow = CreateWorkflow(steps: new List<string> { chatComplete.Output("function_parameters.steps") }, inputs: new Dictionary<string, object>
{
{ "step", "function_parameters.inputs" }
Expand Down
Loading

0 comments on commit bb3dddf

Please sign in to comment.