Add knowledge retrieval configuration to Assistant model and related components
- Introduce new fields for knowledge retrieval configuration in AssistantConfig and Assistant models, including mode, top_n, and score_threshold. - Implement KnowledgeRetrievalConfig schema with validation for top_n. - Update backend services and routes to handle knowledge retrieval settings. - Enhance frontend components to support knowledge retrieval configuration, including a new dialog for advanced settings. - Add tests for knowledge retrieval configuration validation and description generation.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import unittest
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from schemas import KnowledgeRetrievalConfig
|
||||
from services.knowledge import extract_text, split_text
|
||||
|
||||
|
||||
@@ -19,5 +22,22 @@ class KnowledgeTextTest(unittest.TestCase):
|
||||
extract_text("archive.zip", b"data")
|
||||
|
||||
|
||||
class KnowledgeRetrievalConfigTest(unittest.TestCase):
|
||||
def test_accepts_unlimited_top_n_with_threshold(self):
|
||||
config = KnowledgeRetrievalConfig.model_validate(
|
||||
{"mode": "on_demand", "topN": -1, "scoreThreshold": 0.65}
|
||||
)
|
||||
|
||||
self.assertEqual(config.top_n, -1)
|
||||
self.assertEqual(
|
||||
config.model_dump(by_alias=True),
|
||||
{"mode": "on_demand", "topN": -1, "scoreThreshold": 0.65},
|
||||
)
|
||||
|
||||
def test_rejects_zero_top_n(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
KnowledgeRetrievalConfig(top_n=0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user