More LLMs

This commit is contained in:
Cyber MacGeddon 2025-09-25 21:21:14 +01:00
parent c6012a5fed
commit 7c46a4defc
4 changed files with 38 additions and 17 deletions

View file

@ -55,7 +55,9 @@ class Processor(LlmService):
self.max_output = max_output self.max_output = max_output
self.default_model = model self.default_model = model
def build_prompt(self, system, content): def build_prompt(self, system, content, temperature=None):
# Use provided temperature or fall back to default
effective_temperature = temperature if temperature is not None else self.temperature
data = { data = {
"messages": [ "messages": [
@ -67,7 +69,7 @@ class Processor(LlmService):
} }
], ],
"max_tokens": self.max_output, "max_tokens": self.max_output,
"temperature": self.temperature, "temperature": effective_temperature,
"top_p": 1 "top_p": 1
} }
@ -100,18 +102,22 @@ class Processor(LlmService):
return result return result
async def generate_content(self, system, prompt, model=None): async def generate_content(self, system, prompt, model=None, temperature=None):
# Use provided model or fall back to default # Use provided model or fall back to default
model_name = model or self.default_model model_name = model or self.default_model
# Use provided temperature or fall back to default
effective_temperature = temperature if temperature is not None else self.temperature
logger.debug(f"Using model: {model_name}") logger.debug(f"Using model: {model_name}")
logger.debug(f"Using temperature: {effective_temperature}")
try: try:
prompt = self.build_prompt( prompt = self.build_prompt(
system, system,
prompt prompt,
effective_temperature
) )
response = self.call_llm(prompt) response = self.call_llm(prompt)

View file

@ -62,12 +62,15 @@ class Processor(LlmService):
azure_endpoint = endpoint, azure_endpoint = endpoint,
) )
async def generate_content(self, system, prompt, model=None): async def generate_content(self, system, prompt, model=None, temperature=None):
# Use provided model or fall back to default # Use provided model or fall back to default
model_name = model or self.default_model model_name = model or self.default_model
# Use provided temperature or fall back to default
effective_temperature = temperature if temperature is not None else self.temperature
logger.debug(f"Using model: {model_name}") logger.debug(f"Using model: {model_name}")
logger.debug(f"Using temperature: {effective_temperature}")
prompt = system + "\n\n" + prompt prompt = system + "\n\n" + prompt
@ -86,7 +89,7 @@ class Processor(LlmService):
] ]
} }
], ],
temperature=self.temperature, temperature=effective_temperature,
max_tokens=self.max_output, max_tokens=self.max_output,
top_p=1, top_p=1,
) )

View file

@ -86,12 +86,18 @@ class Processor(LlmService):
logger.info("GoogleAIStudio LLM service initialized") logger.info("GoogleAIStudio LLM service initialized")
def _get_or_create_config(self, model_name): def _get_or_create_config(self, model_name, temperature=None):
"""Get cached generation config or create new one""" """Get or create generation config with dynamic temperature"""
if model_name not in self.generation_configs: # Use provided temperature or fall back to default
logger.info(f"Creating generation config for '{model_name}'") effective_temperature = temperature if temperature is not None else self.temperature
self.generation_configs[model_name] = types.GenerateContentConfig(
temperature = self.temperature, # Create cache key that includes temperature to avoid conflicts
cache_key = f"{model_name}:{effective_temperature}"
if cache_key not in self.generation_configs:
logger.info(f"Creating generation config for '{model_name}' with temperature {effective_temperature}")
self.generation_configs[cache_key] = types.GenerateContentConfig(
temperature = effective_temperature,
top_p = 1, top_p = 1,
top_k = 40, top_k = 40,
max_output_tokens = self.max_output, max_output_tokens = self.max_output,
@ -99,16 +105,19 @@ class Processor(LlmService):
safety_settings = self.safety_settings, safety_settings = self.safety_settings,
) )
return self.generation_configs[model_name] return self.generation_configs[cache_key]
async def generate_content(self, system, prompt, model=None): async def generate_content(self, system, prompt, model=None, temperature=None):
# Use provided model or fall back to default # Use provided model or fall back to default
model_name = model or self.default_model model_name = model or self.default_model
# Use provided temperature or fall back to default
effective_temperature = temperature if temperature is not None else self.temperature
logger.debug(f"Using model: {model_name}") logger.debug(f"Using model: {model_name}")
logger.debug(f"Using temperature: {effective_temperature}")
generation_config = self._get_or_create_config(model_name) generation_config = self._get_or_create_config(model_name, effective_temperature)
# Set system instruction per request (can't be cached) # Set system instruction per request (can't be cached)
generation_config.system_instruction = system generation_config.system_instruction = system

View file

@ -52,12 +52,15 @@ class Processor(LlmService):
logger.info(f"Using vLLM service at {base_url}") logger.info(f"Using vLLM service at {base_url}")
logger.info("vLLM LLM service initialized") logger.info("vLLM LLM service initialized")
async def generate_content(self, system, prompt, model=None): async def generate_content(self, system, prompt, model=None, temperature=None):
# Use provided model or fall back to default # Use provided model or fall back to default
model_name = model or self.default_model model_name = model or self.default_model
# Use provided temperature or fall back to default
effective_temperature = temperature if temperature is not None else self.temperature
logger.debug(f"Using model: {model_name}") logger.debug(f"Using model: {model_name}")
logger.debug(f"Using temperature: {effective_temperature}")
headers = { headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
@ -67,7 +70,7 @@ class Processor(LlmService):
"model": model_name, "model": model_name,
"prompt": system + "\n\n" + prompt, "prompt": system + "\n\n" + prompt,
"max_tokens": self.max_output, "max_tokens": self.max_output,
"temperature": self.temperature, "temperature": effective_temperature,
} }
try: try: