Este guia irá ajudá-lo a começar com o archflow em poucos minutos.
- Java 17+
- Maven 3.8+
- Docker (opcional, para execução de alguns componentes)
<dependency>
<groupId>br.com.archflow</groupId>
<artifactId>archflow-core</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
langchain4j.openai.api-key=seu-api-key
langchain4j.openai.model-name=gpt-4-turbo
import br.com.archflow.core.annotation.AIFlow;
import br.com.archflow.core.annotation.FlowStep;
import br.com.archflow.core.model.StepResult;
@AIFlow
public class CustomerSupportFlow {
@FlowStep(order = 1)
public StepResult analyzeIntent(String customerMessage) {
return StepResult.of(Map.of(
"intent", "Análise do problema do cliente",
"sentiment", "neutral"
));
}
@FlowStep(order = 2)
public StepResult generateResponse(Map<String, Object> analysis) {
return StepResult.of(
"Entendi sua necessidade. Como posso ajudar?"
);
}
}
@Configuration
public class FlowConfig {
@Bean
public FlowEngine flowEngine(
LangChain4j langChain,
FlowValidator validator
) {
return FlowEngine.builder()
.langChain(langChain)
.validator(validator)
.build();
}
}
@Service
public class SupportService {
private final FlowEngine flowEngine;
public CompletableFuture<FlowResult> handleCustomerMessage(String message) {
return flowEngine.execute(
new CustomerSupportFlow(),
ExecutionContext.builder()
.input(message)
.build()
);
}
}
@PluginDescriptor(
id = "sentiment-analyzer",
name = "Sentiment Analyzer",
operations = {
@PluginOperation(
name = "analyze",
description = "Analisa sentimento do texto"
)
}
)
public class SentimentPlugin implements AIPlugin {
@Override
public Object execute(String operationId, Object input, Map<String, Object> context) {
// Implementação
return Map.of("sentiment", "positive");
}
}
@AIFlow
public class EnhancedSupportFlow {
@Inject
private SentimentPlugin sentimentPlugin;
@FlowStep(order = 1)
public StepResult analyzeSentiment(String message) {
return StepResult.of(
sentimentPlugin.execute("analyze", message, Map.of())
);
}
}
@Component
public class FlowMetrics {
private final MeterRegistry registry;
public void recordExecution(FlowResult result) {
registry.timer("flow.execution")
.record(result.getExecutionTime());
registry.counter("flow.status." + result.getStatus())
.increment();
}
}
Acesse http://localhost:8080/actuator/metrics
para ver as métricas.
logging.level.br.com.archflow=DEBUG
2024-02-16 10:00:00.000 DEBUG [archflow] --- Starting flow execution: customer-support
2024-02-16 10:00:00.100 DEBUG [archflow] --- Step 'analyzeIntent' completed
2024-02-16 10:00:00.200 DEBUG [archflow] --- Flow completed successfully
- Explore a Documentação Completa
- Veja Exemplos Práticos
- Aprenda sobre Plugins
- Configure para Produção
Verifique sua API key e conexão com internet.
Certifique-se que o modelo solicitado está disponível.
Verifique a ordem dos steps.
Certifique-se que todos os inputs necessários estão presentes.
Ajuste as configurações de memória da JVM.
Verifique se há memory leaks nos seus fluxos.
Precisa de ajuda?
Para aprender mais sobre o archflow, confira os seguintes guias e documentos:
- Guia de Contribuição - Como contribuir para o projeto
- Guia do Desenvolvedor - Informações detalhadas sobre desenvolvimento de componentes
- Features - Funcionalidades oferecidas pelo framework
- Proposta de Plugins - Estrutura e desenvolvimento de plugins
- Stack Tecnológico - Tecnologias utilizadas no projeto
Esses documentos oferecem uma visão mais detalhada sobre o funcionamento e as melhores práticas para utilizar o archflow.