File tree Expand file tree Collapse file tree 4 files changed +47
-64
lines changed
Expand file tree Collapse file tree 4 files changed +47
-64
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,15 @@ import { FetchError } from "ofetch"
44
55import type { EmbeddingRequest } from "~/services/copilot/embedding/types"
66
7- import { createEmbeddings } from "~/services/copilot/embedding/service "
7+ import { createEmbeddings } from "~/services/copilot/create-embeddings "
88
99export const embeddingRoutes = new Hono ( )
1010
1111embeddingRoutes . post ( "/" , async ( c ) => {
1212 try {
13- const embeddings = await createEmbeddings ( await c . req . json < EmbeddingRequest > ( ) )
13+ const embeddings = await createEmbeddings (
14+ await c . req . json < EmbeddingRequest > ( ) ,
15+ )
1416 return c . json ( embeddings )
1517 } catch ( error ) {
1618 if ( error instanceof FetchError ) {
Original file line number Diff line number Diff line change 1+ import { buildCopilotHeaders , COPILOT_API_BASE_URL } from "~/lib/api-config"
2+ import { state } from "~/lib/state"
3+
4+ export const createEmbeddings = async ( payload : EmbeddingRequest ) => {
5+ if ( ! state . copilotToken ) throw new Error ( "Copilot token not found" )
6+
7+ const response = await fetch ( `${ COPILOT_API_BASE_URL } /embeddings` , {
8+ method : "POST" ,
9+ headers : {
10+ ...buildCopilotHeaders ( state . copilotToken ) ,
11+ } ,
12+ body : JSON . stringify ( payload ) ,
13+ } )
14+
15+ if ( ! response . ok ) {
16+ throw new Error ( "Failed to create embeddings" , {
17+ cause : await response . json ( ) ,
18+ } )
19+ }
20+
21+ return ( await response . json ( ) ) as EmbeddingResponse
22+ }
23+
24+ export interface EmbeddingRequest {
25+ input : string | Array < string >
26+ model : string
27+ }
28+
29+ export interface Embedding {
30+ object : string
31+ embedding : Array < number >
32+ index : number
33+ }
34+
35+ export interface EmbeddingResponse {
36+ object : string
37+ data : Array < Embedding >
38+ model : string
39+ usage : {
40+ prompt_tokens : number
41+ total_tokens : number
42+ }
43+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments