Skip to content

Commit 8b264c4

Browse files
committed
apply review suggestions
fix
1 parent c92ebfb commit 8b264c4

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

nemoguardrails/colang/v2_x/runtime/runtime.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from urllib.parse import urljoin
2121

2222
import aiohttp
23-
import langchain
2423

2524
from nemoguardrails.actions.actions import ActionResult
2625
from nemoguardrails.colang import parse_colang_file
@@ -44,8 +43,6 @@
4443
from nemoguardrails.rails.llm.config import RailsConfig
4544
from nemoguardrails.utils import new_event_dict, new_readable_uuid
4645

47-
langchain.debug = False
48-
4946
log = logging.getLogger(__name__)
5047

5148

nemoguardrails/evaluate/evaluate_factcheck.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def create_negative_samples(self, dataset):
108108
evidence=evidence, answer=answer
109109
)
110110
negative_answer = llm_with_config.invoke(formatted_prompt)
111-
data["incorrect_answer"] = negative_answer.strip()
111+
negative_answer_content = negative_answer.content
112+
data["incorrect_answer"] = negative_answer_content.strip()
112113

113114
return dataset
114115

@@ -188,14 +189,16 @@ def run(self):
188189
split="negative"
189190
)
190191

191-
print(f"Positive Accuracy: {pos_num_correct/len(self.dataset) * 100}")
192-
print(f"Negative Accuracy: {neg_num_correct/len(self.dataset) * 100}")
192+
print(f"Positive Accuracy: {pos_num_correct / len(self.dataset) * 100}")
193+
print(f"Negative Accuracy: {neg_num_correct / len(self.dataset) * 100}")
193194
print(
194-
f"Overall Accuracy: {(pos_num_correct + neg_num_correct)/(2*len(self.dataset))* 100}"
195+
f"Overall Accuracy: {(pos_num_correct + neg_num_correct) / (2 * len(self.dataset)) * 100}"
195196
)
196197

197198
print("---Time taken per sample:---")
198-
print(f"Ask LLM:\t{(pos_time+neg_time)*1000/(2*len(self.dataset)):.1f}ms")
199+
print(
200+
f"Ask LLM:\t{(pos_time + neg_time) * 1000 / (2 * len(self.dataset)):.1f}ms"
201+
)
199202

200203
if self.write_outputs:
201204
dataset_name = os.path.basename(self.dataset_path).split(".")[0]

nemoguardrails/library/hallucination/actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async def self_check_hallucination(
7171
f"Current LLM engine is {type(llm).__name__}, which may not support all features."
7272
)
7373

74-
if "n" not in llm.__fields__:
74+
if "n" not in llm.model_fields:
7575
log.warning(
7676
f"LLM engine {type(llm).__name__} does not support the 'n' parameter for generating multiple completion choices. "
7777
f"Please use an OpenAI LLM engine or a model that supports the 'n' parameter for optimal performance."

tests/test_configs/with_custom_llm/custom_llm.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
CallbackManagerForLLMRun,
2121
)
2222
from langchain_core.language_models.llms import BaseLLM
23+
from langchain_core.outputs import Generation, LLMResult
2324

2425

2526
class CustomLLM(BaseLLM):
@@ -47,9 +48,7 @@ def _generate(
4748
stop: Optional[List[str]] = None,
4849
run_manager: Optional[CallbackManagerForLLMRun] = None,
4950
**kwargs,
50-
):
51-
from langchain_core.outputs import Generation, LLMResult
52-
51+
) -> LLMResult:
5352
generations = [
5453
[Generation(text=self._call(prompt, stop, run_manager, **kwargs))]
5554
for prompt in prompts
@@ -62,9 +61,7 @@ async def _agenerate(
6261
stop: Optional[List[str]] = None,
6362
run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
6463
**kwargs,
65-
):
66-
from langchain_core.outputs import Generation, LLMResult
67-
64+
) -> LLMResult:
6865
generations = [
6966
[Generation(text=await self._acall(prompt, stop, run_manager, **kwargs))]
7067
for prompt in prompts

0 commit comments

Comments
 (0)