Allow model and max tokens to be dynamic parameters in Standalone LLM Tool.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user