ReplGPT.jl
Documentation for ReplGPT.jl
Key Management Functions
ReplGPT.getAPIkey
— Methodfunction 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
.
ReplGPT.setAPIkey
— Methodfunction 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()
.
ReplGPT.clearAPIkey
— Methodfunction clearAPIkey()
Deletes the OpenAI API key saved in LocalPreferences.toml
if present.
See also: ReplGPT.setAPIkey(key::String)
Model Selection
ReplGPT.setmodelname
— Methodfunction 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()
.
ReplGPT.getmodelname
— Methodfunction 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
.
ReplGPT.clearmodelname
— Methodfunction clearmodelname()
Deletes the OpenAI API model saved in LocalPreferences.toml
if present.
See also: ReplGPT.setmodelname(model::String)
Conversation Management
ReplGPT.initialize_conversation
— Methodfunction 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.
ReplGPT.save_conversation
— Methodfunction 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".
Output Formatting
ReplGPT.setFormatter
— Methodfunction 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)
ReplGPT.markdown
— Methodfunction 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.
ReplGPT.plaintext
— Methodfunction plaintext(s::String)
A simple plain text formatter. Unlike ReplGPT.markdown
, this formatter performs no text transformations except removing some leading whitespace.