How to Use the Command 'tgpt' (with examples)
The tgpt
command is a versatile tool that allows users to engage with various AI chatbot providers without needing API keys for many. This command can be used for chatting, generating images, writing code, executing shell commands, and more. It is highly adaptable, letting users choose from several providers like openai
, opengpts
, koboldai
, phind
, llama2
, and blackboxai
. Additionally, it offers flexibility in configuring specific parameters like prompt input and response characteristics. Below are detailed examples illustrating different use cases of the tgpt
command.
Use case 1: Chat with the default provider (GPT-3.5-turbo)
Code:
tgpt "What's the weather like today?"
Motivation:
This use case is ideal for users who want to quickly interact with the state-of-the-art GPT-3.5-turbo model to obtain natural language responses to their queries. It is convenient for first-time users or those who typically interact with the standard default model configuration.
Explanation:
tgpt
: This is the command utilized to invoke interaction with an AI chatbot."What's the weather like today?"
: This is the prompt or query being sent to the default AI model for processing and response.
Example Output:
The weather today varies by location, but many areas are experiencing sunny skies with mild temperatures. Please check your local weather service for precise details.
Use case 2: Start multi-line interactive mode
Code:
tgpt --multiline
Motivation:
The multi-line interactive mode is perfect for an in-depth conversation where ideas or questions are expanded over multiple lines before receiving a response. It allows for a more fluid and natural conversation flow, similar to chatting in a messaging app.
Explanation:
tgpt
: Calls the tgpt command interface.--multiline
: This flag initiates a multi-line interaction where the user can enter multiple lines of text as input before submitting for a response.
Example Output:
Enter your query (press Ctrl+D to submit):
How does photosynthesis work?
Sure! Photosynthesis is the process by which...
Use case 3: Generate images and save them to the current directory
Code:
tgpt --image "Draw a futuristic city skyline"
Motivation:
This command is used by creative professionals or hobbyists looking to generate visual content based on elements described verbally. It becomes particularly useful for concept artists, designers, and storytellers aiming to visualize scenes or ideas quickly.
Explanation:
tgpt
: Command invoked to interact with AI capabilities.--image
: This argument specifies that the output of the interaction should be an image generated from the prompt."Draw a futuristic city skyline"
: The prompt instructs the AI to generate an image reflecting this description.
Example Output:
Image saved as futuristic_city_skyline.png
(Note: The actual image file would appear in the current working directory.)
Use case 4: Generate code with the default provider (GPT-3.5-turbo)
Code:
tgpt --code "Write a Python function to sort a list"
Motivation:
Developers or learners who want to quickly draft code solutions can benefit from this use case. It leverages the AI’s prowess in coding to obtain code snippets, best practices, or even complex algorithms without delving into documentation for simple tasks.
Explanation:
tgpt
: Invoking the tgpt command.--code
: Signals that the returned output should be in the form of source code."Write a Python function to sort a list"
: The specific instruction to the AI for generating the desired code.
Example Output:
def sort_list(my_list):
return sorted(my_list)
Use case 5: Chat with a specific provider quietly (without animations)
Code:
tgpt --provider openai --quiet --whole "Tell me a joke"
Motivation:
This option is suitable for users who want to interact with a specific provider and prefer a streamlined experience, without animations or additional visual effects. It caters to environments where quick, quiet output is necessary, such as during presentations or demos.
Explanation:
tgpt
: Initiates the command.--provider openai
: Specifies the use of OpenAI’s model for processing the prompt.--quiet
: Suppresses any loading animations or extra visual feedback.--whole
: Ensures that the entire response is returned at once, rather than piecemeal."Tell me a joke"
: The input query asking for a humorous output.
Example Output:
Why don't scientists trust atoms? Because they make up everything!
Use case 6: Generate and execute shell commands using a specific provider (with confirmation prompt)
Code:
tgpt --provider llama2 --shell "List all files in the current directory"
Motivation:
This scenario aids users in generating shell commands efficiently and safely executing them with a confirmation step. It is beneficial for system administrators, developers, or enthusiasts exploring command-line interfaces with ease of automation.
Explanation:
tgpt
: The command execution starts here.--provider llama2
: Specifies that thellama2
AI model will be used.--shell
: Requests the AI to generate a shell command."List all files in the current directory"
: Describes the task to be accomplished via shell command.
Example Output:
Command generated: ls
Execute? (y/n): y
file1.txt
file2.pdf
directory1/
Use case 7: Prompt with an API key, model, max response length, temperature, and top_p
(required when using OpenAI provider)
Code:
tgpt --provider openai --key "api_key" --model "gpt-3.5-turbo" --max-length 10 --temperature 0.7 --top_p 0.9 "How do I plant tomatoes?"
Motivation:
This use case is designed for power users who require specific tuning of the AI response, providing control over response length, creativity (temperature), and diversity (top_p
). It targets developers, researchers, or advanced users mainly working with OpenAI.
Explanation:
tgpt
: Starts the interaction with AI.--provider openai
: Directs to use OpenAI’s models.--key "api_key"
: Specific API key required for authentication.--model "gpt-3.5-turbo"
: Indicates the selected AI model for processing.--max-length 10
: Limits the response to a maximum of 10 tokens (words or characters based on context).--temperature 0.7
: Controls the randomness of the response; higher values result in more creative output.--top_p 0.9
: Dictates the nucleus sampling value, balancing response diversity."How do I plant tomatoes?"
: The input query pertaining to gardening.
Example Output:
Till soil, plant seeds, water regularly.
Use case 8: Feed a file as additional pre-prompt input
Code:
tgpt --provider blackboxai "Summarize this document" < path/to/file
Motivation:
Users dealing with large text files who need summaries or insights can greatly benefit from this feature, especially if the raw data is complex or lengthy. This is particularly handy for analysts, students, or knowledge workers who routinely work with documents.
Explanation:
tgpt
: Base command to interact with AI.--provider blackboxai
: Specifies that theblackboxai
model will be utilized."Summarize this document"
: Instruction directing the AI on the desired output.< path/to/file
: A redirection operator feeding the content of the file as input before the prompt.
Example Output:
The document outlines key strategies in project management, emphasizing efficiency and team collaboration...
Conclusion:
The tgpt
command is a powerful and flexible tool that can be customized to suit various user needs, from simple conversational tasks to advanced features like code generation and document summarization. This guide showcases how each use case can be applied in real-world scenarios, enabling users to harness artificial intelligence in a multitude of innovative ways.