Skip to content

A CLI tool used to query APIs which implement the Open AI API spec

License

Notifications You must be signed in to change notification settings

Ephex2/go-gpt-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This project is meant to provide a CLI tool to allow you to interact with servers that implement the OpenAI API spec.

It offers the ability to create different profiles for different endpoints, allowing for the ability to quickly swap between different sets of saved parameters for different endpoints. For example, there could be a profile with a system prompt that is optimized for completing requests for code, while another could be setup for a more conversational experience.

This project is still a work in progress - let me know if anything needs immediate improvement!


Quickstart

Build the project, and set up the api key:

cd src
go build
go-gpt-cli config apikey mykey12345

Query away!

go-gpt-cli chat prompt "Write a short poem about a sunrise"
In the stillness of dawn's embrace,
Soft hues of light begin to grace.
Silent whispers in the sky,
Golden rays that gently fly.

A canvas painted fresh and new,
Nature's beauty in full view.
As darkness fades and colors blend,
A sunrise story without end.

Change Base Url

If you want to connect to another API which implements the OpenAI API spec, the URL can be changed quickly using the seturl command:

go-gpt-cli config seturl http://my.local.instance:PORT

Profiles and Endpoints

The term used for the routes which offer different functionality (image handling, chat completions, etc.) in this project is 'endpoints'.

Examples of endpoints are:

  • audio
  • chat
  • image
  • embeddings
  • and more

Each endpoint which can be used to make calls to the API and requires parameters to be set (e.g. model is excluded) will have an associated profile.

These profiles can be used to modify the values sent in a request to the api.

Profile Create

You can create profiles by specifying an endpoint name and name for them, as seen below:

go-gpt-cli profile create chat codereview

# ./go-gpt-cli profile create <endpointName> <profileName>

Profile Read

Profiles are represented as json; they can be read and updated as required:

go-gpt-cli profile read chat codereview > codeprofile.json
# --- perform editing as desired ---

# update the profile
go-gpt-cli profile update chat ./codeprofile.json

Default Profiles

A profile can be set as the default profile to be used for an endpoint by using the 'default' command:

go-gpt-cli profile default chat codereview

A default profile (as specified by values set in the code) will be created and set as the default profile to be used for an endpoint if no default profile for an endpoint exists when a command using that endpoint is run.

To list existing default profiles, use the config get command:

go-gpt-cli config get

{
  ...
  "audioDefaultProfile": "default",
  "chatDefaultProfile": "default",
  "embeddingsDefaultProfile": "default",
  "fileDefaultProfile": "default",
  "finetuningDefaultProfile": "default",
  "imageDefaultProfile": "default"
}

Warning: This will also output your apikey in plain-text.

Set a URL Override for a Profile

Profiles should have a Url property, as shown below:

{
    "ProfileName": "default",
    "CreateCompletionBody": {
        "messages": [
        ...
    "Url": ""
}

If the Url property is an empty string, as above, it will be disregarded.

Otherwise, the Url property will override the base url set by the go-gpt-cli configuration ( set with go-gpt-cli config seturl )

Profile Endpoints

To list the different endpoints which make use of profiles, you can run the 'profile endpoints' command:

go-gpt-cli profile endpoints
embeddings
file
finetuning
audio
chat
image

Cobra completions

This project uses standard cobra completions to help autocomplete shell commands. To setup documentation for completions, use completion -h:

go-gpt-cli completion -h

To load completions:

Bash:

  $ source <(go-gpt-cli completion bash)

  # To load completions for each session, execute once:
  # Linux:
  $ go-gpt-cli completion bash > /etc/bash_completion.d/go-gpt-cli
  # macOS:
  $ go-gpt-cli completion bash > $(brew --prefix)/etc/bash_completion.d/go-gpt-cli

Zsh:

  # If shell completion is not already enabled in your environment,
  # you will need to enable it.  You can execute the following once:

  $ echo "autoload -U compinit; compinit" >> ~/.zshrc

  # To load completions for each session, execute once:
  $ go-gpt-cli completion zsh > "${fpath[1]}/_go-gpt-cli"

  # You will need to start a new shell for this setup to take effect.

fish:

  $ go-gpt-cli completion fish | source

  # To load completions for each session, execute once:
  $ go-gpt-cli completion fish > ~/.config/fish/completions/go-gpt-cli.fish

PowerShell:

  PS> go-gpt-cli completion powershell | Out-String | Invoke-Expression

  # To load completions for every new session, run:
  PS> go-gpt-cli completion powershell > go-gpt-cli.ps1
  # and source this file from your PowerShell profile.

Usage:
  go-gpt-cli completion [bash|zsh|fish|powershell]

Flags:
  -h, --help   help for completion

About

A CLI tool used to query APIs which implement the Open AI API spec

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages