-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry pick branch 'genexuslabs:embedding-data-type' into beta
- Loading branch information
1 parent
abec843
commit f26685f
Showing
7 changed files
with
121 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using GeneXus.Procedure; | ||
using GeneXus.Utils; | ||
|
||
namespace GeneXus.AI | ||
{ | ||
internal class GXAgent : GXProcedure | ||
{ | ||
protected string CallAssistant( string caller, GXProperties properties, CallResult response) | ||
{ | ||
return string.Empty; | ||
} | ||
} | ||
} |
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
75 changes: 75 additions & 0 deletions
75
dotnet/src/dotnetcore/Providers/AI/Services/EmbeddingService.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,75 @@ | ||
using System; | ||
using System.ClientModel; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using GeneXus.Configuration; | ||
using GeneXus.Utils; | ||
using OpenAI; | ||
using OpenAI.Embeddings; | ||
namespace GeneXus.AI | ||
{ | ||
internal class EmbeddingService : IEmbeddingService | ||
{ | ||
protected OpenAIClient _openAIClient; | ||
protected string API_KEY; | ||
protected virtual string DEFAULT_PROVIDER => "https://api.saia.ai/embeddings"; | ||
protected virtual string DEFAULT_API_KEY => "apitokenfortest_"; | ||
protected const string AI_PROVIDER = "AI_PROVIDER"; | ||
protected const string AI_PROVIDER_API_KEY = "AI_PROVIDER_API_KEY"; | ||
private static volatile EmbeddingService m_instance; | ||
private static object m_SyncRoot = new Object(); | ||
|
||
internal EmbeddingService() | ||
{ | ||
string val; | ||
Uri providerUri = new Uri(DEFAULT_PROVIDER); | ||
API_KEY = DEFAULT_API_KEY; | ||
if (Config.GetValueOf(AI_PROVIDER, out val)) | ||
{ | ||
providerUri = new Uri(val); | ||
} | ||
if (Config.GetValueOf(AI_PROVIDER_API_KEY, out val)) | ||
{ | ||
API_KEY = val; | ||
} | ||
OpenAIClientOptions options = new OpenAIClientOptions() | ||
{ | ||
Endpoint = providerUri | ||
}; | ||
|
||
_openAIClient = new OpenAIClient(new ApiKeyCredential(API_KEY), options); | ||
} | ||
public async Task<ReadOnlyMemory<float>> GenerateEmbeddingAsync(string model, int dimensions, string input) | ||
{ | ||
OpenAIEmbeddingCollection data = await GenerateEmbeddingAsync(model, dimensions, new List<string> { input }); | ||
return data.First().ToFloats(); | ||
} | ||
async Task<OpenAIEmbeddingCollection> GenerateEmbeddingAsync(string model, int dimensions, IEnumerable<string> input) | ||
{ | ||
EmbeddingClient client = _openAIClient.GetEmbeddingClient(model); | ||
EmbeddingGenerationOptions options = new EmbeddingGenerationOptions() { Dimensions = dimensions }; | ||
ClientResult<OpenAIEmbeddingCollection> clientResult = await client.GenerateEmbeddingsAsync(input, options); | ||
|
||
return clientResult.Value; | ||
} | ||
internal static EmbeddingService Instance | ||
{ | ||
get | ||
{ | ||
if (m_instance == null) | ||
{ | ||
lock (m_SyncRoot) | ||
{ | ||
if (m_instance == null) | ||
m_instance = new EmbeddingService(); | ||
} | ||
} | ||
return m_instance; | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
} |
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