File tree Expand file tree Collapse file tree 10 files changed +51
-16
lines changed
Expand file tree Collapse file tree 10 files changed +51
-16
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,15 @@ export const COPILOT_API_CONFIG = {
88} as const
99
1010export const COPILOT_API_BASE_URL = "https://api.individual.githubcopilot.com"
11- export const COPILOT_API_HEADERS = {
11+ const COPILOT_API_SPOOF_HEADERS = {
1212 "copilot-integration-id" : "vscode-chat" ,
13- "editor-version" : "vscode/1.98.0-insider" ,
1413}
1514
15+ export const buildCopilotHeaders = ( token : string ) => ( {
16+ Authorization : `token ${ token } ` ,
17+ ...COPILOT_API_SPOOF_HEADERS ,
18+ } )
19+
1620export const GITHUB_API_BASE_URL = "https://api.github.com"
1721
1822export const GITHUB_BASE_URL = "https://github.com"
Original file line number Diff line number Diff line change @@ -4,13 +4,13 @@ import { FetchError } from "ofetch"
44
55import type { EmbeddingRequest } from "~/services/copilot/embedding/types"
66
7- import { embedding } from "~/services/copilot/embedding/service"
7+ import { createEmbeddings } from "~/services/copilot/embedding/service"
88
99export const embeddingRoutes = new Hono ( )
1010
1111embeddingRoutes . post ( "/" , async ( c ) => {
1212 try {
13- const embeddings = await embedding ( await c . req . json < EmbeddingRequest > ( ) )
13+ const embeddings = await createEmbeddings ( await c . req . json < EmbeddingRequest > ( ) )
1414 return c . json ( embeddings )
1515 } catch ( error ) {
1616 if ( error instanceof FetchError ) {
Original file line number Diff line number Diff line change 11import consola from "consola"
22import { FetchError , ofetch } from "ofetch"
33
4- import { COPILOT_API_CONFIG } from "~/lib/constants "
4+ import { COPILOT_API_CONFIG } from "~/lib/api-config "
55import { modelsCache } from "~/lib/models"
66import { tokenService } from "~/lib/token"
77
Original file line number Diff line number Diff line change 11import { stream } from "fetch-event-stream"
22
3- import { COPILOT_API_CONFIG } from "~/lib/constants "
3+ import { COPILOT_API_CONFIG } from "~/lib/api-config "
44import { tokenService } from "~/lib/token"
55
66import type { ChatCompletionsPayload } from "./types"
Original file line number Diff line number Diff line change 1+ import { COPILOT_API_BASE_URL } from "~/lib/api-config"
2+ import { state } from "~/lib/state"
3+
14import type { EmbeddingRequest , EmbeddingResponse } from "./types"
25
36import { copilot } from "../../api-instance"
47
5- export const embedding = ( payload : EmbeddingRequest ) =>
6- copilot < EmbeddingResponse > ( "/embeddings" , {
7- method : "POST" ,
8- body : {
9- ...payload ,
8+ export const createEmbeddings = ( payload : EmbeddingRequest ) => {
9+ const response = await fetch ( `${ COPILOT_API_BASE_URL } /embeddings` , {
10+ headers : {
11+ authorization : `token ${ state . copilotToken } ` ,
1012 } ,
1113 } )
14+ }
15+
16+ copilot < EmbeddingResponse > ( "/embeddings" , {
17+ method : "POST" ,
18+ body : {
19+ ...payload ,
20+ } ,
21+ } )
22+
23+ export interface EmbeddingRequest {
24+ input : string | Array < string >
25+ model : string
26+ }
27+
28+ export interface Embedding {
29+ object : string
30+ embedding : Array < number >
31+ index : number
32+ }
33+
34+ export interface EmbeddingResponse {
35+ object : string
36+ data : Array < Embedding >
37+ model : string
38+ usage : {
39+ prompt_tokens : number
40+ total_tokens : number
41+ }
42+ }
Original file line number Diff line number Diff line change 1- import { GITHUB_API_BASE_URL } from "~/lib/constants "
1+ import { GITHUB_API_BASE_URL } from "~/lib/api-config "
22import { state } from "~/lib/state"
33
44export const getCopilotToken = async ( ) => {
Original file line number Diff line number Diff line change 1- import { COPILOT_API_BASE_URL } from "~/lib/constants "
1+ import { COPILOT_API_BASE_URL } from "~/lib/api-config "
22import { state } from "~/lib/state"
33
44export const getModels = async ( ) => {
Original file line number Diff line number Diff line change 1- import { GITHUB_BASE_URL , GITHUB_CLIENT_ID } from "~/lib/constants "
1+ import { GITHUB_BASE_URL , GITHUB_CLIENT_ID } from "~/lib/api-config "
22
33export async function getDeviceCode ( ) : Promise < DeviceCodeResponse > {
44 const response = await fetch ( `${ GITHUB_BASE_URL } /login/device/code` , {
Original file line number Diff line number Diff line change 1- import { GITHUB_API_BASE_URL } from "~/lib/constants "
1+ import { GITHUB_API_BASE_URL } from "~/lib/api-config "
22import { state } from "~/lib/state"
33
44export async function getGitHubUser ( ) {
Original file line number Diff line number Diff line change 1- import { GITHUB_BASE_URL , GITHUB_CLIENT_ID } from "~/lib/constants "
1+ import { GITHUB_BASE_URL , GITHUB_CLIENT_ID } from "~/lib/api-config "
22import { sleep } from "~/lib/sleep"
33
44import type { DeviceCodeResponse } from "./get-device-code"
You can’t perform that action at this time.
0 commit comments