add documents
This commit is contained in:
93
docs/api/app_client.md
Normal file
93
docs/api/app_client.md
Normal file
@@ -0,0 +1,93 @@
|
||||
# AppClient
|
||||
|
||||
The `AppClient` provides methods for application analytics and logs.
|
||||
|
||||
## Initialization
|
||||
|
||||
```python
|
||||
from fastgpt_client import AppClient
|
||||
|
||||
client = AppClient(
|
||||
api_key="fastgpt-xxxxx",
|
||||
base_url="http://localhost:3000"
|
||||
)
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
### get_app_logs_chart
|
||||
|
||||
Get application analytics chart data.
|
||||
|
||||
```python
|
||||
client.get_app_logs_chart(
|
||||
appId: str,
|
||||
dateStart: str,
|
||||
dateEnd: str,
|
||||
offset: int = 1,
|
||||
source: list[str] | None = None,
|
||||
userTimespan: str = "day",
|
||||
chatTimespan: str = "day",
|
||||
appTimespan: str = "day"
|
||||
) -> httpx.Response
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
|-----------|------|----------|-------------|
|
||||
| `appId` | `str` | Yes | Application ID |
|
||||
| `dateStart` | `str` | Yes | Start date (ISO 8601 format: `YYYY-MM-DD`) |
|
||||
| `dateEnd` | `str` | Yes | End date (ISO 8601 format: `YYYY-MM-DD`) |
|
||||
| `offset` | `int` | No | Offset value (default: `1`) |
|
||||
| `source` | `list[str]` | No | List of sources (default: `["api"]`) |
|
||||
| `userTimespan` | `str` | No | User data timespan: `day`, `week`, or `month` (default: `"day"`) |
|
||||
| `chatTimespan` | `str` | No | Chat data timespan: `day`, `week`, or `month` (default: `"day"`) |
|
||||
| `appTimespan` | `str` | No | App data timespan: `day`, `week`, or `month` (default: `"day"`) |
|
||||
|
||||
**Source Options:**
|
||||
|
||||
- `"api"` - API interactions
|
||||
- `"online"` - Online usage
|
||||
- `"share"` - Shared links
|
||||
- `"test"` - Test interactions
|
||||
|
||||
**Example:**
|
||||
|
||||
```python
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
with AppClient(api_key="fastgpt-xxxxx") as client:
|
||||
# Get analytics for the last 7 days
|
||||
end_date = datetime.now()
|
||||
start_date = end_date - timedelta(days=7)
|
||||
|
||||
response = client.get_app_logs_chart(
|
||||
appId="your-app-id",
|
||||
dateStart=start_date.strftime("%Y-%m-%d"),
|
||||
dateEnd=end_date.strftime("%Y-%m-%d"),
|
||||
source=["api", "online"],
|
||||
userTimespan="day",
|
||||
chatTimespan="day",
|
||||
appTimespan="day"
|
||||
)
|
||||
|
||||
data = response.json()
|
||||
|
||||
# Access analytics data
|
||||
print(f"Users: {data['data'].get('users', {})}")
|
||||
print(f"Chats: {data['data'].get('chats', {})}")
|
||||
print(f"App metrics: {data['data'].get('app', {})}")
|
||||
```
|
||||
|
||||
**Response Structure:**
|
||||
|
||||
The response contains analytics data with the following possible keys:
|
||||
|
||||
- `users` - User engagement metrics
|
||||
- `chats` - Chat interaction metrics
|
||||
- `app` - Application-level metrics
|
||||
- `tokens` - Token usage statistics
|
||||
- `prices` - Cost information
|
||||
|
||||
Each metric may be organized by the specified timespan (day/week/month).
|
||||
Reference in New Issue
Block a user