Overview
OpenAI is a cloud service that provides high-performance Large Language Models (LLM), including GPT-4. Fess can use the OpenAI API to implement AI mode functionality.
Using OpenAI enables high-quality response generation powered by state-of-the-art AI models.
Key Features
High-Quality Responses: Highly accurate response generation using cutting-edge GPT models
Scalability: Easy scaling as a cloud service
Continuous Improvement: Performance improves with regular model updates
Rich Functionality: Supports diverse tasks including text generation, summarization, and translation
Supported Models
Main models available with OpenAI:
gpt-4o- Latest high-performance modelgpt-4o-mini- Lightweight version of GPT-4o (cost-efficient)gpt-4-turbo- High-speed version of GPT-4gpt-3.5-turbo- Model with excellent cost performance
Note
For the latest information on available models, see OpenAI Models.
Prerequisites
Before using OpenAI, prepare the following.
OpenAI Account: Create an account at https://platform.openai.com/
API Key: Generate an API key from the OpenAI dashboard
Billing Setup: Configure billing information as API usage incurs charges
Obtaining an API Key
Log in to OpenAI Platform
Navigate to the “API keys” section
Click “Create new secret key”
Enter a key name and create
Securely save the displayed key (it will only be shown once)
Warning
API keys are confidential information. Please note the following:
Do not commit to version control systems
Do not output to logs
Manage using environment variables or secure configuration files
Basic Configuration
Add the following settings to app/WEB-INF/conf/system.properties.
Minimal Configuration
# Enable AI mode functionality
rag.chat.enabled=true
# Set LLM provider to OpenAI
rag.llm.type=openai
# OpenAI API key
rag.llm.openai.api.key=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Model to use
rag.llm.openai.model=gpt-4o-mini
Recommended Configuration (Production)
# Enable AI mode functionality
rag.chat.enabled=true
# LLM provider setting
rag.llm.type=openai
# OpenAI API key
rag.llm.openai.api.key=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Model setting (use high-performance model)
rag.llm.openai.model=gpt-4o
# API endpoint (usually no change needed)
rag.llm.openai.api.url=https://api.openai.com/v1
# Timeout setting
rag.llm.openai.timeout=60000
Configuration Options
All configuration options available for the OpenAI client.
| Property | Description | Default |
|---|---|---|
rag.llm.openai.api.key | OpenAI API key | (Required) |
rag.llm.openai.model | Model name to use | gpt-4o-mini |
rag.llm.openai.api.url | API base URL | https://api.openai.com/v1 |
rag.llm.openai.timeout | Request timeout (in milliseconds) | 60000 |
Environment Variable Configuration
For security reasons, it is recommended to configure API keys using environment variables.
Docker Environment
docker run -e RAG_LLM_OPENAI_API_KEY=sk-xxx... codelibs/fess:15.5.0
docker-compose.yml
services:
fess:
image: codelibs/fess:15.5.0
environment:
- RAG_CHAT_ENABLED=true
- RAG_LLM_TYPE=openai
- RAG_LLM_OPENAI_API_KEY=${OPENAI_API_KEY}
- RAG_LLM_OPENAI_MODEL=gpt-4o-mini
systemd Environment
/etc/systemd/system/fess.service.d/override.conf:
[Service]
Environment="RAG_LLM_OPENAI_API_KEY=sk-xxx..."
Using Azure OpenAI
When using OpenAI models via Microsoft Azure, change the API endpoint.
# Azure OpenAI endpoint
rag.llm.openai.api.url=https://your-resource.openai.azure.com/openai/deployments/your-deployment
# Azure API key
rag.llm.openai.api.key=your-azure-api-key
# Deployment name (specified as model name)
rag.llm.openai.model=your-deployment-name
Note
When using Azure OpenAI, the API request format may differ slightly. Please refer to Azure OpenAI documentation for details.
Model Selection Guide
Guidelines for selecting models based on intended use.
| Model | Cost | Quality | Use Case |
|---|---|---|---|
gpt-3.5-turbo | Low | Good | General Q&A, cost-focused |
gpt-4o-mini | Medium | High | Balanced use cases (recommended) |
gpt-4o | High | Highest | Complex reasoning, when high quality is needed |
gpt-4-turbo | High | Highest | When fast response is needed |
Cost Reference
OpenAI API is billed based on usage. The following are reference prices as of 2024.
| Model | Input (per 1K tokens) | Output (per 1K tokens) |
|---|---|---|
| gpt-3.5-turbo | $0.0005 | $0.0015 |
| gpt-4o-mini | $0.00015 | $0.0006 |
| gpt-4o | $0.005 | $0.015 |
Note
For the latest pricing, see OpenAI Pricing.
Rate Limiting
OpenAI API has rate limits. Configure appropriately in combination with Fess rate limiting functionality.
# Fess rate limit settings
rag.chat.rate.limit.enabled=true
rag.chat.rate.limit.requests.per.minute=10
OpenAI Tier-based Limits
Limits vary based on your OpenAI account tier:
Free: 3 RPM (requests/minute)
Tier 1: 500 RPM
Tier 2: 5,000 RPM
Tier 3+: Higher limits
Troubleshooting
Authentication Errors
Symptom: “401 Unauthorized” error occurs
Check the following:
Verify API key is correctly configured
Verify API key is valid (check in OpenAI dashboard)
Verify API key has necessary permissions
Rate Limit Errors
Symptom: “429 Too Many Requests” error occurs
Solutions:
Set stricter rate limits in Fess:
rag.chat.rate.limit.requests.per.minute=5
Upgrade your OpenAI account tier
Quota Exceeded
Symptom: “You exceeded your current quota” error
Solutions:
Check usage in OpenAI dashboard
Review billing settings and increase limits if necessary
Timeout
Symptom: Requests time out
Solutions:
Extend timeout duration:
rag.llm.openai.timeout=120000
Consider using a faster model (e.g., gpt-3.5-turbo)
Debug Settings
When investigating issues, adjust Fess log levels to output detailed OpenAI-related logs.
app/WEB-INF/classes/log4j2.xml:
<Logger name="org.codelibs.fess.llm.openai" level="DEBUG"/>
Security Notes
When using OpenAI API, please note the following security considerations.
Data Privacy: Search result contents are sent to OpenAI servers
API Key Management: Key leakage can lead to unauthorized use
Compliance: If handling confidential data, verify your organization’s policies
Usage Policy: Comply with OpenAI’s terms of service
References
LLM Integration Overview - LLM Integration Overview
AI Mode Configuration - AI Mode Details