Julia Community 🟣

Cover image for PromptingTools.jl: Getting Started
Jan Siml
Jan Siml

Posted on • Originally published at siml.earth

PromptingTools.jl: Getting Started

Introduction

PromptingTools.jl is your gateway to buying back valuable time. Just a few cents can now liberate you from the tedium of repetitive tasks, leaving you free to focus on what truly matters.

Installation

Installing PromptingTools.jl is a breeze. Ensure Julia is installed on your system, and add the package via the Julia REPL with ]add https://github.com/svilupp/PromptingTools.jl. This package is designed to be user-friendly, catering to both beginners and seasoned programmers.

Setting Up OpenAI API Key

To use PromptingTools.jl, obtain an OpenAI API key by signing up at OpenAI. Then, set it as an environment variable in Julia: ENV["OPENAI_API_KEY"] = "your-api-key".

For detailed guidance on setting persistent environment variables, refer to these links for Windows (see "Windows Set-up") and Unix/Linux.

Usage Examples

  1. String Manipulation:
   using PromptingTools
   msg = aigenerate("Rewrite this sentence in a formal tone: {{sentence}}"; sentence="Hey, what's up?")
Enter fullscreen mode Exit fullscreen mode
  1. Data Extraction:
   # Define a custom return type
   "Individual hashtag"
   struct HashTag
       tag::String
   end
   struct HashTags
       tags::Vector{HashTag}
   end
   msg = aiextract("Extract individual hashtags from this tweet: 'I love #JuliaLang and #GenerativeAI!'"; return_type = HashTags)
Enter fullscreen mode Exit fullscreen mode
  1. Image OCR:
   # gpt4v is an alias for GPT-4 Vision
   msg = aiscan("Transcribe the text in the provided image.", image_path="path_to_image.jpg", model="gpt4v")
Enter fullscreen mode Exit fullscreen mode
  1. Asking Questions:
   # alias gpt4t is optional. It will forward the query to the most powerful GPT-4 Turbo model
   ai"In Julia, what's the use case for a Channel?"gpt4t
Enter fullscreen mode Exit fullscreen mode
  1. Prompt Templates:
   aitemplates("OCR")
Enter fullscreen mode Exit fullscreen mode

Available Functions

PromptingTools.jl offers a variety of functions including aigenerate, aiextract, aiclassify, and aiscan. Each is tailored for specific tasks, ranging from generating content to working with images. Moreover, there are pre-defined prompt templates for common tasks - find the best one with aitemplates. Explore the documentation to learn more about these functions and how they can transform your workflow.

Start your AI-powered journey in Julia with PromptingTools.jl and discover a new realm of possibilities!

The title image credit goes to DALL-E 3.

Top comments (0)