diff --git a/package.json b/package.json index f613ac9..7096c7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@premai/prem-sdk", - "version": "0.3.76", + "version": "0.3.78", "license": "MIT", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/src/index.ts b/src/index.ts index b68de48..74be062 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,11 @@ import axios, { Axios, AxiosError, AxiosRequestConfig, CreateAxiosDefaults } from "axios" import { PremBaseConfig } from "$types/index" +import repositoriesModule from "$modules/repositories" +import repositorydocumentModule from "$modules/repository.document" import chatcompletionsModule from "$modules/chat.completions" import embeddingsModule from "$modules/embeddings" import modelsModule from "$modules/models" -import repositoriesModule from "$modules/repositories" -import repositorydocumentModule from "$modules/repository.document" import feedbacksModule from "$modules/feedbacks" import tracesModule from "$modules/traces" @@ -13,11 +13,11 @@ export default class Prem { config: PremBaseConfig & { baseUrl: string } axios: Axios - chat = { completions: new chatcompletionsModule(this) } + repositories = new repositoriesModule(this) + repository = { document: new repositorydocumentModule(this) } + chat = { completions: new chatcompletionsModule(this) } embeddings = new embeddingsModule(this) models = new modelsModule(this) - repositories = new repositoriesModule(this) - repository = { document: new repositorydocumentModule(this) } feedbacks = new feedbacksModule(this) traces = new tracesModule(this) diff --git a/src/modules/repositories/index.ts b/src/modules/repositories/index.ts index a0ed04d..14b3e2c 100644 --- a/src/modules/repositories/index.ts +++ b/src/modules/repositories/index.ts @@ -1,7 +1,7 @@ import { APIModule } from "$components/index" -import v1_repositories_create from "./operations/v1_repositories_create" +import api_repositories_repositories_create from "./operations/api_repositories_repositories_create" export default class extends APIModule { - create = v1_repositories_create(this.client) + create = api_repositories_repositories_create(this.client) } \ No newline at end of file diff --git a/src/modules/repositories/operations/api_repositories_repositories_create.ts b/src/modules/repositories/operations/api_repositories_repositories_create.ts new file mode 100644 index 0000000..43d4091 --- /dev/null +++ b/src/modules/repositories/operations/api_repositories_repositories_create.ts @@ -0,0 +1,12 @@ +import { AxiosRequestConfig } from "axios" +import Prem from "$src/index" +import type { operations } from "$types/api" + +export default (client: Prem) => (params: operations["api_repositories_repositories_create"]["requestBody"]["content"]["application/json"], options?: AxiosRequestConfig): Promise => { + return client.call({ + method: "post", + url: `/api/repositories/repositories/`, + data: params, + ...options + }) +} \ No newline at end of file diff --git a/src/modules/repositories/operations/v1_repositories_create.ts b/src/modules/repositories/operations/v1_repositories_create.ts deleted file mode 100644 index 147de99..0000000 --- a/src/modules/repositories/operations/v1_repositories_create.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { AxiosRequestConfig } from "axios" -import Prem from "$src/index" -import type { operations } from "$types/api" - -export default (client: Prem) => (params: operations["v1_repositories_create"]["requestBody"]["content"]["application/json"], options?: AxiosRequestConfig): Promise => { - return client.call({ - method: "post", - url: `/v1/repositories/`, - data: params, - ...options - }) -} \ No newline at end of file diff --git a/src/modules/repository.document/index.ts b/src/modules/repository.document/index.ts index 3642c4e..b93e80c 100644 --- a/src/modules/repository.document/index.ts +++ b/src/modules/repository.document/index.ts @@ -1,7 +1,7 @@ import { APIModule } from "$components/index" -import v1_repository_document_create from "./operations/v1_repository_document_create" +import api_repositories_repository_document_create from "./operations/api_repositories_repository_document_create" export default class extends APIModule { - create = v1_repository_document_create(this.client) + create = api_repositories_repository_document_create(this.client) } \ No newline at end of file diff --git a/src/modules/repository.document/operations/api_repositories_repository_document_create.ts b/src/modules/repository.document/operations/api_repositories_repository_document_create.ts new file mode 100644 index 0000000..28fdda3 --- /dev/null +++ b/src/modules/repository.document/operations/api_repositories_repository_document_create.ts @@ -0,0 +1,12 @@ +import { AxiosRequestConfig } from "axios" +import Prem from "$src/index" +import type { operations } from "$types/api" + +export default (client: Prem) => (repository_id: string, options?: AxiosRequestConfig): Promise => { + return client.call({ + method: "post", + url: `/api/repositories/repository/${repository_id}/document`, + + ...options + }) +} \ No newline at end of file diff --git a/src/modules/repository.document/operations/v1_repository_document_create.ts b/src/modules/repository.document/operations/v1_repository_document_create.ts deleted file mode 100644 index 3b2f949..0000000 --- a/src/modules/repository.document/operations/v1_repository_document_create.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { AxiosRequestConfig } from "axios" -import Prem from "$src/index" -import type { operations } from "$types/api" -import { createReadStream, existsSync } from "fs" -import FormData from "form-data" - -export default (client: Prem) => (repository_id: string, params: operations["v1_repository_document_create"]["requestBody"]["content"]["application/json"], options?: AxiosRequestConfig): Promise => { - const filePath = params.file - - if (!existsSync(filePath)) { - throw new Error(`File not found: ${filePath}`) - } - - const formData = new FormData() - const fileStream = createReadStream(filePath) - formData.append("file", fileStream) - - return client.call({ - method: "post", - url: `/v1/repository/${repository_id}/document`, - data: formData, - headers: { - ...(options?.headers || {}), - ...formData.getHeaders(), - }, - ...options - }) -} diff --git a/src/types/api.d.ts b/src/types/api.d.ts index b24c71c..747c0a3 100644 --- a/src/types/api.d.ts +++ b/src/types/api.d.ts @@ -10,6 +10,12 @@ type XOR = (T | U) extends object ? (Without & U) | (Without & type OneOf = T extends [infer Only] ? Only : T extends [infer A, infer B, ...infer Rest] ? OneOf<[XOR, ...Rest]> : never; export interface paths { + "/api/repositories/repositories/": { + post: operations["api_repositories_repositories_create"]; + }; + "/api/repositories/repository/{repository_id}/document": { + post: operations["api_repositories_repository_document_create"]; + }; "/v1/chat/completions": { /** @description Creates a model response for the given chat conversation. Supports streaming with SSE, [documentation here](https://docs.premai.io/get-started/chat-completion-sse). */ post: operations["v1_chat_completions_create"]; @@ -24,12 +30,6 @@ export interface paths { "/v1/models/{id}/": { get: operations["v1_models_retrieve"]; }; - "/v1/repositories/": { - post: operations["v1_repositories_create"]; - }; - "/v1/repository/{repository_id}/document": { - post: operations["v1_repository_document_create"]; - }; "/v1/set_trace_feedback": { /** @description Set trace feedback */ post: operations["v1_set_trace_feedback_create"]; @@ -280,15 +280,12 @@ export interface components { /** * @description * `PENDING` - Pending * * `UPLOADED` - Uploaded - * * `PARSING` - Parsing - * * `CHUNKING` - Chunking - * * `WAITING_FOR_CHUNKS_COMPLETION` - Waiting for chunks completion - * * `PROCESSING` - Processing + * * `INDEXING` - Indexing * * `COMPLETED` - Completed * * `FAILED` - Failed * @enum {string} */ - status: "PENDING" | "UPLOADED" | "PARSING" | "CHUNKING" | "WAITING_FOR_CHUNKS_COMPLETION" | "PROCESSING" | "COMPLETED" | "FAILED"; + status: "PENDING" | "UPLOADED" | "INDEXING" | "COMPLETED" | "FAILED"; error: string | null; /** @default 0 */ chunk_count: number; @@ -489,11 +486,10 @@ export interface components { * @description * `text2text` - Text to Text * * `text2image` - Text to Image * * `text2vector` - Text to Vector - * * `autopilot` - Autopilot * @enum {string} */ - model_type?: "text2text" | "text2image" | "text2vector" | "autopilot"; - model_provider?: ("openai" | "azure" | "azure-mistral" | "cohere" | "anthropic" | "cloudflare" | "deepinfra" | "lamini" | "octoai" | "replicate" | "together" | "fireworksai" | "mistralai" | "prem" | "anyscale" | "openrouter" | "perplexity" | "groq") | "" | null; + model_type?: "text2text" | "text2image" | "text2vector"; + model_provider?: ("openai" | "azure" | "anthropic" | "prem" | "groq") | "" | null; deprecated?: boolean; }; ModelNotFoundError: { @@ -512,33 +508,19 @@ export interface components { /** * @description * `openai` - OpenAI * * `azure` - Azure OpenAI - * * `azure-mistral` - Azure Mistral - * * `cohere` - Cohere * * `anthropic` - Anthropic - * * `cloudflare` - Cloudflare - * * `deepinfra` - Deep Infra - * * `lamini` - Lamini - * * `octoai` - Octo AI - * * `replicate` - Replicate - * * `together` - Together - * * `fireworksai` - Fireworks AI - * * `mistralai` - Mistral AI * * `prem` - Prem AI - * * `anyscale` - Anyscale - * * `openrouter` - Open Router - * * `perplexity` - Perplexity * * `groq` - Groq * @enum {string} */ - ModelProviderEnum: "openai" | "azure" | "azure-mistral" | "cohere" | "anthropic" | "cloudflare" | "deepinfra" | "lamini" | "octoai" | "replicate" | "together" | "fireworksai" | "mistralai" | "prem" | "anyscale" | "openrouter" | "perplexity" | "groq"; + ModelProviderEnum: "openai" | "azure" | "anthropic" | "prem" | "groq"; /** * @description * `text2text` - Text to Text * * `text2image` - Text to Image * * `text2vector` - Text to Vector - * * `autopilot` - Autopilot * @enum {string} */ - ModelTypeEnum: "text2text" | "text2image" | "text2vector" | "autopilot"; + ModelTypeEnum: "text2text" | "text2image" | "text2vector"; NotFoundError: OneOf<[{ message: string; /** @@ -730,15 +712,12 @@ export interface components { /** * @description * `PENDING` - Pending * * `UPLOADED` - Uploaded - * * `PARSING` - Parsing - * * `CHUNKING` - Chunking - * * `WAITING_FOR_CHUNKS_COMPLETION` - Waiting for chunks completion - * * `PROCESSING` - Processing + * * `INDEXING` - Indexing * * `COMPLETED` - Completed * * `FAILED` - Failed * @enum {string} */ - StatusEnum: "PENDING" | "UPLOADED" | "PARSING" | "CHUNKING" | "WAITING_FOR_CHUNKS_COMPLETION" | "PROCESSING" | "COMPLETED" | "FAILED"; + StatusEnum: "PENDING" | "UPLOADED" | "INDEXING" | "COMPLETED" | "FAILED"; Tool: { /** * @description * `function` - function @@ -828,11 +807,10 @@ export interface components { * @description * `text2text` - Text to Text * * `text2image` - Text to Image * * `text2vector` - Text to Vector - * * `autopilot` - Autopilot * @enum {string} */ - model_type?: "text2text" | "text2image" | "text2vector" | "autopilot"; - model_provider?: ("openai" | "azure" | "azure-mistral" | "cohere" | "anthropic" | "cloudflare" | "deepinfra" | "lamini" | "octoai" | "replicate" | "together" | "fireworksai" | "mistralai" | "prem" | "anyscale" | "openrouter" | "perplexity" | "groq") | "" | null; + model_type?: "text2text" | "text2image" | "text2vector"; + model_provider?: ("openai" | "azure" | "anthropic" | "prem" | "groq") | "" | null; deprecated?: boolean; }; session_id?: string | null; @@ -937,6 +915,87 @@ export type external = Record; export interface operations { + api_repositories_repositories_create: { + requestBody: { + content: { + "application/json": { + id: number; + name: string; + description?: string | null; + organization: string; + }; + "application/x-www-form-urlencoded": { + id: number; + name: string; + description?: string | null; + organization: string; + }; + "multipart/form-data": { + id: number; + name: string; + description?: string | null; + organization: string; + }; + }; + }; + responses: { + 201: { + content: { + "application/json": { + id: number; + name: string; + description?: string | null; + organization: string; + }; + }; + }; + }; + }; + api_repositories_repository_document_create: { + parameters: { + path: { + repository_id: number; + }; + }; + requestBody: { + content: { + "multipart/form-data": { + /** Format: uri */ + file: string; + }; + }; + }; + responses: { + 201: { + content: { + "application/json": { + repository_id: number; + document_id: number; + name: string; + /** + * @description * `pdf` - PDF + * * `docx` - Word + * * `txt` - Text + * @enum {string} + */ + document_type: "pdf" | "docx" | "txt"; + /** + * @description * `PENDING` - Pending + * * `UPLOADED` - Uploaded + * * `INDEXING` - Indexing + * * `COMPLETED` - Completed + * * `FAILED` - Failed + * @enum {string} + */ + status: "PENDING" | "UPLOADED" | "INDEXING" | "COMPLETED" | "FAILED"; + error: string | null; + /** @default 0 */ + chunk_count: number; + }; + }; + }; + }; + }; /** @description Creates a model response for the given chat conversation. Supports streaming with SSE, [documentation here](https://docs.premai.io/get-started/chat-completion-sse). */ v1_chat_completions_create: { requestBody: { @@ -1624,11 +1683,10 @@ export interface operations { * @description * `text2text` - Text to Text * * `text2image` - Text to Image * * `text2vector` - Text to Vector - * * `autopilot` - Autopilot * @enum {string} */ - model_type?: "text2text" | "text2image" | "text2vector" | "autopilot"; - model_provider?: ("openai" | "azure" | "azure-mistral" | "cohere" | "anthropic" | "cloudflare" | "deepinfra" | "lamini" | "octoai" | "replicate" | "together" | "fireworksai" | "mistralai" | "prem" | "anyscale" | "openrouter" | "perplexity" | "groq") | "" | null; + model_type?: "text2text" | "text2image" | "text2vector"; + model_provider?: ("openai" | "azure" | "anthropic" | "prem" | "groq") | "" | null; deprecated?: boolean; })[]; }; @@ -1652,101 +1710,16 @@ export interface operations { * @description * `text2text` - Text to Text * * `text2image` - Text to Image * * `text2vector` - Text to Vector - * * `autopilot` - Autopilot * @enum {string} */ - model_type?: "text2text" | "text2image" | "text2vector" | "autopilot"; - model_provider?: ("openai" | "azure" | "azure-mistral" | "cohere" | "anthropic" | "cloudflare" | "deepinfra" | "lamini" | "octoai" | "replicate" | "together" | "fireworksai" | "mistralai" | "prem" | "anyscale" | "openrouter" | "perplexity" | "groq") | "" | null; + model_type?: "text2text" | "text2image" | "text2vector"; + model_provider?: ("openai" | "azure" | "anthropic" | "prem" | "groq") | "" | null; deprecated?: boolean; }; }; }; }; }; - v1_repositories_create: { - requestBody: { - content: { - "application/json": { - id: number; - name: string; - description?: string | null; - organization: string; - }; - "application/x-www-form-urlencoded": { - id: number; - name: string; - description?: string | null; - organization: string; - }; - "multipart/form-data": { - id: number; - name: string; - description?: string | null; - organization: string; - }; - }; - }; - responses: { - 201: { - content: { - "application/json": { - id: number; - name: string; - description?: string | null; - organization: string; - }; - }; - }; - }; - }; - v1_repository_document_create: { - parameters: { - path: { - repository_id: number; - }; - }; - requestBody: { - content: { - "multipart/form-data": { - /** Format: uri */ - file: string; - }; - }; - }; - responses: { - 201: { - content: { - "application/json": { - repository_id: number; - document_id: number; - name: string; - /** - * @description * `pdf` - PDF - * * `docx` - Word - * * `txt` - Text - * @enum {string} - */ - document_type: "pdf" | "docx" | "txt"; - /** - * @description * `PENDING` - Pending - * * `UPLOADED` - Uploaded - * * `PARSING` - Parsing - * * `CHUNKING` - Chunking - * * `WAITING_FOR_CHUNKS_COMPLETION` - Waiting for chunks completion - * * `PROCESSING` - Processing - * * `COMPLETED` - Completed - * * `FAILED` - Failed - * @enum {string} - */ - status: "PENDING" | "UPLOADED" | "PARSING" | "CHUNKING" | "WAITING_FOR_CHUNKS_COMPLETION" | "PROCESSING" | "COMPLETED" | "FAILED"; - error: string | null; - /** @default 0 */ - chunk_count: number; - }; - }; - }; - }; - }; /** @description Set trace feedback */ v1_set_trace_feedback_create: { requestBody: { @@ -1891,11 +1864,10 @@ export interface operations { * @description * `text2text` - Text to Text * * `text2image` - Text to Image * * `text2vector` - Text to Vector - * * `autopilot` - Autopilot * @enum {string} */ - model_type?: "text2text" | "text2image" | "text2vector" | "autopilot"; - model_provider?: ("openai" | "azure" | "azure-mistral" | "cohere" | "anthropic" | "cloudflare" | "deepinfra" | "lamini" | "octoai" | "replicate" | "together" | "fireworksai" | "mistralai" | "prem" | "anyscale" | "openrouter" | "perplexity" | "groq") | "" | null; + model_type?: "text2text" | "text2image" | "text2vector"; + model_provider?: ("openai" | "azure" | "anthropic" | "prem" | "groq") | "" | null; deprecated?: boolean; }; session_id?: string | null; diff --git a/src/types/apiComponents.d.ts b/src/types/apiComponents.d.ts index a07b77e..7ae5e6b 100644 --- a/src/types/apiComponents.d.ts +++ b/src/types/apiComponents.d.ts @@ -311,22 +311,11 @@ export type DocumentOutput = { /** * * `PENDING` - Pending * * `UPLOADED` - Uploaded - * * `PARSING` - Parsing - * * `CHUNKING` - Chunking - * * `WAITING_FOR_CHUNKS_COMPLETION` - Waiting for chunks completion - * * `PROCESSING` - Processing + * * `INDEXING` - Indexing * * `COMPLETED` - Completed * * `FAILED` - Failed */ - status: - | "PENDING" - | "UPLOADED" - | "PARSING" - | "CHUNKING" - | "WAITING_FOR_CHUNKS_COMPLETION" - | "PROCESSING" - | "COMPLETED" - | "FAILED" + status: "PENDING" | "UPLOADED" | "INDEXING" | "COMPLETED" | "FAILED" error: string chunk_count: number [k: string]: unknown @@ -581,32 +570,9 @@ export type Model = { * * `text2text` - Text to Text * * `text2image` - Text to Image * * `text2vector` - Text to Vector - * * `autopilot` - Autopilot - */ - model_type?: "text2text" | "text2image" | "text2vector" | "autopilot" - model_provider?: - | ( - | "openai" - | "azure" - | "azure-mistral" - | "cohere" - | "anthropic" - | "cloudflare" - | "deepinfra" - | "lamini" - | "octoai" - | "replicate" - | "together" - | "fireworksai" - | "mistralai" - | "prem" - | "anyscale" - | "openrouter" - | "perplexity" - | "groq" - ) - | "" - | null + */ + model_type?: "text2text" | "text2image" | "text2vector" + model_provider?: ("openai" | "azure" | "anthropic" | "prem" | "groq") | "" | null deprecated?: boolean [k: string]: unknown } @@ -628,50 +594,18 @@ export type ModelNotFoundErrorCodeEnum = "ModelNotFoundError" /** * * `openai` - OpenAI * * `azure` - Azure OpenAI - * * `azure-mistral` - Azure Mistral - * * `cohere` - Cohere * * `anthropic` - Anthropic - * * `cloudflare` - Cloudflare - * * `deepinfra` - Deep Infra - * * `lamini` - Lamini - * * `octoai` - Octo AI - * * `replicate` - Replicate - * * `together` - Together - * * `fireworksai` - Fireworks AI - * * `mistralai` - Mistral AI * * `prem` - Prem AI - * * `anyscale` - Anyscale - * * `openrouter` - Open Router - * * `perplexity` - Perplexity * * `groq` - Groq */ -export type ModelProviderEnum = - | "openai" - | "azure" - | "azure-mistral" - | "cohere" - | "anthropic" - | "cloudflare" - | "deepinfra" - | "lamini" - | "octoai" - | "replicate" - | "together" - | "fireworksai" - | "mistralai" - | "prem" - | "anyscale" - | "openrouter" - | "perplexity" - | "groq" +export type ModelProviderEnum = "openai" | "azure" | "anthropic" | "prem" | "groq" /** * * `text2text` - Text to Text * * `text2image` - Text to Image * * `text2vector` - Text to Vector - * * `autopilot` - Autopilot */ -export type ModelTypeEnum = "text2text" | "text2image" | "text2vector" | "autopilot" +export type ModelTypeEnum = "text2text" | "text2image" | "text2vector" export type NotFoundError = | { @@ -913,22 +847,11 @@ export type ResponseChoice = { /** * * `PENDING` - Pending * * `UPLOADED` - Uploaded - * * `PARSING` - Parsing - * * `CHUNKING` - Chunking - * * `WAITING_FOR_CHUNKS_COMPLETION` - Waiting for chunks completion - * * `PROCESSING` - Processing + * * `INDEXING` - Indexing * * `COMPLETED` - Completed * * `FAILED` - Failed */ -export type StatusEnum = - | "PENDING" - | "UPLOADED" - | "PARSING" - | "CHUNKING" - | "WAITING_FOR_CHUNKS_COMPLETION" - | "PROCESSING" - | "COMPLETED" - | "FAILED" +export type StatusEnum = "PENDING" | "UPLOADED" | "INDEXING" | "COMPLETED" | "FAILED" export type Tool = { /** @@ -1039,32 +962,9 @@ export type TraceRetrieve = { * * `text2text` - Text to Text * * `text2image` - Text to Image * * `text2vector` - Text to Vector - * * `autopilot` - Autopilot */ - model_type?: "text2text" | "text2image" | "text2vector" | "autopilot" - model_provider?: - | ( - | "openai" - | "azure" - | "azure-mistral" - | "cohere" - | "anthropic" - | "cloudflare" - | "deepinfra" - | "lamini" - | "octoai" - | "replicate" - | "together" - | "fireworksai" - | "mistralai" - | "prem" - | "anyscale" - | "openrouter" - | "perplexity" - | "groq" - ) - | "" - | null + model_type?: "text2text" | "text2image" | "text2vector" + model_provider?: ("openai" | "azure" | "anthropic" | "prem" | "groq") | "" | null deprecated?: boolean [k: string]: unknown }