Remove unnecessary system_instruction argument from run_inference() methods
This commit is contained in:
@@ -30,25 +30,17 @@ class LLMSwitcher(ServiceSwitcher[StrategyType]):
|
|||||||
"""Get the currently active LLM, if any."""
|
"""Get the currently active LLM, if any."""
|
||||||
return self.strategy.active_service
|
return self.strategy.active_service
|
||||||
|
|
||||||
async def run_inference(
|
async def run_inference(self, context: LLMContext) -> Optional[str]:
|
||||||
self, context: LLMContext, system_instruction: Optional[str] = None
|
|
||||||
) -> Optional[str]:
|
|
||||||
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context, using the currently active LLM.
|
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context, using the currently active LLM.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
context: The LLM context containing conversation history.
|
context: The LLM context containing conversation history.
|
||||||
system_instruction: Optional system instruction to guide the LLM's
|
|
||||||
behavior. You could also (again, optionally) provide a system
|
|
||||||
instruction directly in the context. If both are provided, the
|
|
||||||
one in the context takes precedence.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The LLM's response as a string, or None if no response is generated.
|
The LLM's response as a string, or None if no response is generated.
|
||||||
"""
|
"""
|
||||||
if self.active_llm:
|
if self.active_llm:
|
||||||
return await self.active_llm.run_inference(
|
return await self.active_llm.run_inference(context=context)
|
||||||
context=context, system_instruction=system_instruction
|
|
||||||
)
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def register_function(
|
def register_function(
|
||||||
|
|||||||
@@ -228,17 +228,11 @@ class AnthropicLLMService(LLMService):
|
|||||||
response = await api_call(**params)
|
response = await api_call(**params)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def run_inference(
|
async def run_inference(self, context: LLMContext | OpenAILLMContext) -> Optional[str]:
|
||||||
self, context: LLMContext | OpenAILLMContext, system_instruction: Optional[str] = None
|
|
||||||
) -> Optional[str]:
|
|
||||||
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context.
|
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
context: The LLM context containing conversation history.
|
context: The LLM context containing conversation history.
|
||||||
system_instruction: Optional system instruction to guide the LLM's
|
|
||||||
behavior. You could also (again, optionally) provide a system
|
|
||||||
instruction directly in the context. If both are provided, the
|
|
||||||
one in the context takes precedence.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The LLM's response as a string, or None if no response is generated.
|
The LLM's response as a string, or None if no response is generated.
|
||||||
@@ -255,7 +249,7 @@ class AnthropicLLMService(LLMService):
|
|||||||
else:
|
else:
|
||||||
context = AnthropicLLMContext.upgrade_to_anthropic(context)
|
context = AnthropicLLMContext.upgrade_to_anthropic(context)
|
||||||
messages = context.messages
|
messages = context.messages
|
||||||
system = getattr(context, "system", None) or system_instruction or NOT_GIVEN
|
system = getattr(context, "system", NOT_GIVEN)
|
||||||
|
|
||||||
# LLM completion
|
# LLM completion
|
||||||
response = await self._client.messages.create(
|
response = await self._client.messages.create(
|
||||||
|
|||||||
@@ -792,17 +792,11 @@ class AWSBedrockLLMService(LLMService):
|
|||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def run_inference(
|
async def run_inference(self, context: LLMContext | OpenAILLMContext) -> Optional[str]:
|
||||||
self, context: LLMContext | OpenAILLMContext, system_instruction: Optional[str] = None
|
|
||||||
) -> Optional[str]:
|
|
||||||
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context.
|
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
context: The LLM context containing conversation history.
|
context: The LLM context containing conversation history.
|
||||||
system_instruction: Optional system instruction to guide the LLM's
|
|
||||||
behavior. You could also (again, optionally) provide a system
|
|
||||||
instruction directly in the context. If both are provided, the
|
|
||||||
one in the context takes precedence.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The LLM's response as a string, or None if no response is generated.
|
The LLM's response as a string, or None if no response is generated.
|
||||||
@@ -822,7 +816,7 @@ class AWSBedrockLLMService(LLMService):
|
|||||||
else:
|
else:
|
||||||
context = AWSBedrockLLMContext.upgrade_to_bedrock(context)
|
context = AWSBedrockLLMContext.upgrade_to_bedrock(context)
|
||||||
messages = context.messages
|
messages = context.messages
|
||||||
system = getattr(context, "system", None) or system_instruction
|
system = getattr(context, "system", None)
|
||||||
|
|
||||||
# Determine if we're using Claude or Nova based on model ID
|
# Determine if we're using Claude or Nova based on model ID
|
||||||
model_id = self.model_name
|
model_id = self.model_name
|
||||||
|
|||||||
@@ -733,17 +733,11 @@ class GoogleLLMService(LLMService):
|
|||||||
def _create_client(self, api_key: str, http_options: Optional[HttpOptions] = None):
|
def _create_client(self, api_key: str, http_options: Optional[HttpOptions] = None):
|
||||||
self._client = genai.Client(api_key=api_key, http_options=http_options)
|
self._client = genai.Client(api_key=api_key, http_options=http_options)
|
||||||
|
|
||||||
async def run_inference(
|
async def run_inference(self, context: LLMContext | OpenAILLMContext) -> Optional[str]:
|
||||||
self, context: LLMContext | OpenAILLMContext, system_instruction: Optional[str] = None
|
|
||||||
) -> Optional[str]:
|
|
||||||
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context.
|
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
context: The LLM context containing conversation history.
|
context: The LLM context containing conversation history.
|
||||||
system_instruction: Optional system instruction to guide the LLM's
|
|
||||||
behavior. You could also (again, optionally) provide a system
|
|
||||||
instruction directly in the context. If both are provided, the
|
|
||||||
one in the context takes precedence.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The LLM's response as a string, or None if no response is generated.
|
The LLM's response as a string, or None if no response is generated.
|
||||||
@@ -758,7 +752,7 @@ class GoogleLLMService(LLMService):
|
|||||||
else:
|
else:
|
||||||
context = GoogleLLMContext.upgrade_to_google(context)
|
context = GoogleLLMContext.upgrade_to_google(context)
|
||||||
messages = context.messages
|
messages = context.messages
|
||||||
system = getattr(context, "system_message", None) or system_instruction
|
system = getattr(context, "system_message", None)
|
||||||
|
|
||||||
generation_config = GenerateContentConfig(system_instruction=system)
|
generation_config = GenerateContentConfig(system_instruction=system)
|
||||||
|
|
||||||
|
|||||||
@@ -195,18 +195,13 @@ class LLMService(AIService):
|
|||||||
"""
|
"""
|
||||||
return self._adapter
|
return self._adapter
|
||||||
|
|
||||||
async def run_inference(
|
async def run_inference(self, context: LLMContext | OpenAILLMContext) -> Optional[str]:
|
||||||
self, context: LLMContext | OpenAILLMContext, system_instruction: Optional[str] = None
|
|
||||||
) -> Optional[str]:
|
|
||||||
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context.
|
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context.
|
||||||
|
|
||||||
Must be implemented by subclasses.
|
Must be implemented by subclasses.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
context: The LLM context containing conversation history.
|
context: The LLM context containing conversation history.
|
||||||
system_instruction: Optional system instruction to guide the LLM's
|
|
||||||
behavior. You could also (again, optionally) provide a system
|
|
||||||
instruction directly in the context.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The LLM's response as a string, or None if no response is generated.
|
The LLM's response as a string, or None if no response is generated.
|
||||||
|
|||||||
@@ -245,16 +245,11 @@ class BaseOpenAILLMService(LLMService):
|
|||||||
params.update(self._settings["extra"])
|
params.update(self._settings["extra"])
|
||||||
return params
|
return params
|
||||||
|
|
||||||
async def run_inference(
|
async def run_inference(self, context: LLMContext | OpenAILLMContext) -> Optional[str]:
|
||||||
self, context: LLMContext | OpenAILLMContext, system_instruction: Optional[str] = None
|
|
||||||
) -> Optional[str]:
|
|
||||||
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context.
|
"""Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
context: The LLM context containing conversation history.
|
context: The LLM context containing conversation history.
|
||||||
system_instruction: Optional system instruction to guide the LLM's
|
|
||||||
behavior. You could also (again, optionally) provide a system
|
|
||||||
instruction directly in the context.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The LLM's response as a string, or None if no response is generated.
|
The LLM's response as a string, or None if no response is generated.
|
||||||
|
|||||||
Reference in New Issue
Block a user