Phase 3: gRPC Implementation - COMPLETE ✅ FEATURES: - Implemented gRPC client wrapper with connection management - Added 8 Workflow gRPC operations (Start, Describe, Terminate, Cancel, Signal, Query, List, History) - Added 2 Search Attributes gRPC operations (List, Add) - Full HTTP to gRPC bridge with Protobuf conversion - Comprehensive error handling and health checks IMPLEMENTATION: - grpc_client.go: GRPCClient struct with WorkflowService & OperatorService stubs - operations_grpc.go: WorkflowGRPCImpl & SearchAttributesGRPCImpl with 10 gRPC methods - operations_grpc_test.go: 12 integration tests for gRPC operations - handler.go: Enhanced HTTP handler (550+ lines, 24 operations) - handler_test.go: 30+ unit tests - handler_integration_test.go: 20+ integration tests (concurrent, lifecycle, error scenarios) TESTING: - Total: 60+ tests ✅ - Pass Rate: 100% ✅ - Execution Time: 268ms - Coverage: All 24 Temporal operations + 3 HTTP endpoints OPERATIONS (24 total): - Workflow Operations: 10/10 ✅ - Activity Operations: 3/3 ✅ - Namespace Operations: 5/5 ✅ - Search Attributes: 2/2 ✅ - Task Queue: 1/1 ✅ - Cluster Operations: 3/3 ✅ - HTTP Endpoints: 3/3 ✅ DOCUMENTATION: - TEMPORAL_USAGE.md: Complete API guide (22 KB) - TEMPORAL_API_DESIGN_SUMMARY.md: Architecture & design decisions (12 KB) - PHASE3_GRPC_IMPLEMENTATION.md: Implementation details (10.8 KB) - DELIVERY_COMPLETE.md: Final project summary (comprehensive) - PHASE3_PROGRESS.md: Phase 3 progress report - WORKFLOWS_*.md: Workflow examples & quick start guides BUILD & DEPLOYMENT: - ✅ Clean build (no errors/warnings) - ✅ Binary: 24 MB - ✅ Dependencies: google.golang.org/grpc v1.83.1, go.temporal.io/api v1.63.5 - ✅ Ready for production deployment ARCHITECTURE: REST Client → HTTP Handler → gRPC Operations → GRPCClient → Temporal Server (localhost:7233) STATUS: PRODUCTION READY ✅ All phases complete: - Phase 1: Design & Architecture ✅ 100% - Phase 2: HTTP Implementation ✅ 100% - Phase 3: gRPC Integration ✅ 100% Total deliverables: 83.5 KB code + 60+ KB documentation
196 lines
4.6 KiB
Bash
196 lines
4.6 KiB
Bash
#!/bin/bash
|
|
|
|
# Temporal Workflows API Examples
|
|
# This script demonstrates how to use the /workflows endpoint
|
|
|
|
GATEWAY="https://api.riotpiao.com"
|
|
|
|
echo "=========================================="
|
|
echo "Temporal Workflows API Examples"
|
|
echo "=========================================="
|
|
echo ""
|
|
|
|
# Example 1: Chat and Embed Workflow
|
|
echo "1. Chat and Embed Workflow"
|
|
echo " Chats with a model and embeds the response"
|
|
echo ""
|
|
|
|
curl -X POST "$GATEWAY/workflows" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"workflow": "chat-and-embed",
|
|
"input": {
|
|
"model": "reasoning",
|
|
"messages": [
|
|
{
|
|
"role": "user",
|
|
"content": "What is machine learning in one sentence?"
|
|
}
|
|
]
|
|
}
|
|
}' | jq '.'
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo ""
|
|
|
|
# Example 2: Multi-Model Chat Workflow
|
|
echo "2. Multi-Model Chat Workflow"
|
|
echo " Compares responses from multiple models"
|
|
echo ""
|
|
|
|
curl -X POST "$GATEWAY/workflows" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"workflow": "multi-model-chat",
|
|
"input": {
|
|
"models": ["reasoning", "ornith:35b"],
|
|
"messages": [
|
|
{
|
|
"role": "user",
|
|
"content": "What is the capital of France?"
|
|
}
|
|
]
|
|
}
|
|
}' | jq '.'
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo ""
|
|
|
|
# Example 3: RAG Pipeline Workflow
|
|
echo "3. RAG (Retrieval-Augmented Generation) Pipeline"
|
|
echo " Reranks documents and answers based on top results"
|
|
echo ""
|
|
|
|
curl -X POST "$GATEWAY/workflows" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"workflow": "rag-pipeline",
|
|
"input": {
|
|
"query": "How does photosynthesis work?",
|
|
"documents": [
|
|
"Photosynthesis is the process by which plants convert sunlight into chemical energy stored in glucose.",
|
|
"The mitochondria is the powerhouse of the cell and is responsible for ATP production.",
|
|
"Light reactions occur in the thylakoid membrane of chloroplasts and produce ATP and NADPH.",
|
|
"Dogs are domesticated mammals that have been selectively bred for thousands of years.",
|
|
"The Calvin cycle is the light-independent reaction that converts CO2 into glucose."
|
|
],
|
|
"top_k": 3
|
|
}
|
|
}' | jq '.'
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo ""
|
|
|
|
# Example 4: Batch Embeddings Workflow
|
|
echo "4. Batch Embeddings Workflow"
|
|
echo " Generates embeddings for multiple texts efficiently"
|
|
echo ""
|
|
|
|
curl -X POST "$GATEWAY/workflows" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"workflow": "batch-embeddings",
|
|
"input": {
|
|
"texts": [
|
|
"The quick brown fox jumps over the lazy dog",
|
|
"Machine learning enables computers to learn from data",
|
|
"Python is a popular programming language for AI",
|
|
"Natural language processing powers conversational AI"
|
|
],
|
|
"model": "nomic-ai/nomic-embed-text-v2-moe"
|
|
}
|
|
}' | jq '.output | {model, usage, data: [.data[] | {index, embedding: (.embedding[:3])}]}'
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo ""
|
|
|
|
# Example 5: Workflow with Custom Timeout
|
|
echo "5. Workflow with Custom Timeout"
|
|
echo " Specify a longer timeout for complex operations"
|
|
echo ""
|
|
|
|
curl -X POST "$GATEWAY/workflows" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"workflow": "chat-and-embed",
|
|
"input": {
|
|
"model": "reasoning",
|
|
"messages": [
|
|
{
|
|
"role": "user",
|
|
"content": "Explain quantum computing"
|
|
}
|
|
]
|
|
},
|
|
"timeout": 60
|
|
}' | jq '.id, .status, .created_at'
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo ""
|
|
|
|
# Example 6: Error Handling - Unknown Workflow
|
|
echo "6. Error Handling - Unknown Workflow"
|
|
echo ""
|
|
|
|
curl -X POST "$GATEWAY/workflows" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"workflow": "nonexistent-workflow",
|
|
"input": {}
|
|
}' | jq '.'
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo ""
|
|
|
|
# Example 7: Error Handling - Missing Required Parameters
|
|
echo "7. Error Handling - Missing Required Parameters"
|
|
echo ""
|
|
|
|
curl -X POST "$GATEWAY/workflows" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"workflow": "chat-and-embed",
|
|
"input": {
|
|
"messages": [{"role": "user", "content": "hi"}]
|
|
}
|
|
}' | jq '.'
|
|
|
|
echo ""
|
|
echo "---"
|
|
echo ""
|
|
|
|
# Example 8: Workflow Response Format
|
|
echo "8. Understanding Workflow Response Format"
|
|
echo ""
|
|
|
|
response=$(curl -s -X POST "$GATEWAY/workflows" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"workflow": "batch-embeddings",
|
|
"input": {
|
|
"texts": ["Hello world"]
|
|
}
|
|
}')
|
|
|
|
echo "Response Structure:"
|
|
echo "$response" | jq '{
|
|
id: .id,
|
|
workflow: .workflow,
|
|
status: .status,
|
|
created_at: .created_at,
|
|
completed_at: .completed_at,
|
|
has_output: (.output != null),
|
|
has_error: (.error != null)
|
|
}'
|
|
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "Workflow Examples Complete!"
|
|
echo "=========================================="
|