Skip to content

sourcegraph/gptel-cody

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

gptel-cody: Cody backend for gptel

gptel-cody is a backend for the gptel package, adding support for Sourcegraph’s Cody AI assistant. It integrates seamlessly with gptel, allowing Emacs users to interact with Cody using the familiar gptel interface.

Features

  • Seamless integration with gptel
  • Support for Cody’s chat capabilities
  • Automatic model selection based on Sourcegraph instance configuration
  • Streaming responses for real-time interaction

Installation

TODO we need to get this onto melpa first. Update

gptel-cody can be installed from MELPA. First, ensure you have MELPA set up in your Emacs configuration. Then, you can install it using package.el:

M-x package-install RET gptel-cody RET

Alternatively, you can use use-package with :ensure t:

(use-package gptel-cody
  :ensure t)

Setup

To use gptel-cody, you need to have access to a Sourcegraph instance with Cody enabled. You’ll need to set up the backend with your Sourcegraph URL and API token.

Add the following to your Emacs configuration:

(require 'gptel-cody)

(gptel-make-cody "Cody"
  :host "sourcegraph.example.com"  ; Replace with your Sourcegraph instance URL
  :key "your-api-token")           ; Replace with your actual API token

Usage

Once set up, you can use gptel-cody just like any other gptel backend. Here are some common usage patterns:

  1. Start a new chat session:
    M-x gptel RET Cody RET
        
  2. Send a query in any buffer:
    M-x gptel-send
        
  3. Set Cody as the default backend:
    (setq gptel-backend (gptel-make-cody "Cody"
                          :host "sourcegraph.example.com"
                          :key "your-api-token"))
        

Configuration

TODO this is all wrong

gptel-cody inherits most of its configuration from gptel. However, there are a few Cody-specific options you can customize:

  • gptel-cody-models: A list of available Cody models. This is usually automatically populated based on your Sourcegraph instance’s configuration.
  • gptel-cody--client-name: The client name used in API requests. Default is “Cody-Emacs-gptel”.
  • gptel-cody--version: The version of the gptel-cody package.

Troubleshooting

If you encounter issues:

  1. Ensure your Sourcegraph instance URL and API token are correct.
  2. Check that Cody is enabled on your Sourcegraph instance.
  3. Verify that your API token has the necessary permissions.
  4. Enable debug logging in gptel to see more detailed information about the requests and responses. (setq gptel-log-level 'debug)

Contributing

Contributions to gptel-cody are welcome! Please submit issues and pull requests on the GitHub repository.

License

gptel-cody is distributed under the Apache License, Version 2.0. See the LICENSE file for more details.

TODOs

README is correct

get key even if not gptel-backend

Right now I think this is a general issue in gptel. The builtin functions for getting the key use gptel-backend’s key, rather than the current backend.

lazily load models

Right now we query the sourcegraph API for the list of models on gptel-make-cody. We should try defer this until gptel is actually used so that we don’t do authed network requests on emacs startup.

handle empty text

I don’t know if this is a bug in gptel or strictness on Cody’s side. But I set a directive without having inline prose, and we ended up having a final bit of the transcript being

{
  "speaker": "human",
  "text": ""
}

This lead to a failure from the server.

enhanced context for enterprise

Already have a branch for this. The API is straightforward to support. However, there are plans to move enhanced context to be fully behind the simple API (ie the server parses things like repo mentions).

Goal is to extend transient menu to have an option to add enhanced context. I believe the simple approach is to translate the remote context into the local files. An alternative is to have a grep/rg/occur like buffer of the results and then and that to the context.

handle errors from backend

Battle test this a bit further to ensure we nicely report errors when they happen. EG invalid access token

remote prompts

Sourcegraph has an API to get prompts from your enterprise instance. We should provide a way to optionally sync them.

query ViewerPrompts($query: String!) {
    prompts(query: $query, first: 100, viewerIsAffiliated: true, orderBy: PROMPT_NAME_WITH_OWNER) {
        nodes {
            id
            name
            nameWithOwner
            owner {
                namespaceName
            }
            description
            draft
            definition {
                text
            }
            url
        }
        totalCount
        pageInfo {
            hasNextPage
            endCursor
        }
    }
}

About

Cody support for gptel - A simple LLM client for Emacs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published