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.
- Seamless integration with gptel
- Support for Cody’s chat capabilities
- Automatic model selection based on Sourcegraph instance configuration
- Streaming responses for real-time interaction
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)
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
Once set up, you can use gptel-cody just like any other gptel backend. Here are some common usage patterns:
- Start a new chat session:
M-x gptel RET Cody RET
- Send a query in any buffer:
M-x gptel-send
- Set Cody as the default backend:
(setq gptel-backend (gptel-make-cody "Cody" :host "sourcegraph.example.com" :key "your-api-token"))
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.
If you encounter issues:
- Ensure your Sourcegraph instance URL and API token are correct.
- Check that Cody is enabled on your Sourcegraph instance.
- Verify that your API token has the necessary permissions.
- Enable debug logging in gptel to see more detailed information about the requests and responses.
(setq gptel-log-level 'debug)
Contributions to gptel-cody are welcome! Please submit issues and pull requests on the GitHub repository.
gptel-cody is distributed under the Apache License, Version 2.0. See the LICENSE file for more details.
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.
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.
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.
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.
Battle test this a bit further to ensure we nicely report errors when they happen. EG invalid access token
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
}
}
}