More LLMs

This commit is contained in:
Cyber MacGeddon 2025-09-25 21:20:27 +01:00
parent cc45c3c6d0
commit c6012a5fed
7 changed files with 62 additions and 30 deletions

View file

@ -45,12 +45,15 @@ class Processor(LlmService):
logger.info("Cohere LLM service initialized") logger.info("Cohere 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}")
try: try:
@ -58,7 +61,7 @@ class Processor(LlmService):
model=model_name, model=model_name,
message=prompt, message=prompt,
preamble = system, preamble = system,
temperature=self.temperature, temperature=effective_temperature,
chat_history=[], chat_history=[],
prompt_truncation='auto', prompt_truncation='auto',
connectors=[] connectors=[]

View file

@ -50,12 +50,15 @@ class Processor(LlmService):
logger.info("Llamafile LLM service initialized") logger.info("Llamafile 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}")
prompt = system + "\n\n" + prompt prompt = system + "\n\n" + prompt
@ -65,15 +68,15 @@ class Processor(LlmService):
model=model_name, model=model_name,
messages=[ messages=[
{"role": "user", "content": prompt} {"role": "user", "content": prompt}
] ],
#temperature=self.temperature, temperature=effective_temperature,
#max_tokens=self.max_output, max_tokens=self.max_output,
#top_p=1, top_p=1,
#frequency_penalty=0, frequency_penalty=0,
#presence_penalty=0, presence_penalty=0,
#response_format={ response_format={
# "type": "text" "type": "text"
#} }
) )
inputtokens = resp.usage.prompt_tokens inputtokens = resp.usage.prompt_tokens

View file

@ -50,12 +50,15 @@ class Processor(LlmService):
logger.info("LMStudio LLM service initialized") logger.info("LMStudio 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}")
prompt = system + "\n\n" + prompt prompt = system + "\n\n" + prompt
@ -67,15 +70,15 @@ class Processor(LlmService):
model=model_name, model=model_name,
messages=[ messages=[
{"role": "user", "content": prompt} {"role": "user", "content": prompt}
] ],
#temperature=self.temperature, temperature=effective_temperature,
#max_tokens=self.max_output, max_tokens=self.max_output,
#top_p=1, top_p=1,
#frequency_penalty=0, frequency_penalty=0,
#presence_penalty=0, presence_penalty=0,
#response_format={ response_format={
# "type": "text" "type": "text"
#} }
) )
logger.debug(f"Full response: {resp}") logger.debug(f"Full response: {resp}")

View file

@ -48,12 +48,15 @@ class Processor(LlmService):
logger.info("Mistral LLM service initialized") logger.info("Mistral 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}")
prompt = system + "\n\n" + prompt prompt = system + "\n\n" + prompt
@ -72,7 +75,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,
frequency_penalty=0, frequency_penalty=0,

View file

@ -17,6 +17,7 @@ from .... base import LlmService, LlmResult
default_ident = "text-completion" default_ident = "text-completion"
default_model = 'gemma2:9b' default_model = 'gemma2:9b'
default_temperature = 0.0
default_ollama = os.getenv("OLLAMA_HOST", 'http://localhost:11434') default_ollama = os.getenv("OLLAMA_HOST", 'http://localhost:11434')
class Processor(LlmService): class Processor(LlmService):
@ -24,30 +25,36 @@ class Processor(LlmService):
def __init__(self, **params): def __init__(self, **params):
model = params.get("model", default_model) model = params.get("model", default_model)
temperature = params.get("temperature", default_temperature)
ollama = params.get("ollama", default_ollama) ollama = params.get("ollama", default_ollama)
super(Processor, self).__init__( super(Processor, self).__init__(
**params | { **params | {
"model": model, "model": model,
"temperature": temperature,
"ollama": ollama, "ollama": ollama,
} }
) )
self.default_model = model self.default_model = model
self.temperature = temperature
self.llm = Client(host=ollama) self.llm = Client(host=ollama)
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
try: try:
response = self.llm.generate(model_name, prompt) response = self.llm.generate(model_name, prompt, options={'temperature': effective_temperature})
response_text = response['response'] response_text = response['response']
logger.debug("Sending response...") logger.debug("Sending response...")
@ -89,6 +96,13 @@ class Processor(LlmService):
help=f'ollama (default: {default_ollama})' help=f'ollama (default: {default_ollama})'
) )
parser.add_argument(
'-t', '--temperature',
type=float,
default=default_temperature,
help=f'LLM temperature parameter (default: {default_temperature})'
)
def run(): def run():
Processor.launch(default_ident, __doc__) Processor.launch(default_ident, __doc__)

View file

@ -58,12 +58,15 @@ class Processor(LlmService):
logger.info("OpenAI LLM service initialized") logger.info("OpenAI 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}")
prompt = system + "\n\n" + prompt prompt = system + "\n\n" + prompt
@ -82,7 +85,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,
frequency_penalty=0, frequency_penalty=0,

View file

@ -51,12 +51,15 @@ class Processor(LlmService):
logger.info(f"Using TGI service at {base_url}") logger.info(f"Using TGI service at {base_url}")
logger.info("TGI LLM service initialized") logger.info("TGI 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",
@ -75,7 +78,7 @@ class Processor(LlmService):
} }
], ],
"max_tokens": self.max_output, "max_tokens": self.max_output,
"temperature": self.temperature, "temperature": effective_temperature,
} }
try: try: