Skip to content

Commit

Permalink
Merge pull request #113 from Chaithra-07/main
Browse files Browse the repository at this point in the history
Code samples to test Workflow Execution
  • Loading branch information
v1r3n authored Apr 17, 2024
2 parents bf4c1fc + 57cba33 commit e86fafc
Show file tree
Hide file tree
Showing 38 changed files with 3,019 additions and 528 deletions.
10 changes: 10 additions & 0 deletions Conductor/Api/IIntegrationResourceApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ public interface IIntegrationResourceApi : IApiAccessor
/// <returns>Task of Integration</returns>
ThreadTask.Task<Integration> GetIntegrationProviderAsync(string name);

/// <summary>
/// Get Integration provider definitions
/// </summary>
/// <remarks>
///
/// </remarks>
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <returns>Task of List<IntegrationDef></returns>
ThreadTask.Task<List<IntegrationDef>> GetIntegrationProviderDefsAsync();

/// <summary>
/// Get all Integrations Providers
/// </summary>
Expand Down
24 changes: 24 additions & 0 deletions Conductor/Api/IntegrationResourceApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,18 @@ public async System.Threading.Tasks.Task<ApiResponse<Integration>> GetIntegratio
localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)),
(Integration)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(Integration)));
}

/// <summary>
/// Get Integration provider definitions
/// </summary>
/// <exception cref="Conductor.Client.ApiException">Thrown when fails to make API call</exception>
/// <returns>List<IntegrationDef></returns>
public List<IntegrationDef> GetIntegrationProviderDefs()
{
ApiResponse<List<IntegrationDef>> localVarResponse = GetIntegrationProviderDefsWithHttpInfo();
return localVarResponse.Data;
}

/// <summary>
/// Get Integration provider definitions
/// </summary>
Expand Down Expand Up @@ -1456,6 +1468,18 @@ public ApiResponse<List<IntegrationDef>> GetIntegrationProviderDefsWithHttpInfo(
(List<IntegrationDef>)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(List<IntegrationDef>)));
}

/// <summary>
/// Get Integration provider definitions
/// </summary>
/// <exception cref="Conductor.Client.ApiException">Thrown when fails to make API call</exception>
/// <returns>Task of List<IntegrationDef></returns>
public async System.Threading.Tasks.Task<List<IntegrationDef>> GetIntegrationProviderDefsAsync()
{
ApiResponse<List<IntegrationDef>> localVarResponse = await GetIntegrationProviderDefsAsyncWithHttpInfo();
return localVarResponse.Data;

}

/// <summary>
/// Get Integration provider definitions
/// </summary>
Expand Down
51 changes: 39 additions & 12 deletions Conductor/Client/Ai/Orchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ public string TestPromptTemplate(PromptTemplateTestRequest promptTemplateTestReq
/// <exception cref="Exception"></exception>
public void AddAIIntegration(string aiIntegrationName, LLMProviderEnum provider, List<string> models, string description, IntegrationConfig config, bool overwrite = false)
{
IntegrationUpdate details = null;
try
{
var details = new IntegrationUpdate();
details = new IntegrationUpdate();
details.Configuration = config.ToDictionary();
details.Type = provider.ToString();
details.Category = IntegrationUpdate.CategoryEnum.AIMODEL;
Expand All @@ -138,20 +139,20 @@ public void AddAIIntegration(string aiIntegrationName, LLMProviderEnum provider,
var existingIntegration = _integrationResourceApi.GetIntegrationProvider(aiIntegrationName);
if (existingIntegration == null || overwrite)
_integrationResourceApi.SaveIntegrationProvider(details, aiIntegrationName);
foreach (var model in models)
{
var apiDetails = new IntegrationApiUpdate();
apiDetails.Enabled = true;
apiDetails.Description = description;
var existingIntegrationApi = _integrationResourceApi.GetIntegrationApi(aiIntegrationName, model);
if (existingIntegrationApi == null || overwrite)
_integrationResourceApi.SaveIntegrationApi(apiDetails, model, aiIntegrationName);
}
SaveIntegrationApis(aiIntegrationName, models, description, overwrite);
}
catch (Exception ex)
{
string errorMessage = string.Format(Constants.ADD_AI_INTEGRATION_ERROR_MESSAGE, ex.Message);
throw new Exception(errorMessage, ex);
if (ex.Message.Contains("404") && details != null)
{
_integrationResourceApi.SaveIntegrationProvider(details, aiIntegrationName);
SaveIntegrationApis(aiIntegrationName, models, description, overwrite);
}
else
{
string errorMessage = string.Format(Constants.ADD_AI_INTEGRATION_ERROR_MESSAGE, ex.Message);
throw new Exception(errorMessage, ex);
}
}
}

Expand Down Expand Up @@ -233,5 +234,31 @@ public Dictionary<string, string> GetTokenUsed(string aiIntegration)
throw new Exception(errorMessage, ex);
}
}

/// <summary>
/// Method to save IntegrationApi's
/// </summary>
/// <param name="aiIntegrationName"></param>
/// <param name="models"></param>
/// <param name="description"></param>
/// <param name="overwrite"></param>
private void SaveIntegrationApis(string aiIntegrationName, List<string> models, string description, bool overwrite)
{
foreach (var model in models)
{
var apiDetails = new IntegrationApiUpdate
{
Enabled = true,
Description = description
};

var existingIntegrationApi = _integrationResourceApi.GetIntegrationApi(aiIntegrationName, model);

if (existingIntegrationApi == null || overwrite)
{
_integrationResourceApi.SaveIntegrationApi(apiDetails, model, aiIntegrationName);
}
}
}
}
}
4 changes: 1 addition & 3 deletions Conductor/Client/ApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Conductor.Client.Models;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
Expand All @@ -8,7 +6,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand Down Expand Up @@ -118,6 +115,7 @@ private RestRequest PrepareRequest(
String contentType)
{
var request = new RestRequest(path, method);
request.AddHeader("Accept-Encoding", "gzip");

// add path parameter, if any
foreach (var param in pathParams)
Expand Down
93 changes: 93 additions & 0 deletions Conductor/Client/Models/StateChangeConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace Conductor.Client.Models
{
public class StateChangeConfig
{
/// <summary>
/// Gets or sets Type
/// </summary>
public List<StateChangeEventType> Type { get; set; }

/// <summary>
/// Gets or sets Events
/// </summary>
public List<StateChangeEvent> Events { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="StateChangeConfig" /> class.
/// </summary>
/// <param name="eventType"></param>
/// <param name="events"></param>
public StateChangeConfig(List<StateChangeEventType> eventType = null, List<StateChangeEvent> events = null)
{
Type = eventType;
Events = events;
}
}
}

/// <summary>
/// Defines StateChangeEventType
/// </summary>

[JsonConverter(typeof(StringEnumConverter))]
public enum StateChangeEventType
{
/// <summary>
/// Enum OnScheduled for value: onScheduled
/// </summary>
[EnumMember(Value = "onScheduled")]
OnScheduled = 0,

/// <summary>
/// Enum OnStart for value: onStart
/// </summary>
[EnumMember(Value = "onStart")]
OnStart = 1,

/// <summary>
/// Enum OnFailed for value: onFailed
/// </summary>
[EnumMember(Value = "onFailed")]
OnFailed = 2,

/// <summary>
/// Enum OnSuccess for value: onSuccess
/// </summary>
[EnumMember(Value = "onSuccess")]
OnSuccess = 3,

/// <summary>
/// Enum OnCancelled for value: onCancelled
/// </summary>
[EnumMember(Value = "onCancelled")]
OnCancelled = 4
}

public class StateChangeEvent
{
/// <summary>
/// Gets or sets Type
/// </summary>
public string Type { get; set; }

/// <summary>
/// Gets or sets Payload
/// </summary>
public Dictionary<string, object> Payload { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="StateChangeEvent" /> class
/// </summary>
/// <param name="type"></param>
/// <param name="payload"></param>
public StateChangeEvent(string type, Dictionary<string, object> payload)
{
Type = type;
Payload = payload;
}
}
Loading

0 comments on commit e86fafc

Please sign in to comment.