Nvidia CLI AI Chat
NVIDIA CLI Chat
I bring you yet another amazing way to chat with AI, this time using nvidia NIMS! I built this terminal app to be able to test out some of the massive and state of the art LLMβs from Nvidia. All you need is a free developer API key, anyone can sign up and get free credits to play around with the models.
This project provides a command-line interface (CLI) chat application using various NVIDIA models through the NVIDIA API. The application allows users to interact with different language models, each with specific parameters, and have conversations directly in the terminal.
Features
- Supports multiple NVIDIA models with specific parameters.
- Interactive chat interface using
rich
for better terminal formatting. - Configuration via environment variables.
- API key management for secure access to NVIDIA models.
Prerequisites
- Python 3.6 or higher
- Dev account with Nvidia (itβs free) for your API Key https://build.nvidia.com/explore/discover
Installation
Clone the Repository:
1 2
git clone https://github.com/bigsk1/nvidia_cli_chat.git cd nvidia_cli_chat
Create a Virtual Environment:
1 2
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
Install Dependencies:
1
pip install -r requirements.txt
Set Up Environment Variables:
Rename .env.sample to .env:
1 2 3 4 5 6 7
API_KEY="your_single_api_key" MISTRAL_LARGE="mistralai/mistral-large" LLAMA3_70B="meta/llama3-70b-instruct" PHI_3_MINI_128K="microsoft/phi-3-mini-128k-instruct" ARCTIC="snowflake/arctic" GRANITE_34B_CODE="ibm/granite-34b-code-instruct"
Replace
your_single_api_key
with your actual personal NVIDIA API key. You can add additional models by just copying the models format in .env and adding them to models.py
Usage
Run the Chat Interface:
1
python main.py
Select a Model:
You will be prompted to select a model by number. Each model has a specific name and description to help you choose the appropriate one for your needs.
Interact with the Model:
- Type your messages in the terminal.
- The model will respond with generated text based on your input.
Exit the Chat:
- Type
exit
orquit
to end the chat session.
- Type
Project Structure
1
2
3
4
5
6
7
8
nvidia_cli_chat/
βββ main.py # Main script to run the chat interface
βββ api_handler.py # Handles API requests to NVIDIA
βββ chat_interface.py # Manages the terminal chat interface
βββ models.py # Defines available models and their parameters
βββ .env # Environment variables (not included in version control)
βββ requirements.txt # Project dependencies
βββ README.md # Project documentation
Files Overview
main.py
: The entry point of the application, which initializes the chat interface and manages the interaction loop.api_handler.py
: Contains theNvidiaAPI
class that handles requests to the NVIDIA API.chat_interface.py
: Usesrich
to create an interactive and formatted chat interface in the terminal.models.py
: Defines the available models, their descriptions, and parameters. Allows users to select a model at runtime..env
: Stores environment variables including the API key and model identifiers.requirements.txt
: Lists the Python packages required to run the application.
Example
Code examples in terminal