Files

196 lines
4.6 KiB
Bash
Raw Permalink Normal View History

#!/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 "=========================================="