mirror of
https://github.com/Warky-Devs/vecna.git
synced 2026-05-05 01:26:58 +00:00
feat: 🎉 Vectors na Vectors, the begining
Translate 1536 <-> 768 , 3072 <-> 2048
This commit is contained in:
36
pkg/server/spec/handler.go
Normal file
36
pkg/server/spec/handler.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package spec
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"net/http"
|
||||
|
||||
"github.com/uptrace/bunrouter"
|
||||
)
|
||||
|
||||
//go:embed openapi.yaml
|
||||
var openapiYAML []byte
|
||||
|
||||
// SpecHandler serves the raw OpenAPI YAML spec.
|
||||
func SpecHandler() bunrouter.HandlerFunc {
|
||||
return func(w http.ResponseWriter, req bunrouter.Request) error {
|
||||
w.Header().Set("Content-Type", "application/yaml")
|
||||
_, err := w.Write(openapiYAML)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// DocsHandler serves the Scalar API reference UI.
|
||||
func DocsHandler() bunrouter.HandlerFunc {
|
||||
return func(w http.ResponseWriter, req bunrouter.Request) error {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
_, err := w.Write([]byte(`<!doctype html>
|
||||
<html>
|
||||
<head><title>vecna API</title><meta charset="utf-8"/></head>
|
||||
<body>
|
||||
<script id="api-reference" data-url="/openapi.yaml"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
||||
</body>
|
||||
</html>`))
|
||||
return err
|
||||
}
|
||||
}
|
||||
252
pkg/server/spec/openapi.yaml
Normal file
252
pkg/server/spec/openapi.yaml
Normal file
@@ -0,0 +1,252 @@
|
||||
openapi: "3.1.0"
|
||||
info:
|
||||
title: vecna Embedding Adapter
|
||||
description: Proxies text to a backing embedding model and adapts the result vectors between dimensions.
|
||||
version: "1.0.0"
|
||||
|
||||
servers:
|
||||
- url: http://localhost:8080
|
||||
|
||||
security:
|
||||
- BearerAuth: []
|
||||
|
||||
components:
|
||||
securitySchemes:
|
||||
BearerAuth:
|
||||
type: http
|
||||
scheme: bearer
|
||||
|
||||
schemas:
|
||||
Error:
|
||||
type: object
|
||||
properties:
|
||||
error:
|
||||
type: string
|
||||
|
||||
OpenAIEmbedRequest:
|
||||
type: object
|
||||
required: [input, model]
|
||||
properties:
|
||||
input:
|
||||
oneOf:
|
||||
- type: string
|
||||
- type: array
|
||||
items:
|
||||
type: string
|
||||
model:
|
||||
type: string
|
||||
|
||||
OpenAIEmbedResponse:
|
||||
type: object
|
||||
properties:
|
||||
object:
|
||||
type: string
|
||||
example: list
|
||||
model:
|
||||
type: string
|
||||
data:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
object:
|
||||
type: string
|
||||
example: embedding
|
||||
index:
|
||||
type: integer
|
||||
embedding:
|
||||
type: array
|
||||
items:
|
||||
type: number
|
||||
format: float
|
||||
usage:
|
||||
type: object
|
||||
properties:
|
||||
prompt_tokens:
|
||||
type: integer
|
||||
total_tokens:
|
||||
type: integer
|
||||
|
||||
GoogleEmbedContentRequest:
|
||||
type: object
|
||||
required: [content]
|
||||
properties:
|
||||
content:
|
||||
type: object
|
||||
properties:
|
||||
parts:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
text:
|
||||
type: string
|
||||
taskType:
|
||||
type: string
|
||||
|
||||
GoogleEmbedContentResponse:
|
||||
type: object
|
||||
properties:
|
||||
embedding:
|
||||
type: object
|
||||
properties:
|
||||
values:
|
||||
type: array
|
||||
items:
|
||||
type: number
|
||||
format: float
|
||||
|
||||
GoogleBatchRequest:
|
||||
type: object
|
||||
required: [requests]
|
||||
properties:
|
||||
requests:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/GoogleEmbedContentRequest'
|
||||
|
||||
GoogleBatchResponse:
|
||||
type: object
|
||||
properties:
|
||||
embeddings:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
values:
|
||||
type: array
|
||||
items:
|
||||
type: number
|
||||
format: float
|
||||
|
||||
headers:
|
||||
X-Vecna-Forward-Ms:
|
||||
description: Time spent forwarding the request to the backing model (milliseconds).
|
||||
schema:
|
||||
type: integer
|
||||
X-Vecna-Translate-Ms:
|
||||
description: Time spent in the dimension adapter (milliseconds).
|
||||
schema:
|
||||
type: integer
|
||||
X-Vecna-Total-Ms:
|
||||
description: Total request wall-clock time (milliseconds).
|
||||
schema:
|
||||
type: integer
|
||||
|
||||
paths:
|
||||
/v1/embeddings:
|
||||
post:
|
||||
summary: OpenAI-compatible embeddings
|
||||
operationId: openaiEmbeddings
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/OpenAIEmbedRequest'
|
||||
responses:
|
||||
"200":
|
||||
description: Adapted embeddings
|
||||
headers:
|
||||
X-Vecna-Forward-Ms:
|
||||
$ref: '#/components/headers/X-Vecna-Forward-Ms'
|
||||
X-Vecna-Translate-Ms:
|
||||
$ref: '#/components/headers/X-Vecna-Translate-Ms'
|
||||
X-Vecna-Total-Ms:
|
||||
$ref: '#/components/headers/X-Vecna-Total-Ms'
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/OpenAIEmbedResponse'
|
||||
"400":
|
||||
description: Bad request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
"401":
|
||||
description: Unauthorized
|
||||
"502":
|
||||
description: Backing model error
|
||||
|
||||
/v1/models/{model}:embedContent:
|
||||
post:
|
||||
summary: Google-compatible single embedContent
|
||||
operationId: googleEmbedContent
|
||||
parameters:
|
||||
- name: model
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GoogleEmbedContentRequest'
|
||||
responses:
|
||||
"200":
|
||||
description: Adapted embedding
|
||||
headers:
|
||||
X-Vecna-Forward-Ms:
|
||||
$ref: '#/components/headers/X-Vecna-Forward-Ms'
|
||||
X-Vecna-Translate-Ms:
|
||||
$ref: '#/components/headers/X-Vecna-Translate-Ms'
|
||||
X-Vecna-Total-Ms:
|
||||
$ref: '#/components/headers/X-Vecna-Total-Ms'
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GoogleEmbedContentResponse'
|
||||
"400":
|
||||
description: Bad request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
"401":
|
||||
description: Unauthorized
|
||||
"502":
|
||||
description: Backing model error
|
||||
|
||||
/v1/models/{model}:batchEmbedContents:
|
||||
post:
|
||||
summary: Google-compatible batch batchEmbedContents
|
||||
operationId: googleBatchEmbedContents
|
||||
parameters:
|
||||
- name: model
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GoogleBatchRequest'
|
||||
responses:
|
||||
"200":
|
||||
description: Adapted embeddings
|
||||
headers:
|
||||
X-Vecna-Forward-Ms:
|
||||
$ref: '#/components/headers/X-Vecna-Forward-Ms'
|
||||
X-Vecna-Translate-Ms:
|
||||
$ref: '#/components/headers/X-Vecna-Translate-Ms'
|
||||
X-Vecna-Total-Ms:
|
||||
$ref: '#/components/headers/X-Vecna-Total-Ms'
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GoogleBatchResponse'
|
||||
"400":
|
||||
description: Bad request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
"401":
|
||||
description: Unauthorized
|
||||
"502":
|
||||
description: Backing model error
|
||||
Reference in New Issue
Block a user