File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
nemoguardrails/library/embedding_topic_detector Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515
16+ import hashlib
17+ import json
1618import logging
1719from typing import Dict , List , Optional
1820
@@ -77,7 +79,10 @@ async def detect(self, query: str) -> Dict:
7779
7880async def _check (context : Optional [dict ], llm_task_manager , message_key : str ) -> dict :
7981 config = llm_task_manager .config .rails .config .embedding_topic_detector
80- cache_key = f"{ config ['embedding_model' ]} _{ config ['embedding_engine' ]} _{ config .get ('threshold' , 0.75 )} _{ config .get ('top_k' , 3 )} "
82+ examples_hash = hashlib .sha256 (
83+ json .dumps (config ["examples" ], sort_keys = True ).encode ("utf-8" )
84+ ).hexdigest ()
85+ cache_key = f"{ config ['embedding_model' ]} _{ config ['embedding_engine' ]} _{ config .get ('threshold' , 0.75 )} _{ config .get ('top_k' , 3 )} _{ examples_hash } "
8186
8287 if cache_key not in _detector_cache :
8388 _detector_cache [cache_key ] = EmbeddingTopicDetector (
You can’t perform that action at this time.
0 commit comments