Enabling Cody on Sourcegraph Enterprise
This guide will walk you through the steps to install and set up Cody with your Sourcegraph Enterprise instance.
Cody enhances your coding experience by providing intelligent code suggestions, context-aware completions, and advanced code analysis.
Cody Enterprise features
To cater to your Enterprise requirements, Cody Enterprise offers the following features:
IDE Token Expiry
Site administrators can customize the time duration of the access token used by other users on the Sourcegraph Enterprise instance to connect Cody from their IDEs via the Site admin page. Administrators can choose from various options, including 7, 14, 30, 60, and 90 days.
Guardrails
Open source attribution guardrails for public code reduce the exposure to copyrighted code, commonly called copyright guardrails. This involves the implementation of a verification mechanism within Cody to ensure that any code generated by the platform does not replicate open source code.
Guardrails for public code are available to all Sourcegraph Enterprise instances and are disabled by default. You can enable it from the Site configuration. You can do so by setting "attribution.enabled": true
in site config.
It only matches code snippets that are at least 10 lines or longer, and the search corpus 290,000 open source repositories.
Admin Controls
Sourcegraph account admins have selective control over users' access to Cody Enterprise, which is now managed via the Sourcegraph role-based access control system. This provides a more intuitive user interface for assigning permission to use Cody.
Analytics
Cody Enterprise users get a clear view of usage analytics for their instance on a self-service basis. A separately managed cloud service for Cody analytics handles user auth, gets metrics data from Sourcegraph's BigQuery instance, and visualizes the metrics data.
The following metrics are available for Cody Enterprise users:
Metric Type | What is measured? |
---|---|
Active users | - Total active users - Average daily users - Average no. of days each user used Cody (of last 30 days) - Cody users by day (last 30 days) - Cody users by month (last two months) - Cody users by number of days used |
Completions | - Total accepted completions - Minutes saved per completion - Hours saved by completions - Cody completions by day - Completions acceptance rate - Weighted completions acceptance rate - Average completion latency - Acceptance rate by language |
Chat | - Total chat events - Minutes saved per chat - Hours saved by chats - Cody chats by day |
Commands | - Total command events - Minutes saved per command - Hours saved by commands - Cody commands by day - Most used commands |
To enable Cody Analytics:
- Create an account on Sourcegraph Accounts
- A user already having an account on Sourcegraph.com gets automatically migrated to Sourcegraph Accounts. Users can sign in to Cody Analytics using their email and password
- Users without a Sourcegraph.com account, please get in touch with one of our teammates. They can help with both the account setup and assigning instances to specific users
- Map your user account to a Sourcegraph instance, and this gives you access to Cody's analytics
Multi-repo context
Cody Enterprise allows up to 10 repos to support multi-repo context for users on IDE extensions. These can be added from the enhanced context selector window. Multi-repo context can search and retrieve context from multiple repositories responding to user questions, opening up more complex use cases. Enterprise users can ask questions requiring broader knowledge from across a codebase.
Enhanced context selector
The Enhanced context selector panel allows Cody Enterprise users to add up to 10 repos to search across multiple repositories. This will enable users to ask questions requiring broader knowledge from across a codebase.
Create a new chat in VS Code and click the Enhanced Context icon in the chat type field. Click the Choose Repositories... button and select up to 10 repositories from the list.
Setting up Cody Enterprise
You can set up Cody for your Enterprise instance in one of the following ways:
Cody on self-hosted Sourcegraph Enterprise
Prerequisites
- You have Sourcegraph version 5.1.0 or above
- A Sourcegraph Enterprise subscription with Cody Gateway access or an account with a third-party LLM provider
Enable Cody on your Sourcegraph instance
Cody uses one or more third-party LLM (Large Language Model) providers. Make sure you review Cody's usage and privacy notice. Code snippets are sent to a third-party language model provider when you use the Cody extension.
This requires site-admin privileges. To do so,
- First, configure your desired LLM provider either by Using Sourcegraph Cody Gateway (recommended) or Using a third-party LLM provider directly
- Next, go to Site admin > Site configuration (
/site-admin/configuration
) on your instance and set:
{
// [...]
"cody.enabled": true
}
Cody is now fully enabled on your self-hosted Sourcegraph enterprise instance!
Cody on Sourcegraph Cloud
- With Sourcegraph Cloud, you get Cody as a managed service, and you do not need to enable Cody as is required for self-hosted setup
- However, by contacting your account manager, Cody can still be enabled on-demand on your Sourcegraph instance. The Sourcegraph team will refer to the handbook
- Next, you can configure the VS Code extension by following the same steps as mentioned for the self-hosted environment
- After which, you are all set to use Cody with Sourcegraph Cloud
Learn more about running Cody on Sourcegraph Cloud.
Sourcegraph Enterprise Cloud hosted Cody Deployment
Here's a detailed breakdown of the architecture for a Cody Enterprise Cloud-hosted Cody deployment.
Enabling codebase-aware answers
The Cody: Codebase
setting in VS Code enables codebase-aware answers for the Cody extension.
- Open your VS Code workspace settings via Cmd/Ctrl+,, (or File > Preferences (Settings) on Windows & Linux)
- Search for the
Cody: Codebase
setting - Enter the repository name as listed in your Sourcegraph instance, for example,
github.com/sourcegraph/sourcegraph
without thehttps
protocol
By setting this configuration to the repository name, Cody can provide more accurate and relevant answers to your coding questions based on the context of your current codebase.
Disable Cody
To turn Cody off:
- Go to Site admin > Site configuration (
/site-admin/configuration
) on your instance and set:
{
// [...]
"cody.enabled": false
}
- Next, remove
completions
configuration if they exist
Enable Cody only for some users
To enable Cody only for some users, for example, when rolling out a Cody POC, follow all the steps mentioned in Enabling Cody on your Sourcegraph instance. Then, do the following:
Sourcegraph 5.3+
In Sourcegraph 5.3+, access to Cody is managed via user roles. By default, all users have access.
First, ensure Cody is enabled in your site configuration. Go to Site admin > Site configuration (/site-admin/configuration
) on your instance and set:
{
// [...]
"cody.enabled": true,
// Make sure cody.restrictUsersFeatureFlag is not in your configuration! If it is, remove it.
}
cody.restrictUsersFeatureFlag
is not in your site configuration. If it is, remove it or else the old feature-flag approach from Sourcegraph 5.2 and earlier will be used.Next, go to Site admin > Users & Auth > Roles (/site-admin/roles
) on your instance. On that page, you can:
- Control whether users by default have access to Cody (expand
User [System]
and toggle Cody > Access as desired) - Control whether groups of users have access to Cody (
+Create role
and enable the Cody > Access toggle as desired)
Sourcegraph 5.2 and earlier
In Sourcegraph 5.2 and earlier, you should use the feature flag cody
to turn Cody on selectively for some users. To do so:
- Go to Site admin > Site configuration (
/site-admin/configuration
) on your instance and set:
{
// [...]
"cody.enabled": true,
"cody.restrictUsersFeatureFlag": true
}
- Next, go to Site admin > Feature flags (
/site-admin/feature-flags
) - Add a feature flag called
cody
- Select the
boolean
type and set it tofalse
- Once added, click on the feature flag and use add overrides to pick users that will have access to Cody
Using a third-party LLM provider
Instead of Sourcegraph Cody Gateway, you can also configure Sourcegraph to use a third-party provider directly, like:
Anthropic
Create your own key with Anthropic here. Once you have the key, go to Site admin > Site configuration (/site-admin/configuration
) on your instance and set:
{
// [...]
"cody.enabled": true,
"completions": {
"provider": "anthropic",
"chatModel": "claude-2", // Or any other model you would like to use
"fastChatModel": "claude-instant-1", // Or any other model you would like to use
"completionModel": "claude-instant-1", // Or any other model you would like to use
"accessToken": "<key>"
}
}
OpenAI
Create your own key with OpenAI here. Once you have the key, go to Site admin > Site configuration (/site-admin/configuration
) on your instance and set:
{
// [...]
"cody.enabled": true,
"completions": {
"provider": "openai",
"chatModel": "gpt-4", // Or any other model you would like to use
"fastChatModel": "gpt-3.5-turbo", // Or any other model you would like to use
"completionModel": "gpt-3.5-turbo-instruct", // Or any other model that supports the legacy completions endpoint
"accessToken": "<key>"
}
}
Azure OpenAI
Create a project in the Azure OpenAI portal. Go to Keys and Endpoint from the project overview and get one of the keys on that page and the endpoint.
Next, under Model deployments, click "manage deployments" and ensure you deploy the models you want, for example, gpt-35-turbo
. Take note of the deployment name.
Once done, go to Site admin > Site configuration (/site-admin/configuration
) on your instance and set:
{
// [...]
"cody.enabled": true,
"completions": {
"provider": "azure-openai",
"chatModel": "<deployment name of the model>",
"fastChatModel": "<deployment name of the model>",
"completionModel": "<deployment name of the model>", // the model must support the legacy completions endpoint such as gpt-3.5-turbo-instruct
"endpoint": "<endpoint>",
"accessToken": "<See below>"
}
}
For the access token, you can either:
- As of 5.2.4 the access token can be left empty and it will rely on Environmental, Workload Identity or Managed Identity credentials configured for the
frontend
andworker
services - Set it to
<API_KEY>
if directly configuring the credentials using the API key specified in the Azure portal
Anthropic Claude through AWS Bedrock
First, make sure you can access AWS Bedrock. Then, request access to the Anthropic Claude models in Bedrock. This may take some time to provision.
Next, create an IAM user with programmatic access in your AWS account. Depending on your AWS setup, different ways may be required to provide access. All completion requests are made from the frontend
service, so this service needs to be able to access AWS. You can use instance role bindings or directly configure the IAM user credentials in the configuration.
Once ready, go to Site admin > Site configuration (/site-admin/configuration
) on your instance and set:
{
// [...]
"cody.enabled": true,
"completions": {
"provider": "aws-bedrock",
"chatModel": "anthropic.claude-v2",
"fastChatModel": "anthropic.claude-instant-v1",
"endpoint": "<AWS-Region>", // For example: us-west-2.
"accessToken": "<See below>"
}
}
For the access token, you can either:
- Leave it empty and rely on instance role bindings or other AWS configurations in the
frontend
service - Set it to
<ACCESS_KEY_ID>:<SECRET_ACCESS_KEY>
if directly configuring the credentials - Set it to
<ACCESS_KEY_ID>:<SECRET_ACCESS_KEY>:<SESSION_TOKEN>
if a session token is also required
Use StarCoder for Autocomplete
When tested with other coder models for the autocomplete use case, StarCoder offered significant improvements in quality and latency compared to our control groups for users on Sourcegraph.com. You can read more about the improvements in our October 2023 release notes and the GA release notes.
To ensure a fast and reliable experience, we are partnering with Fireworks and have set up a dedicated hardware deployment for our Enterprise users. Sourcegraph supports StarCoder using the [Cody Gateway](/cody/core-concepts/cody-gateway.
To enable StarCoder go to Site admin > Site configuration (/site-admin/configuration
) and change the completionModel
:
{
// [...]
"cody.enabled": true,
"completions": {
"provider": "sourcegraph",
"completionModel": "fireworks/starcoder"
}
}
Users of the Cody Extensions will automatically pick up this change when connected to your Enterprise instance.
It's recommended that every instance admin not using a third-party LLM provider makes this change and we are planning to make this the default in a future release.