I am trying to make LLMLingua compatible with an AI API endpoint. I have no clue what I am doing so if you encounter a problem you will probably have to ask someone else for help.
-
Install the necessary libraries: If you haven’t already, you’ll need to install the openai and llmlingua libraries. You can do this using pip:
pip install openai llmlingua
-
Set up your environment variable: This code uses an environment variable OPENROUTER_API_KEY to store your OpenAI API key. You can set this in your terminal like so:
export OPENROUTER_API_KEY=your_api_key_here
Replace your_api_key_here with your actual OpenRouter API key. -
Run the script: You can now run the script. If you’ve saved it as a Python file (e.g., script.py), you can run it in your terminal like so:
python script.py
-
Enter your contexts: The script will prompt you to enter your contexts. You can enter any text you want to be processed.
-
Enter your question: After entering your contexts, the script will prompt you to enter your question. Again, you can enter any text you want.
-
View the result: The script will print the result of the OpenAI completion.