├── .npmrc ├── apps └── dev │ ├── .eslintrc.json │ ├── src │ ├── styles │ │ └── globals.css │ ├── constants.ts │ ├── components │ │ ├── DatabaseField.tsx │ │ ├── CollectionField.tsx │ │ ├── Button.tsx │ │ ├── PageContent.tsx │ │ ├── Textarea.tsx │ │ ├── Checkbox.tsx │ │ ├── State.tsx │ │ ├── ConnectionTypeSelect.tsx │ │ ├── Input.tsx │ │ └── Sidebar.tsx │ ├── services │ │ ├── eleganceClient.ts │ │ └── eleganceServerClient.ts │ └── app │ │ ├── api │ │ ├── kai │ │ │ └── elegance │ │ │ │ └── [route] │ │ │ │ └── route.ts │ │ └── mysql │ │ │ └── elegance │ │ │ └── [route] │ │ │ └── route.ts │ │ ├── layout.tsx │ │ ├── createEmbedding │ │ └── page.tsx │ │ ├── createFileEmbeddings │ │ └── page.tsx │ │ ├── insertOne │ │ └── page.tsx │ │ ├── findOne │ │ └── page.tsx │ │ ├── deleteMany │ │ └── page.tsx │ │ ├── insertMany │ │ └── page.tsx │ │ ├── page.tsx │ │ ├── createChatCompletion │ │ └── page.tsx │ │ ├── findMany │ │ └── page.tsx │ │ ├── createAndInsertFileEmbeddings │ │ └── page.tsx │ │ ├── updateMany │ │ └── page.tsx │ │ ├── dotProductSearch │ │ └── page.tsx │ │ └── searchChatCompletion │ │ └── page.tsx │ ├── postcss.config.js │ ├── next.config.js │ ├── .gitignore │ ├── tsconfig.json │ ├── package.json │ ├── tailwind.config.js │ └── README.md ├── .env.example ├── packages └── singlestore-elegance-sdk │ ├── src │ ├── server │ │ ├── .d.ts │ │ ├── utils │ │ │ ├── pdf.ts │ │ │ ├── kai.ts │ │ │ ├── connection.ts │ │ │ ├── dataURL.ts │ │ │ ├── helpers.ts │ │ │ ├── csv.ts │ │ │ └── mysql.ts │ │ ├── ai │ │ │ ├── embeddingToBuffer.ts │ │ │ ├── textToEmbeddings.ts │ │ │ ├── index.ts │ │ │ ├── dataURLtoEmbeddings.ts │ │ │ ├── createEmbedding.ts │ │ │ └── createChatCompletion.ts │ │ ├── services │ │ │ └── openai.ts │ │ ├── controllers │ │ │ ├── createEmbedding.ts │ │ │ ├── createChatCompletion.ts │ │ │ ├── query.ts │ │ │ ├── createFileEmbeddings.ts │ │ │ ├── deleteMany.ts │ │ │ ├── findOne.ts │ │ │ ├── updateMany.ts │ │ │ ├── findMany.ts │ │ │ ├── insertMany.ts │ │ │ ├── insertOne.ts │ │ │ ├── index.ts │ │ │ ├── createAndInsertFileEmbeddings.ts │ │ │ ├── searchChatCompletion.ts │ │ │ └── dotProductSearch.ts │ │ └── index.ts │ ├── shared │ │ ├── types │ │ │ ├── error.ts │ │ │ ├── index.ts │ │ │ ├── request.ts │ │ │ ├── connection.ts │ │ │ ├── ai.ts │ │ │ └── controllers.ts │ │ └── helpers.ts │ └── client │ │ ├── utils │ │ ├── helpers.ts │ │ └── fetcher.ts │ │ ├── index.ts │ │ ├── requests │ │ ├── createFileEmbeddings.ts │ │ ├── createAndInsertFileEmbeddings.ts │ │ └── index.ts │ │ └── hooks │ │ ├── useRequest.ts │ │ └── index.ts │ ├── .gitignore │ ├── tsconfig.json │ ├── tsup.config.ts │ ├── package.json │ └── README.md ├── .eslintrc.js ├── turbo.json ├── .gitignore ├── LICENSE.md ├── package.json └── README.md /.npmrc: -------------------------------------------------------------------------------- 1 | auto-install-peers = true 2 | -------------------------------------------------------------------------------- /apps/dev/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | DB_PASSWORD= 2 | MYSQL_USER= 3 | MYSQL_HOST= 4 | KAI_URI= 5 | OPENAI_API_KEY= -------------------------------------------------------------------------------- /packages/singlestore-elegance-sdk/src/server/.d.ts: -------------------------------------------------------------------------------- 1 | declare module "pdf-parse/lib/pdf-parse"; 2 | -------------------------------------------------------------------------------- /apps/dev/src/styles/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /apps/dev/src/constants.ts: -------------------------------------------------------------------------------- 1 | export const DB_NAME_KAI = "dev_kai"; 2 | export const DB_NAME_MYSQL = "dev_mysql"; 3 | -------------------------------------------------------------------------------- /apps/dev/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /packages/singlestore-elegance-sdk/src/shared/types/error.ts: -------------------------------------------------------------------------------- 1 | export type DefaultError = { 2 | message: string; 3 | status?: number; 4 | }; 5 | -------------------------------------------------------------------------------- /apps/dev/next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | reactStrictMode: true 4 | }; 5 | 6 | module.exports = nextConfig; 7 | -------------------------------------------------------------------------------- /packages/singlestore-elegance-sdk/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | /dist 4 | /server 5 | /types -------------------------------------------------------------------------------- /packages/singlestore-elegance-sdk/src/shared/types/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./ai"; 2 | export * from "./connection"; 3 | export * from "./controllers"; 4 | export * from "./error"; 5 | export * from "./request"; 6 | -------------------------------------------------------------------------------- /apps/dev/src/components/DatabaseField.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { Input, InputProps } from "./Input"; 4 | 5 | export function DatabaseField(props: InputProps) { 6 | return ; 7 | } 8 | -------------------------------------------------------------------------------- /packages/singlestore-elegance-sdk/src/server/utils/pdf.ts: -------------------------------------------------------------------------------- 1 | export async function pdfBufferToString(buffer: Buffer) { 2 | const pdf = (await import("pdf-parse/lib/pdf-parse")).default; 3 | return (await pdf(buffer)).text; 4 | } 5 | -------------------------------------------------------------------------------- /apps/dev/src/components/CollectionField.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { Input, InputProps } from "./Input"; 4 | 5 | export function CollectionField(props: InputProps) { 6 | return ; 7 | } 8 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | // This tells ESLint to load the config from the package `eslint-config-custom` 4 | extends: ["custom"], 5 | settings: { 6 | next: { 7 | rootDir: ["apps/*/"], 8 | }, 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /packages/singlestore-elegance-sdk/src/server/ai/embeddingToBuffer.ts: -------------------------------------------------------------------------------- 1 | import { Embedding } from "../../shared/types"; 2 | 3 | export function embeddingToBuffer(embedding: Embedding) { 4 | const float32 = new Float32Array(embedding); 5 | return Buffer.from(new Uint8Array(float32.buffer)); 6 | } 7 | -------------------------------------------------------------------------------- /packages/singlestore-elegance-sdk/src/server/services/openai.ts: -------------------------------------------------------------------------------- 1 | import OpenAI from "openai"; 2 | 3 | import type { AIConfig } from "../../shared/types"; 4 | 5 | export function createOpenAI(config: AIConfig["openai"]) { 6 | if (!config?.apiKey) throw new Error("OpenAI API key is undefined"); 7 | return new OpenAI(config); 8 | } 9 | -------------------------------------------------------------------------------- /apps/dev/src/services/eleganceClient.ts: -------------------------------------------------------------------------------- 1 | import { createEleganceClient } from "@singlestore/elegance-sdk"; 2 | 3 | export const eleganceClientKai = createEleganceClient("kai", { baseURL: "http://localhost:3001/api/kai" }); 4 | export const eleganceClientMySQL = createEleganceClient("mysql", { baseURL: "http://localhost:3001/api/mysql" }); 5 | -------------------------------------------------------------------------------- /apps/dev/src/components/Button.tsx: -------------------------------------------------------------------------------- 1 | import clsx from "clsx"; 2 | 3 | export type ButtonProps = JSX.IntrinsicElements["button"]; 4 | 5 | export function Button({ className, ...props }: ButtonProps) { 6 | return ( 7 |