Skip to content

Commit

Permalink
Includes code samples for testing AI Integration and workflow execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaithra-07 committed Apr 11, 2024
1 parent fa032b8 commit 57cba33
Show file tree
Hide file tree
Showing 36 changed files with 2,985 additions and 528 deletions.
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 57cba33

Please sign in to comment.