public ValueTask <GeneratedText> GenerateTextAsync( TextGenerationConfiguration configuration, EndpointAuthentication authentication, CancellationToken cancellationToken) { return(_serviceClient.PostAsync <TextGenerationConfigurationDto, GeneratedText>( ServiceName, $"{RoutePrefix}/generate", authentication, TextGenerationConfigurationDto.ToDto(configuration), cancellationToken)); }
public async ValueTask <string> GenerateTextAsync(TextGenerationConfigurationDto configuration) { if (!IsSupported(configuration.Language)) { throw new NotSupportedException($"Language {configuration.Language} is not supported."); } if (configuration.Length < 0) { throw new InvalidOperationException("Cannot have negative length."); } var minLength = configuration.Length == 0 ? 10 // Default value. : configuration.Length; var builder = new StringBuilder(); while (builder.Length < Math.Min(minLength, MaxTextLength)) { var quoteFromApi = await _textRetriever.GetNextTextValue(configuration.Language) .ConfigureAwait(false); var chunks = configuration.TextType == Texts.TextStructure.Words ? quoteFromApi.Split('.').SelectMany(x => x.Split(' ')) : quoteFromApi.Split('.'); // TODO: Account for spaces. foreach (var chunk in chunks) { var allowed = true; foreach (var letter in chunk) { if (!_allowedLetters.Contains(letter)) { allowed = false; break; } } if (!allowed) { continue; } if (configuration.ShouldContain.Count() > ShouldContainMinCount) { allowed = false; } if (!allowed) {
public async ValueTask <ActionResult <GeneratedText> > GenerateText(TextGenerationConfigurationDto configuration) { if (configuration.Contains == null) { return(await _textGenerator.GenerateTextAsync( TextGenerationConfiguration.Standard( new(configuration.Language), textStructure: configuration.TextStructure))); } return(await _textGenerator.GenerateTextAsync( TextGenerationConfiguration.SelfImprovement( new(configuration.Language), shouldContain: configuration.Contains, textStructure: configuration.TextStructure))); }