Add GitHub token support for semantic search#54
Open
qbradley wants to merge 1 commit into
Open
Conversation
Copilot subscribers can now use their GitHub token for `lat search` embeddings instead of a separate OpenAI or Vercel API key. Problem ------- Semantic search required an OpenAI (`sk-...`) or Vercel AI Gateway (`vck_...`) API key. Users with a GitHub Copilot subscription already have access to the same `text-embedding-3-small` model via the GitHub Models API, but couldn't use it. Solution -------- Add a `github` embedding provider that targets the GitHub Models API at `https://models.github.ai/inference/embeddings`. The API is OpenAI-compatible, so the existing `embed()` function works unchanged. Provider detection recognizes three GitHub token prefixes: - `ghp_` — classic personal access tokens - `gho_` — OAuth tokens (returned by `gh auth token`) - `github_pat_` — fine-grained personal access tokens Other changes: - Add `errorHint` field to `EmbeddingProvider` type, appended to API error messages to give provider-specific troubleshooting guidance - Update `lat init` to accept GitHub tokens with `models:read` scope guidance and a `gh auth token` helper tip - Update all error messages (Anthropic rejection, unrecognized prefix) to reference GitHub as an option - Update README, lat.md/cli.md, and AGENTS.md documentation Validation ---------- - 15 provider detection tests (3 new GitHub prefix tests with full config assertions, updated Anthropic/unknown error tests, negative test for `ghs_` App tokens) - 2 new `errorHint` integration tests (mock fetch, verify hint appended on error / absent when unset) - All 159 tests pass; `tsc --noEmit` and `lat check` clean Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@qbradley is attempting to deploy a commit to the Yury Selivanov's projects Team on Vercel. A member of the Team first needs to authorize it. |
lars20070
reviewed
May 4, 2026
| '), Vercel AI Gateway (' + | ||
| styleText('dim', 'vck_...') + | ||
| '), or GitHub (' + | ||
| styleText('dim', 'ghp_...') + |
Contributor
There was a problem hiding this comment.
Maybe mention all three possible prefixes ghp_... / gho_... / github_pat_... here?
lars20070
reviewed
May 4, 2026
|
|
||
| // --- errorHint tests --- | ||
|
|
||
| import { embed } from '../src/search/embeddings.js'; |
Contributor
There was a problem hiding this comment.
Maybe move the import to the top?
Contributor
|
@qbradley Great solution for avoiding additional OpenAI or Vercel API keys. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Copilot subscribers can now use their GitHub token for
lat searchembeddings instead of a separate OpenAI or Vercel API key.Problem
Semantic search required an OpenAI (
sk-...) or Vercel AI Gateway (vck_...) API key. Users with a GitHub Copilot subscription already have access to the sametext-embedding-3-smallmodel via the GitHub Models API, but couldn't use it.Solution
Add a
githubembedding provider that targets the GitHub Models API athttps://models.github.ai/inference/embeddings. The API is OpenAI-compatible, so the existingembed()function works unchanged.Provider detection recognizes three GitHub token prefixes:
ghp_— classic personal access tokensgho_— OAuth tokens (returned bygh auth token)github_pat_— fine-grained personal access tokensOther changes:
errorHintfield toEmbeddingProvidertype, appended to API error messages to give provider-specific troubleshooting guidancelat initto accept GitHub tokens withmodels:readscope guidance and agh auth tokenhelper tipValidation
ghs_App tokens)errorHintintegration tests (mock fetch, verify hint appended on error / absent when unset)tsc --noEmitandlat checkclean