|
5 | 5 | from __future__ import annotations
|
6 | 6 |
|
7 | 7 | from typing import TYPE_CHECKING, Any, Callable, Optional, cast
|
| 8 | +import asyncio |
8 | 9 |
|
9 | 10 | from cleanlab_tlm import TrustworthyRAG
|
10 | 11 | from pydantic import BaseModel, Field, field_validator
|
@@ -138,10 +139,14 @@ def validate(
|
138 | 139 | - 'is_bad_response': True if the response is flagged as potentially bad (when True, a lookup in Codex is performed), False otherwise.
|
139 | 140 | - Additional keys: Various keys from a [`ThresholdedTrustworthyRAGScore`](/cleanlab_codex/types/validator/#class-thresholdedtrustworthyragscore) dictionary, with raw scores from [TrustworthyRAG](/tlm/api/python/utils.rag/#class-trustworthyrag) for each evaluation metric. `is_bad` indicating whether the score is below the threshold.
|
140 | 141 | """
|
| 142 | + expert_task = asyncio.create_task(self.remediate_async(query)) |
141 | 143 | scores, is_bad_response = self.detect(query, context, response, prompt, form_prompt)
|
142 |
| - expert_answer = None |
143 | 144 | if is_bad_response:
|
144 |
| - expert_answer = self.remediate(query) |
| 145 | + expert_answer, maybe_entry = asyncio.run(expert_task) |
| 146 | + if expert_answer == None: |
| 147 | + self._project.add_entries([maybe_entry]) |
| 148 | + else: |
| 149 | + expert_answer = None |
145 | 150 |
|
146 | 151 | return {
|
147 | 152 | "expert_answer": expert_answer,
|
@@ -198,3 +203,7 @@ def remediate(self, query: str) -> str | None:
|
198 | 203 | """
|
199 | 204 | codex_answer, _ = self._project.query(question=query)
|
200 | 205 | return codex_answer
|
| 206 | + |
| 207 | + async def remediate_async(self, query: str): |
| 208 | + codex_answer, entry = self._project.query(question=query, read_only=True) |
| 209 | + return codex_answer, entry |
0 commit comments