-
Notifications
You must be signed in to change notification settings - Fork 0
Introduce User API Key Admin Endpoints and Model Configuration SDK API #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce User API Key Admin Endpoints and Model Configuration SDK API #4
Conversation
…/server/routes.py): generate user API key: generates and returns an API key for a given user get user API key: returns the API key of a given user.
…, list models, set default models, list default models).
as-ondewo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General comments:
- Some files have formatting issues like trailing spaces or not newline at the end of the file. This should be fixed by the pre-commit hooks, so please use them.
- Expand Python SDK (sdk/python) to cover new endpoints.
- Add documentation for new HTTP and Python SDK endpoints (docs/references).
- Add support for new admin endpoints to admin CLI (admin/client/admin_client.py).
- For completeness we should also add an admin endpoint for deleting API keys. I've updated the Jira ticket to also include this.
- Consistently use
dictandlistfor type hints instead ofDictandList - What's your setup for running the tests? Most of them fail for me.
test/testcases/test_sdk_api/test_user_models_management/conftest.py
Outdated
Show resolved
Hide resolved
as-ondewo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some more needed changes apart from the unaddressed comments of my first review. Most of them are for the user tests which I didn't look at in depth in my first review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General comments that apply to all user tests:
- use
RetCodeenum constants instead of integer return codes - always check for a concrete return code, not just
!= 0 - always check for concrete messages, not just some phrases being contained in the message
- never use conditional assert statements inside of if statements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are very incomplete and in some cases test things that shouldn't actually work.
- setting a built-in default model:
- for each type of model that has built-in models test
- setting a model that exists and is configured for the current RAGFlow instance (should work)
- setting a model that exists but is not configured for the current RAGFlow instance (shouldn't work)
- setting a model that does not exist (should not work)
- for setting multiple models simultaneously test
- setting only valid models
- setting a mix of valid and invalid models
- setting only invalid models
- the tests that you currently have pass but shouldn't because they set models that aren't configured for current RAGFlow instance
- for each type of model that has built-in models test
- setting normal (not built-in) models:
- same tests as for the built-in models
- setting a model to
nullor""should remove the default model, not leave it unchanged- add tests for clearing one/multiple/all models
| models_after: Dict[str, Any] = res["data"] | ||
| assert "Builtin" not in models_after, "Builtin should be removed from models list" | ||
|
|
||
| @pytest.mark.p1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is redundant. Other tests already check the return code
| # Removing non-existent factory should still succeed (no-op) | ||
| assert res["code"] == 0, res | ||
|
|
||
| @pytest.mark.p2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trying to delete a non-existent factory should fail
| assert len(models1[factory_name]["llm"]) == len(models2[factory_name]["llm"]) | ||
|
|
||
| @pytest.mark.p2 | ||
| def test_list_user_models_tags(self, HttpApiAuth): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check that the tags are actually correct
| assert "tags" in factory_data | ||
|
|
||
| @pytest.mark.p2 | ||
| def test_list_user_models_builtin_factory(self, HttpApiAuth): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- it shouldn't be possible to add the "Builtin" factory (should always be available)
- most of the tests here are completely pointless
- it is not feasible to test all possible model providers but we should at least test all possible success and failure cases for one local model and one API service
- test parameter validation for all factories
- test adding an individual model (not just all models from a factory)
…dd-User-API-Key-Endpoints-to-RAGFlow-Admin-Interface
…dd-User-API-Key-Endpoints-to-RAGFlow-Admin-Interface
Summary
This PR adds user API key management endpoints to the RAGFlow admin interface, allowing administrators to generate and retrieve API keys for users. It also includes SDK API endpoints for model management, enabling users to add, remove, list, and configure default models. Additionally, it includes comprehensive test infrastructure improvements with proper cleanup mechanisms for API tokens and related cache data.
Changes
Features
Admin API Endpoints
POST /admin/users/<user_name>/api_keyendpoint to generate new API keys for usersGET /admin/users/<username>/api_keyendpoint to retrieve all API keys for a userSDK API Endpoints (Model Management)
POST /api/v1/modelsendpoint to add models for a user by factory and API keyDELETE /api/v1/modelsendpoint to remove all models for a factoryGET /api/v1/modelsendpoint to list all configured models for a userPOST /api/v1/models/defaultendpoint to set default models (chat, embedding, ASR, image-to-text, rerank, TTS)GET /api/v1/models/defaultendpoint to retrieve default model configurationsAPI Endpoints
Admin API Endpoints
Generate User API Key
Response:
{ "code": 0, "data": { "token": "ragflow-...", "beta": "...", "tenant_id": "...", "create_date": "...", "update_date": null }, "message": "API key generated successfully" }Get User API Keys
Response:
{ "code": 0, "data": [ { "token": "ragflow-...", "beta": "...", "tenant_id": "...", "dialog_id": "...", "source": "...", "create_date": "...", "update_date": "..." } ], "message": "Get user API keys" }SDK API Endpoints
Add Model
Request Body:
{ "llm_factory": "OpenAI", "api_key": "sk-...", "base_url": "https://api.openai.com/v1" // optional }Response:
{ "code": 0, "data": true, "message": "Success" }Notes:
Remove Model
Request Body:
{ "llm_factory": "OpenAI" }Response:
{ "code": 0, "data": true, "message": "Success" }List User Models
Query Parameters:
include_details(bool, optional): Whether to include detailed information (api_base, max_tokens, status). Default: falseResponse:
{ "code": 0, "data": { "OpenAI": { "tags": {...}, "llm": [ { "type": "chat", "name": "gpt-4", "used_token": 0, "api_base": "...", // if include_details=true "max_tokens": 8192, // if include_details=true "status": "1" // if include_details=true } ] } }, "message": "Success" }Set Default Models
Request Body:
{ "llm_id": "gpt-4", "embd_id": "text-embedding-ada-002", "asr_id": "whisper-1", "img2txt_id": "gpt-4-vision-preview", "rerank_id": "bge-reranker-base", "tts_id": "tts-1" }Response:
{ "code": 0, "data": true, "message": "Success" }Notes:
Get Default Models
Response:
{ "code": 0, "data": { "llm_id": "gpt-4", "embd_id": "text-embedding-ada-002", "asr_id": "whisper-1", "img2txt_id": "gpt-4-vision-preview", "rerank_id": "bge-reranker-base", "tts_id": "tts-1" }, "message": "Success" }