GenAI.BuildingBlocks 2.0.0

dotnet add package GenAI.BuildingBlocks --version 2.0.0                
NuGet\Install-Package GenAI.BuildingBlocks -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GenAI.BuildingBlocks" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GenAI.BuildingBlocks --version 2.0.0                
#r "nuget: GenAI.BuildingBlocks, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GenAI.BuildingBlocks as a Cake Addin
#addin nuget:?package=GenAI.BuildingBlocks&version=2.0.0

// Install GenAI.BuildingBlocks as a Cake Tool
#tool nuget:?package=GenAI.BuildingBlocks&version=2.0.0                

Documentação do Projeto

Este documento fornece uma visão geral de como trabalhar com classes e operações específicas, incluindo a criação de queries Mongo com linguagem natural e a interação com o Microsoft Teams.

1. Criação de Classe que Representa uma Coleção

A classe a seguir representa uma coleção, com atributos utilizados como prompts para geração de queries Mongo com linguagem natural. Utilize o atributo "RuleConditionPrompt" tanto no nível de classe como nas propriedades para criar seu próprio prompt:

[RuleConditionPrompt(Rule = "Regra 100", Condition = @"Lembre-se: você deve retornar todos os campos relacionados na coleção cadastro_usuarios.")]
[RuleConditionPrompt(Rule = "Regra 101", Condition = @"Lembre-se da regra 100.")]
[Display(Name = "Cadastro de Usuários")]
[BsonCollection("cadastro_usuarios_teste_hml")]
public class User : BaseModel
{
    [Display(Name = "ID")]
    [JsonProperty(PropertyName = "_id")]
    [BsonRepresentation(BsonType.String)]
    public ObjectId Id { get; set; }

    [Display(Name = "E-Mail")]
    [JsonProperty(PropertyName = "Mail")]
    public string Mail { get; set; }
}

2. Exemplo de geração de query com linguagem natural baseando-se na classe User

Para gerar uma query com linguagem natural baseando-se na classe User, siga os passos abaixo:

var _mongoQueryBuilder = InternalConfigurationDI.GetService<IMongoQueryBuilder>();
var messageUser = "Liste todos os usuários";

var messagesHistory = new List<Message>();
messagesHistory.Add(messageUser);

ParametersOpenAI PoAI = new ParametersOpenAI(true); // true para OpenAI da Azure, false para outro serviço da OpenAI
PoAI.MessageUser = messageUser;
PoAI.ApiVersion = "sua api version";
PoAI.ApiKey = "sua api key";
PoAI.Endpoint = "endpoint da sua OpenAI";
PoAI.DeploymentName = "Seu DeploymentName";
PoAI.Messages = new List<Message>();
PoAI.Messages.AddRange(messagesHistory);

var queryMongoIA = await _mongoQueryBuilder.GetQueryFromIA<User>(PoAI);
var queryFormated = queryMongoIA?.Replace("", "").Replace('', ' ');
var response = await _mongoCommand.GetRunCommandAsyncToTable(queryFormated);

3. Exemplo de utilização do BaseMongoRepository para operações de repositório

O uso do BaseMongoRepository permite que você trabalhe com Linq para realizar operações de repositório:

public class UserRepository : BaseMongoDBRepository<User>
{
    public UserRepository(string connectionString, string databaseName) : base(connectionString, databaseName)
    {
    }
}

4. Envio de mensagens ao Teams

Para enviar mensagens ao Microsoft Teams, obtenha primeiro o MicrosoftAppId, MicrosoftAppPassword e ConversationId do seu aplicativo. Em seguida, obtenha a instância do TeamsUtilities:

_teamsUtilities = InternalConfigurationDI.GetService<TeamsUtilities>(microsoftAppId, microsoftAppPassword, conversationId);
var result = await _teamsUtilities.SendMessageToTeams("sua mensagem");

5. Comunicação com OpenAI para obter respostas

Você pode enviar perguntas para a OpenAI e obter respostas:

var messageUser = "Quem descobriu o Brasil?";

var messagesHistory = new List<Message>();
messagesHistory.Add(messageUser);

ParametersOpenAI PoAI = new ParametersOpenAI(true); // true para OpenAI da Azure, false para outro serviço da OpenAI
PoAI.MessageUser = messageUser;
PoAI.ApiVersion = "sua api version";
PoAI.ApiKey = "sua api key";
PoAI.Endpoint = "endpoint da sua OpenAI";
PoAI.DeploymentName = "Seu DeploymentName";
PoAI.Messages = new List<Message>();
PoAI.Messages.AddRange(messagesHistory);

var OpenAISDK = InternalConfigurationDI.GetService<IOpenaiSdkService>();
var completion = await OpenAISDK.GetGenAICompletionAsync(PoAI);
var response = completion.Value.Choices[0].Message.Content;

6. Você pode configurar a temperatura e criatividade das respostas

O objeto ParametersOpenAI tem seus valores padrões de temperatura, penalidade, tokens e que podem ser modificados:

        public float? Temperature { get; set; } = 0.2f;
        /// <summary>
        /// Default is 2200
        /// </summary>
        public int? MaxTokens { get; set; } = 2200;
        /// <summary>
        /// Default is 0.9f
        /// </summary>
        public float? NucleusSamplingFactor { get; set; } = 0.9f;
        /// <summary>
        /// Default is 0.0f
        /// </summary>
        public float? FrequencyPenalty { get; set; } = 0.0f;
        /// <summary>
        /// Default is 0.0f
        /// </summary>
        public float? PresencePenalty { get; set; } = 0.0f;
		
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 90 4/25/2024
1.0.13 80 4/1/2024
1.0.12 81 2/23/2024
1.0.11 71 2/23/2024
1.0.10 103 2/19/2024
1.0.9 73 2/16/2024
1.0.8 97 2/5/2024
1.0.7 77 2/2/2024
1.0.6 74 2/1/2024
1.0.5 73 2/1/2024
1.0.4 75 1/30/2024
1.0.3 70 1/29/2024