99from litellm .types .utils import ModelResponse
1010from pydantic import BaseModel
1111
12+ from ..prompt import PromptConfig
1213from .message import Message
1314
1415litellm .modify_params = True # for calls with system message only for anthropic
@@ -169,6 +170,7 @@ def __init__(
169170 user_prompt_template : Optional [str ] = None ,
170171 system_prompt_params : Optional [Dict [str , Any ]] = None ,
171172 max_retries : int = 3 ,
173+ llm_params : Optional [Dict [str , Any ]] = None ,
172174 ) -> None :
173175 """Initialize an LLMFunctionTemplated instance.
174176
@@ -179,12 +181,15 @@ def __init__(
179181 user_prompt_template: Optional template for the user message
180182 system_prompt_params: Parameters for formatting the system prompt if any
181183 max_retries: Maximum number of retry attempts
184+ llm_params: Additional keyword arguments to pass to the LLM client
182185 """
183186 super ().__init__ (model_id = model_id , response_model = response_model , max_retries = max_retries )
184187 self .system_prompt_template = system_prompt_template
185188 self .system_prompt = self ._format (system_prompt_template , system_prompt_params )
186189 self .user_prompt_template = user_prompt_template
187190
191+ self ._llm_params = llm_params or {}
192+
188193 def execute_with_completion (
189194 self ,
190195 user_prompt_params : Optional [Dict [str , Any ]] = None ,
@@ -211,7 +216,7 @@ def execute_with_completion(
211216
212217 user_prompt = self ._format (self .user_prompt_template , user_prompt_params )
213218 messages .append (Message .user (user_prompt ))
214- return self ._execute_with_completion (messages = messages , ** kwargs )
219+ return self ._execute_with_completion (messages = messages , ** self . _llm_params , ** kwargs )
215220
216221 @classmethod
217222 def from_files (
@@ -223,7 +228,7 @@ def from_files(
223228 system_prompt_params : Optional [Dict [str , Any ]] = None ,
224229 max_retries : int = 3 ,
225230 ) -> LLMFunctionTemplated [T_Response ]:
226- """Create an instance from template files.
231+ """Create an instance from template text files.
227232
228233 Args:
229234 model_id: LiteLLM model ID to use
@@ -250,6 +255,62 @@ def from_files(
250255 max_retries = max_retries ,
251256 )
252257
258+ @classmethod
259+ def from_prompt_config (
260+ cls ,
261+ response_model : Type [T_Response ],
262+ prompt_config : PromptConfig ,
263+ system_prompt_params : Optional [Dict [str , Any ]] = None ,
264+ max_retries : int = 3 ,
265+ ) -> LLMFunctionTemplated [T_Response ]:
266+ """Create an instance from prompt config object.
267+
268+ Args:
269+ response_model: Pydantic model class for structuring responses
270+ prompt_config: PromptConfig object
271+ system_prompt_params: Parameters for formatting the system prompt
272+ max_retries: Maximum number of retry attempts
273+ """
274+ system_prompt_template = prompt_config .prompt .system .get_template ()
275+ user_prompt_template = prompt_config .prompt .user .get_template () if prompt_config .prompt .user else None
276+
277+ if prompt_config .llm is None :
278+ raise ValueError ("LLMConfig in PromptConfig is required to create an LLMFunction but was not set" )
279+ model_id = prompt_config .llm .model
280+
281+ return cls (
282+ model_id = model_id ,
283+ response_model = response_model ,
284+ system_prompt_template = system_prompt_template ,
285+ user_prompt_template = user_prompt_template ,
286+ system_prompt_params = system_prompt_params ,
287+ max_retries = max_retries ,
288+ llm_params = prompt_config .llm .params ,
289+ )
290+
291+ @classmethod
292+ def from_prompt_config_file (
293+ cls ,
294+ response_model : Type [T_Response ],
295+ prompt_config_path : str ,
296+ system_prompt_params : Optional [Dict [str , Any ]] = None ,
297+ max_retries : int = 3 ,
298+ ) -> LLMFunctionTemplated [T_Response ]:
299+ """Create an instance from prompt config file.
300+
301+ Args:
302+ response_model: Pydantic model class for structuring responses
303+ prompt_config_path: Path to the prompt config yaml file
304+ system_prompt_params: Parameters for formatting the system prompt
305+ max_retries: Maximum number of retry attempts
306+ """
307+ return cls .from_prompt_config (
308+ response_model = response_model ,
309+ prompt_config = PromptConfig .from_yaml (prompt_config_path ),
310+ system_prompt_params = system_prompt_params ,
311+ max_retries = max_retries ,
312+ )
313+
253314 @staticmethod
254315 def _format (template : str , params : Optional [Dict [str , Any ]] = None ) -> str :
255316 """Format the template string with the given optional parameters."""
0 commit comments