From 5ec9d3f7b59c6e61635ce38d720855523218d39e Mon Sep 17 00:00:00 2001 From: cyclop-bot <178948048+cyclop-bot@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:15:43 -0500 Subject: [PATCH 1/6] Initialize standalone LLM tool with basic class structure. --- standalone_llm_tool.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 standalone_llm_tool.py diff --git a/standalone_llm_tool.py b/standalone_llm_tool.py new file mode 100644 index 0000000..3dac90e --- /dev/null +++ b/standalone_llm_tool.py @@ -0,0 +1,33 @@ +import os +import json +import logging +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): + response = self.client.completions.create( + model=self.model, + prompt=user_prompt, + max_tokens=self.max_tokens + ) + return response + + def process_user_input(self, user_prompt): + logging.info(f"Received prompt: {user_prompt}") + response = self.get_detailed_instructions(user_prompt) + logging.info("Response generated") + return response.choices[0].text + +def main(): + tool = StandaloneLLMTool() + user_prompt = input("Enter your prompt: ") + response = tool.process_user_input(user_prompt) + print("Response:", response) + +if __name__ == '__main__': + main() From c4cbe90bd68980e7b91a120b4dcc4b0031fbe2df Mon Sep 17 00:00:00 2001 From: cyclop-bot <178948048+cyclop-bot@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:16:23 -0500 Subject: [PATCH 2/6] Add documentation for standalone LLM tool usage. --- tools/standalone_llm_tool.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tools/standalone_llm_tool.md diff --git a/tools/standalone_llm_tool.md b/tools/standalone_llm_tool.md new file mode 100644 index 0000000..5c2f4e6 --- /dev/null +++ b/tools/standalone_llm_tool.md @@ -0,0 +1,34 @@ +# Standalone LLM Tool + +## Overview +The Standalone LLM Tool is designed to interact with a preview version of a Large Language Model (LLM) independently. This tool utilizes advanced reasoning and coding capabilities to generate responses based on user input prompts. + +## Setup +1. **Environment Variables**: Ensure that the `OPENAI_API_KEY` is set in your environment to authenticate API requests. +2. **Dependencies**: Make sure all dependencies are installed as per `requirements.txt`. + +## Usage +- Run the tool via the command line: + ```bash + python standalone_llm_tool.py + ``` +- Enter a prompt when prompted: + ``` + Enter your prompt: + ``` +- View the detailed response provided by the LLM preview model. + +## Features +- **LLM Model**: Utilizes a designated LLM preview model for processing. +- **Prompt Handling**: Accepts user input and returns comprehensive instructions or code snippets. +- **Advanced Reasoning**: Leverages the model's capabilities for enhanced reasoning and coding tasks. + +## Notes +- This tool is designed for standalone execution and does not integrate with Telegram or other platforms. +- The model used here is intended for generating detailed narratives or solving coding-related queries, thanks to its preview features. + +## Troubleshooting +For any issues encountered while using the tool, consider the following: +- Verify API key validity and quota. +- Ensure your Python environment is correctly set up with necessary dependencies. +- Refer to any console logs for specific error messages to aid in debugging. From 055399c514f413302105eb936fe4dcca9b98369b Mon Sep 17 00:00:00 2001 From: cyclop-bot <178948048+cyclop-bot@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:18:02 -0500 Subject: [PATCH 3/6] Refactor Standalone LLM Tool for programmatic use. --- standalone_llm_tool.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/standalone_llm_tool.py b/standalone_llm_tool.py index 3dac90e..834b913 100644 --- a/standalone_llm_tool.py +++ b/standalone_llm_tool.py @@ -23,11 +23,9 @@ class StandaloneLLMTool: logging.info("Response generated") return response.choices[0].text -def main(): - tool = StandaloneLLMTool() - user_prompt = input("Enter your prompt: ") - response = tool.process_user_input(user_prompt) - print("Response:", response) -if __name__ == '__main__': - main() +# Utility function for programmatic access + +def get_llm_response(prompt): + tool = StandaloneLLMTool() + return tool.process_user_input(prompt) 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 4/6] 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) From 15d8172980de66fcd0064c13819136b38e64fc78 Mon Sep 17 00:00:00 2001 From: cyclop-bot <178948048+cyclop-bot@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:20:53 -0500 Subject: [PATCH 5/6] Update standalone LLM tool documentation for dynamic parameter usage and programmatic access. --- tools/standalone_llm_tool.md | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tools/standalone_llm_tool.md b/tools/standalone_llm_tool.md index 5c2f4e6..6c4d2b7 100644 --- a/tools/standalone_llm_tool.md +++ b/tools/standalone_llm_tool.md @@ -1,31 +1,35 @@ # Standalone LLM Tool ## Overview -The Standalone LLM Tool is designed to interact with a preview version of a Large Language Model (LLM) independently. This tool utilizes advanced reasoning and coding capabilities to generate responses based on user input prompts. +The Standalone LLM Tool is designed to interact with a preview version of a Large Language Model (LLM) programmatically. This tool utilizes advanced reasoning and coding capabilities to generate responses based on user input prompts. ## Setup 1. **Environment Variables**: Ensure that the `OPENAI_API_KEY` is set in your environment to authenticate API requests. 2. **Dependencies**: Make sure all dependencies are installed as per `requirements.txt`. ## Usage -- Run the tool via the command line: - ```bash - python standalone_llm_tool.py +Instead of using command-line prompts, this tool can now be integrated directly into your Python projects: + +### Function Usage +- Import the tool and use the following utility function: + ```python + from standalone_llm_tool import get_llm_response + + # Parameters: prompt (str), model (str, optional), max_tokens (int, optional) + response = get_llm_response("What is AI?", model="llm-preview", max_tokens=16384) + + print(response) ``` -- Enter a prompt when prompted: - ``` - Enter your prompt: - ``` -- View the detailed response provided by the LLM preview model. ## Features -- **LLM Model**: Utilizes a designated LLM preview model for processing. -- **Prompt Handling**: Accepts user input and returns comprehensive instructions or code snippets. -- **Advanced Reasoning**: Leverages the model's capabilities for enhanced reasoning and coding tasks. +- **LLM Model**: Accepts a designated model parameter for flexible processing. +- **Prompt Handling**: Accepts user input and provides comprehensive instructions or code snippets. +- **Dynamic Parameters**: Allows customization of the model and max tokens per request. +- **Advanced Reasoning**: Leverages the LLM's capabilities for enhanced reasoning and coding tasks. ## Notes -- This tool is designed for standalone execution and does not integrate with Telegram or other platforms. -- The model used here is intended for generating detailed narratives or solving coding-related queries, thanks to its preview features. +- The model and token parameters are dynamically handled, offering flexibility for various application needs. +- This tool is ideal for generating detailed narratives or solving coding-related queries due to its advanced LLM capabilities. ## Troubleshooting For any issues encountered while using the tool, consider the following: From bdc483993db58b42cb5940860f2b7339bc10c4d8 Mon Sep 17 00:00:00 2001 From: Jonathan Lucas Date: Mon, 28 Oct 2024 17:56:06 -0500 Subject: [PATCH 6/6] Added standalone llm --- tools/standalone_llm_tool.py | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tools/standalone_llm_tool.py diff --git a/tools/standalone_llm_tool.py b/tools/standalone_llm_tool.py new file mode 100644 index 0000000..1b712ce --- /dev/null +++ b/tools/standalone_llm_tool.py @@ -0,0 +1,58 @@ +from .base_tool import BaseTool +import os +import json +import logging +from openai import OpenAI + +class StandaloneLLMTool(BaseTool): + def __init__(self): + self.client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY")) + + def clear(self): + pass + + def get_functions(self): + return [ + { + "name": "call_external_llm", + "description": "Call an external language model", + "parameters": { + "type": "object", + "properties": { + "prompt": { + "type": "string", + "description": "The prompt you are providing" + }, + "model": { + "type": "string", + "description": "The model to use for generating the detailed instructions. Use mini for most coding tasks, preview when needing sophisticated reasoning", + "enum": ["o1-mini", "o1-preview"], + "default": "o1-mini" + }, + "max_tokens": { + "type": "integer", + "description": "The maximum number of tokens to use for generating the detailed instructions. Default is 16384.", + } + }, + "required": ["prompt"] + } + } + ] + + def execute(self, function_name, **kwargs): + if function_name == "call_external_llm": + return self.call_external_llm(kwargs.get("prompt"), kwargs.get("model"), kwargs.get("max_tokens")) + else: + error_message = f"Unknown function: {function_name}" + logging.error(error_message) + + def call_external_llm(self, prompt, model="o1-mini", max_tokens=16384): + logging.info(f"Calling external model: {model}") + response = self.client.completions.create( + model=model, + prompt=prompt, + max_tokens=max_tokens + ) + token_amount = response.summary["total_tokens"] + logging.info("Response generated, {token_amount} tokens used.") + return response.choices[0].text \ No newline at end of file