Merge pull request #166 from bucolucas/standalone-llm-tool-dev
Implement Standalone LLM Tool
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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"))
|
||||
|
||||
def get_detailed_instructions(self, user_prompt, model="llm-preview", max_tokens=16384):
|
||||
response = self.client.completions.create(
|
||||
model=model,
|
||||
prompt=user_prompt,
|
||||
max_tokens=max_tokens
|
||||
)
|
||||
return response
|
||||
|
||||
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, model, max_tokens)
|
||||
logging.info("Response generated")
|
||||
return response.choices[0].text
|
||||
|
||||
|
||||
# Utility function for programmatic access
|
||||
|
||||
def get_llm_response(prompt, model="llm-preview", max_tokens=16384):
|
||||
tool = StandaloneLLMTool()
|
||||
return tool.process_user_input(prompt, model, max_tokens)
|
||||
@@ -0,0 +1,38 @@
|
||||
# Standalone LLM Tool
|
||||
|
||||
## Overview
|
||||
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
|
||||
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)
|
||||
```
|
||||
|
||||
## Features
|
||||
- **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
|
||||
- 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:
|
||||
- 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.
|
||||
Reference in New Issue
Block a user