ReplGPT.jl

Documentation for ReplGPT.jl

Key Management Functions

ReplGPT.getAPIkeyMethod
function getAPIkey()

Returns an OpenAI API key to use from either the LocalPreferences.toml file or the OPENAI_API_KEY environment variable. If neither is present, returns missing.

source
ReplGPT.setAPIkeyMethod
function setAPIkey(key::String)

Sets the OpenAI API key for ReplGPT to use. The key will be saved as plaintext to your environment's LocalPreferences.toml file (perhaps somewhere like ~/.julia/environments/v1.8/LocalPreferences.toml). The key can be deleted with ReplGPT.clearAPIkeyI().

source
ReplGPT.clearAPIkeyMethod
function clearAPIkey()

Deletes the OpenAI API key saved in LocalPreferences.toml if present.

See also: ReplGPT.setAPIkey(key::String)

source

Model Selection

ReplGPT.setmodelnameMethod
function setmodelname(model::String)

Sets the OpenAI API model for ReplGPT to use. The model will be saved as plaintext to your environment's LocalPreferences.toml file (perhaps somewhere like ~/.julia/environments/v1.8/LocalPreferences.toml). The model can be deleted with ReplGPT.clearmodelname().

source
ReplGPT.getmodelnameMethod
function getmodelname()

Returns an OpenAI API model name to use from either the LocalPreferences.toml file or the OPENAI_API_MODEL environment variable. If neither is present, returns gpt-3.5-turbo.

source
ReplGPT.clearmodelnameMethod
function clearmodelname()

Deletes the OpenAI API model saved in LocalPreferences.toml if present.

See also: ReplGPT.setmodelname(model::String)

source

Conversation Management

ReplGPT.initialize_conversationMethod
function ReplGPT.initialize_conversation()

Sets the ChatGPT conversation to an empty state. This effectively starts a new chat with ChatGPT with no recollection of past messages.

source
ReplGPT.save_conversationMethod
function ReplGPT.save_conversation(filepath)

Saves the output of ReplGPT.conversation_as_string() to a file at filepath. See the chat and output of ReplGPT.save_conversation() below.

Example:

julia> 

ChatGPT> What does LISP stand for in computing?
  LISP stands for "LISt Processor".

ChatGPT> How about FORTRAN?
  FORTRAN stands for "FORmula TRANslation".

julia> ReplGPT.save_conversation("/tmp/convo.txt")

shell> cat /tmp/convo.txt
You:
----

What does LISP stand for in computing?

ChatGPT:
--------

LISP stands for "LISt Processor".

You:
----

How about FORTRAN?

ChatGPT:
--------

FORTRAN stands for "FORmula TRANslation".
source

Output Formatting

ReplGPT.setFormatterMethod
function setFormatter(f::Function)

Set the ReplGPT formatter. The default formatter is ReplGPT.markdown, but ReplGPT.plaintext may be preferred if ChatGPT's response shouldn't be displayed as Markdown text.

Other functions may be passed to setFormatter as long as they accept a string as input an return or print something.

Examples

julia> ReplGPT.setFormatter(ReplGPT.plaintext)
plaintext (generic function with 1 method)

julia> ReplGPT.setFormatter(ReplGPT.markdown)
markdown (generic function with 1 method)
source
ReplGPT.markdownMethod
function markdown(s::String)

A simple Markdown formatter. This is the default since ChatGPT seems to like emitting Markdown strings and the formatting looks nice.

See also: ReplGPT.plaintext, another formatter that does no formatting, which is nice in case you don't want the ChatGPT output to be displayed as Markdown.

source
ReplGPT.plaintextMethod
function plaintext(s::String)

A simple plain text formatter. Unlike ReplGPT.markdown, this formatter performs no text transformations except removing some leading whitespace.

source

Index