ဒီနမူနာက Microsoft Foundry Local ကို REST API ဝန်ဆောင်မှုအဖြစ် OpenAI SDK ကိုမသုံးဘဲ အသုံးပြုနည်းကို ပြသထားပါတယ်။ HTTP ကိုတိုက်ရိုက် ပေါင်းစည်းသုံးစွဲခြင်းနည်းလမ်းများကို ပြသပြီး အမြင့်ဆုံးထိန်းချုပ်မှုနှင့် အပြင်အဆင်ပြုလုပ်နိုင်စွမ်းကို ပေးစွမ်းပါတယ်။
Microsoft ရဲ့ Foundry Local ပုံစံများအပေါ် အခြေခံပြီး ဒီနမူနာက အောက်ပါအရာများကို ပေးစွမ်းပါတယ်။
- FoundryLocalManager နှင့် REST API ကိုတိုက်ရိုက် ပေါင်းစည်းခြင်း
- Custom HTTP client အကောင်အထည်ဖော်ခြင်း
- မော်ဒယ်စီမံခန့်ခွဲမှုနှင့် ကျန်းမာရေးအခြေအနေ စစ်ဆေးခြင်း
- Streaming နှင့် non-streaming အဖြေများကို ကိုင်တွယ်ခြင်း
- ထုတ်လုပ်မှုအဆင်သင့် အမှားကိုင်တွယ်မှုနှင့် ပြန်လည်ကြိုးစားမှု လိုက်နာမှု
-
Foundry Local Installation
# Install from GitHub releases winget install Microsoft.FoundryLocal -
Python Dependencies
pip install foundry-local-sdk requests asyncio aiohttp
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Your App │───▶│ REST API Client │───▶│ Foundry Local │
│ │ │ │ │ Service │
│ - Custom Logic │ │ - HTTP Requests │ │ - Model Loading │
│ - Business Rules│ │ - Authentication │ │ - Inference │
│ - Data Pipeline │ │ - Error Handling │ │ - Health Check │
└─────────────────┘ └──────────────────┘ └─────────────────┘
- SDK မလိုအပ်ဘဲ REST API ကို သုံးခြင်း
- Custom authentication နှင့် headers
- Request/response ကို ကိုယ်တိုင်ထိန်းချုပ်နိုင်ခြင်း
- မော်ဒယ်များကို dynamic loading နှင့် unloading
- ကျန်းမာရေးအခြေအနေ စစ်ဆေးခြင်း
- စွမ်းဆောင်ရည် metrics စုဆောင်းခြင်း
- Exponential backoff ဖြင့် ပြန်လည်ကြိုးစားမှု mechanism
- Fault tolerance အတွက် circuit breaker
- Comprehensive logging နှင့် monitoring
- Real-time application အတွက် streaming responses
- High-throughput scenarios အတွက် batch processing
- Custom response parsing နှင့် validation
from api_client import FoundryAPIClient
# Initialize the API client
client = FoundryAPIClient()
# Simple completion
response = await client.complete(
prompt="Explain quantum computing",
model="phi-4-mini",
max_tokens=500
)
print(response.content)# Stream responses for real-time applications
async for chunk in client.stream_complete(
prompt="Write a story about AI",
model="phi-4-mini"
):
print(chunk.content, end="", flush=True)# Check service health
health = await client.health_check()
print(f"Service Status: {health.status}")
print(f"Active Models: {health.loaded_models}")
print(f"Memory Usage: {health.memory_usage}")07/
├── README.md # This documentation
├── requirements.txt # Python dependencies
├── api_client.py # Core API client implementation
├── health_monitor.py # Health checking and monitoring
├── examples/
│ ├── basic_usage.py # Simple API integration example
│ ├── streaming.py # Streaming response example
│ ├── batch_processing.py # Batch processing example
│ └── production.py # Production-ready implementation
└── tests/
├── test_api_client.py # Unit tests for API client
└── test_integration.py # Integration tests
ဒီနမူနာက Microsoft ရဲ့ တရားဝင်ပုံစံများကို လိုက်နာထားပါတယ်။
- SDK Integration:
FoundryLocalManagerကို ဝန်ဆောင်မှုစီမံခန့်ခွဲမှုအတွက် အသုံးပြုခြင်း - REST Endpoints:
/v1/chat/completionsနှင့် အခြား endpoints ကို တိုက်ရိုက် ခေါ်ယူခြင်း - Authentication: Local services အတွက် API key ကို သင့်တော်စွာ ကိုင်တွယ်ခြင်း
- Model Management: Catalog listing, downloading, နှင့် loading ပုံစံများ
- Error Handling: Microsoft အကြံပြုထားသော error codes နှင့် responses
-
Dependencies ကို Install လုပ်ပါ
pip install -r requirements.txt
-
Basic Example ကို Run လုပ်ပါ
python examples/basic_usage.py
-
Streaming ကို စမ်းသပ်ပါ
python examples/streaming.py
-
Production Setup
python examples/production.py
အပြင်အဆင်ပြုလုပ်နိုင်စွမ်းအတွက် Environment variables:
FOUNDRY_MODEL: အသုံးပြုမည့် default model (default: "phi-4-mini")FOUNDRY_TIMEOUT: Request timeout အချိန် (default: 30)FOUNDRY_RETRIES: Retry ကြိုးစားမှုအရေအတွက် (default: 3)FOUNDRY_LOG_LEVEL: Logging level (default: "INFO")
- Connection Management: HTTP connections ကို ထပ်ခါတလဲလဲ အသုံးပြုခြင်း
- Error Handling: Exponential backoff ဖြင့် retry logic ကို အကောင်းဆုံးအကောင်အထည်ဖော်ခြင်း
- Resource Monitoring: မော်ဒယ် memory အသုံးပြုမှုနှင့် စွမ်းဆောင်ရည်ကို စောင့်ကြည့်ခြင်း
- Security: Local services အတွက် သင့်တော်သော authentication ကို အသုံးပြုခြင်း
- Testing: Unit နှင့် integration tests နှစ်မျိုးလုံး ပါဝင်စေရန်
Service Not Running
# Check Foundry Local status
foundry status
# Start if needed
foundry startModel Loading Issues
# List available models
foundry model list
# Download specific model
foundry model download phi-4-miniConnection Errors
- Foundry Local ကို မှန်ကန်သော port တွင် run လုပ်နေကြောင်း စစ်ဆေးပါ
- Firewall settings ကို စစ်ဆေးပါ
- Authentication headers ကို သေချာစွာ ထည့်သွင်းပါ
- Connection Pooling: မကြာခဏ request များအတွက် session objects ကို အသုံးပြုပါ
- Async Operations: Concurrent requests အတွက် asyncio ကို အသုံးပြုပါ
- Caching: မော်ဒယ် response များကို သင့်တော်သောနေရာတွင် cache လုပ်ပါ
- Monitoring: Response times ကို စောင့်ကြည့်ပြီး timeout ကို ပြင်ဆင်ပါ
ဒီနမူနာကို ပြီးမြောက်ပြီးနောက် သင်သည် အောက်ပါအရာများကို နားလည်နိုင်ပါမည်။
- Foundry Local နှင့် REST API ကို တိုက်ရိုက် ပေါင်းစည်းခြင်း
- Custom HTTP client အကောင်အထည်ဖော်ခြင်း ပုံစံများ
- ထုတ်လုပ်မှုအဆင်သင့် error handling နှင့် monitoring
- Microsoft Foundry Local ဝန်ဆောင်မှု architecture
- Local AI services အတွက် စွမ်းဆောင်ရည် တိုးတက်အောင်လုပ်ဆောင်နည်းများ
- Sample 08: Windows 11 Chat Application ကို စမ်းသပ်ပါ
- Sample 09: Multi-Agent Orchestration ကို စမ်းသပ်ပါ
- Sample 10: Foundry Local as Tools Integration ကို လေ့လာပါ