From 73b6321c5c52dd0c1f01559c8483aa720bda0d7f Mon Sep 17 00:00:00 2001 From: cyclop-bot <178948048+cyclop-bot@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:19:22 -0500 Subject: [PATCH] Allow model and max tokens to be dynamic parameters in Standalone LLM Tool. --- standalone_llm_tool.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/standalone_llm_tool.py b/standalone_llm_tool.py index 834b913..b4305e6 100644 --- a/standalone_llm_tool.py +++ b/standalone_llm_tool.py @@ -6,26 +6,24 @@ from openai import OpenAI class StandaloneLLMTool: def __init__(self): self.client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY")) - self.model = "llm-preview" - self.max_tokens = 16384 - def get_detailed_instructions(self, user_prompt): + def get_detailed_instructions(self, user_prompt, model="llm-preview", max_tokens=16384): response = self.client.completions.create( - model=self.model, + model=model, prompt=user_prompt, - max_tokens=self.max_tokens + max_tokens=max_tokens ) return response - def process_user_input(self, user_prompt): + def process_user_input(self, user_prompt, model="llm-preview", max_tokens=16384): logging.info(f"Received prompt: {user_prompt}") - response = self.get_detailed_instructions(user_prompt) + response = self.get_detailed_instructions(user_prompt, model, max_tokens) logging.info("Response generated") return response.choices[0].text # Utility function for programmatic access -def get_llm_response(prompt): +def get_llm_response(prompt, model="llm-preview", max_tokens=16384): tool = StandaloneLLMTool() - return tool.process_user_input(prompt) + return tool.process_user_input(prompt, model, max_tokens)