|
17 | 17 | Module for providing a context manager to temporarily adjust parameters of a language model. |
18 | 18 |
|
19 | 19 | Also allows registration of custom parameter managers for different language model types. |
| 20 | +
|
| 21 | +.. deprecated:: 0.17.0 |
| 22 | + This module is deprecated and will be removed in version 0.19.0. |
| 23 | + Instead of using the context manager approach, pass parameters directly to `llm_call()` |
| 24 | + using the `llm_params` argument: |
| 25 | +
|
| 26 | + Old way (deprecated): |
| 27 | + from nemoguardrails.llm.params import llm_params |
| 28 | + with llm_params(llm, temperature=0.7): |
| 29 | + result = await llm_call(llm, prompt) |
| 30 | +
|
| 31 | + New way (recommended): |
| 32 | + result = await llm_call(llm, prompt, llm_params={"temperature": 0.7}) |
| 33 | +
|
| 34 | + See: https://github.com/NVIDIA/NeMo-Guardrails/issues/1387 |
20 | 35 | """ |
21 | 36 |
|
22 | 37 | import logging |
| 38 | +import warnings |
23 | 39 | from typing import Dict, Type |
24 | 40 |
|
25 | 41 | from langchain.base_language import BaseLanguageModel |
26 | 42 |
|
27 | 43 | log = logging.getLogger(__name__) |
28 | 44 |
|
| 45 | +_DEPRECATION_MESSAGE = ( |
| 46 | + "The nemoguardrails.llm.params module is deprecated and will be removed in version 0.19.0. " |
| 47 | + "Instead of using llm_params context manager, pass parameters directly to llm_call() " |
| 48 | + "using the llm_params argument. " |
| 49 | + "See: https://github.com/NVIDIA/NeMo-Guardrails/issues/1387" |
| 50 | +) |
| 51 | + |
29 | 52 |
|
30 | 53 | class LLMParams: |
31 | | - """Context manager to temporarily modify the parameters of a language model.""" |
| 54 | + """Context manager to temporarily modify the parameters of a language model. |
| 55 | +
|
| 56 | + .. deprecated:: 0.17.0 |
| 57 | + Use llm_call() with llm_params argument instead. |
| 58 | + """ |
32 | 59 |
|
33 | 60 | def __init__(self, llm: BaseLanguageModel, **kwargs): |
| 61 | + warnings.warn(_DEPRECATION_MESSAGE, DeprecationWarning, stacklevel=2) |
34 | 62 | self.llm = llm |
35 | 63 | self.altered_params = kwargs |
36 | 64 | self.original_params = {} |
@@ -82,13 +110,22 @@ def __exit__(self, type, value, traceback): |
82 | 110 |
|
83 | 111 |
|
84 | 112 | def register_param_manager(llm_type: Type[BaseLanguageModel], manager: Type[LLMParams]): |
85 | | - """Register a parameter manager.""" |
| 113 | + """Register a parameter manager. |
| 114 | +
|
| 115 | + .. deprecated:: 0.17.0 |
| 116 | + This function is deprecated and will be removed in version 0.19.0. |
| 117 | + """ |
| 118 | + warnings.warn(_DEPRECATION_MESSAGE, DeprecationWarning, stacklevel=2) |
86 | 119 | _param_managers[llm_type] = manager |
87 | 120 |
|
88 | 121 |
|
89 | 122 | def llm_params(llm: BaseLanguageModel, **kwargs): |
90 | | - """Returns a parameter manager for the given language model.""" |
| 123 | + """Returns a parameter manager for the given language model. |
91 | 124 |
|
| 125 | + .. deprecated:: 0.17.0 |
| 126 | + Use llm_call() with llm_params argument instead. |
| 127 | + """ |
| 128 | + warnings.warn(_DEPRECATION_MESSAGE, DeprecationWarning, stacklevel=2) |
92 | 129 | _llm_params = _param_managers.get(llm.__class__, LLMParams) |
93 | 130 |
|
94 | 131 | return _llm_params(llm, **kwargs) |
0 commit comments