Create an .env file in the project root:
cp .env.example .envSee .env.example for all available configuration options.
- Get API key from OpenAI Platform
- Update
bloggingAgent/appsettings.json:
{
"OpenAISettings": {
"ApiKey": "sk-your-key-here",
"Model": "gpt-3.5-turbo",
"Temperature": 0.7,
"MaxTokens": 1000
}
}Or use environment variable:
export OPENAI_API_KEY=sk-your-key-hereParameters:
ApiKey- Your OpenAI API keyModel- Model to use (gpt-3.5-turbo, gpt-4, etc.)Temperature- Response creativity (0-1, default: 0.7)MaxTokens- Maximum response length (default: 1000)
- Install Ollama
- Start Ollama service:
ollama serve - Pull model:
ollama pull llama2 - Update
bloggingAgent/appsettings.json:
{
"LlmSettings": {
"OllamaEndpoint": "http://localhost:11434",
"OllamaModel": "llama2"
}
}Parameters:
OllamaEndpoint- Ollama service URLOllamaModel- Model name (llama2, neural-chat, etc.)
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}{
"ConnectionStrings": {
"DefaultConnection": "Server=your-server.databaseasp.net; Database=your-db; User Id=your-user; Password=your-password; Encrypt=True; TrustServerCertificate=True; MultipleActiveResultSets=True;"
}
}Parameters:
Server- SQL Server hostname or IP addressDatabase- Database nameUser Id- SQL Server authentication userPassword- User passwordEncrypt=True- Encrypt connection (recommended)TrustServerCertificate=True- Trust self-signed certs (set to False in production)MultipleActiveResultSets=True- Allow multiple active queries
Example with Your Database:
{
"ConnectionStrings": {
"DefaultConnection": "Server=db54433.public.databaseasp.net; Database=db54433; User Id=db54433; Password=h#7LNr-28=Xb; Encrypt=True; TrustServerCertificate=True; MultipleActiveResultSets=True;"
}
}{
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=blogging_agent;Username=user;Password=password;Port=5432;SSL Mode=Require"
}
}{
"ContentSettings": {
"DefaultAuthor": "AI Assistant",
"MaxPostLength": 5000,
"DefaultTags": ["blog", "ai-generated"],
"AutoPublish": false,
"AutoOptimizeContent": true
}
}{
"SeoSettings": {
"MinTitleLength": 30,
"MaxTitleLength": 60,
"MinDescriptionLength": 120,
"MaxDescriptionLength": 160,
"AutoGenerateMetaDescription": true,
"AutoOptimizeContent": true,
"MinReadingTimeMinutes": 2,
"MaxReadingTimeMinutes": 20
}
}{
"CacheSettings": {
"ExpirationMinutes": 30,
"EnableDistributedCache": false,
"RedisConnectionString": "localhost:6379"
}
}{
"SecuritySettings": {
"JwtSecret": "your-secret-key-min-32-chars-long",
"JwtExpiryHours": 24,
"EnableCors": true,
"CorsOrigins": ["http://localhost:3000", "https://yourdomain.com"]
}
}ASPNETCORE_ENVIRONMENT=Development
ASPNETCORE_URLS=http://localhost:5000;https://localhost:5001
LOG_LEVEL=InformationASPNETCORE_ENVIRONMENT=Production
ASPNETCORE_URLS=http://0.0.0.0:80;https://0.0.0.0:443
LOG_LEVEL=Warning{
"Logging": {
"LogLevel": {
"Default": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Data Source=bloggingagent.db"
},
"OpenAISettings": {
"ApiKey": "",
"Model": "gpt-3.5-turbo",
"Temperature": 0.7,
"MaxTokens": 1000
},
"LlmSettings": {
"OllamaEndpoint": "http://localhost:11434",
"OllamaModel": "llama2"
},
"ContentSettings": {
"DefaultAuthor": "AI Assistant",
"MaxPostLength": 5000,
"DefaultTags": ["blog"],
"AutoPublish": false
},
"SeoSettings": {
"MinTitleLength": 30,
"MaxTitleLength": 60
},
"CacheSettings": {
"ExpirationMinutes": 30
}
}dotnet runFeatures:
- Detailed error pages
- Verbose logging
- Database resets on startup
- Hot reload enabled
dotnet publish -c Release -o ./publish
cd publish
./bloggingAgentFeatures:
- Minimal error information
- Warning level logging
- Production database handling
- Performance optimized
Set environment variables when running Docker:
docker run -e OPENAI_API_KEY=sk-xxx \
-e ASPNETCORE_ENVIRONMENT=Production \
-e ASPNETCORE_URLS=http://0.0.0.0:80 \
-p 5000:80 \
blogging-agent:latestSettings are loaded in this order (later overrides earlier):
appsettings.jsonappsettings.{Environment}.json- Environment variables
- User secrets (development only)
Store sensitive data without committing to repository:
# Initialize secrets storage
dotnet user-secrets init
# Set a secret
dotnet user-secrets set "OpenAISettings:ApiKey" "sk-your-key"
# List all secrets
dotnet user-secrets list
# Remove a secret
dotnet user-secrets remove "OpenAISettings:ApiKey"- Verify key is set in correct location (appsettings.json or .env)
- Check environment variable name exactly matches
- Restart application after changes
- Check for trailing spaces in keys
- Verify
ConnectionStrings:DefaultConnectionis correct - Check file permissions for SQLite database
- Ensure database directory exists
- For PostgreSQL: verify server is running and accessible
- Check
CacheSettings:ExpirationMinutesis set - For distributed cache: verify Redis connection string
- Restart application to clear cache
- Verify
SeoSettingsvalues are reasonable - Check minimum/maximum lengths aren't conflicting
- Ensure content meets minimum length requirements
{
"CacheSettings": {
"ExpirationMinutes": 60,
"EnableDistributedCache": true,
"RedisConnectionString": "your-redis-server:6379"
},
"OpenAISettings": {
"MaxTokens": 500,
"Temperature": 0.5
}
}- Enable distributed cache with Redis
- Increase cache expiration time
- Optimize database queries
- Use production build (
-c Release)