{"id":20744007,"url":"https://github.com/zylon-ai/privategpt-ts","last_synced_at":"2025-04-24T05:44:56.126Z","repository":{"id":238924109,"uuid":"768243082","full_name":"zylon-ai/privategpt-ts","owner":"zylon-ai","description":"PrivateGPT Typescript SDK","archived":false,"fork":false,"pushed_at":"2024-08-01T13:43:43.000Z","size":119,"stargazers_count":28,"open_issues_count":1,"forks_count":7,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-24T05:44:49.656Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zylon-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-06T18:16:17.000Z","updated_at":"2025-04-23T11:29:05.000Z","dependencies_parsed_at":"2024-11-17T07:14:12.714Z","dependency_job_id":"a0c8603c-7573-47f7-b380-6d9cdb975059","html_url":"https://github.com/zylon-ai/privategpt-ts","commit_stats":null,"previous_names":["zylon-ai/privategpt-ts"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zylon-ai%2Fprivategpt-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zylon-ai%2Fprivategpt-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zylon-ai%2Fprivategpt-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zylon-ai%2Fprivategpt-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zylon-ai","download_url":"https://codeload.github.com/zylon-ai/privategpt-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250573299,"owners_count":21452342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T07:13:58.174Z","updated_at":"2025-04-24T05:44:56.110Z","avatar_url":"https://github.com/zylon-ai.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PrivateGPT TypeScript SDK\n\nThe PrivateGPT TypeScript SDK is a powerful open-source library that allows developers to work with AI in a private and secure manner. This SDK provides a set of tools and utilities to interact with the PrivateGPT API and leverage its capabilities.\n\n[Live demo](https://privategpt-react.vercel.app/)\n\n[Live demo source code](https://github.com/frgarciames/privategpt-react)\n\n[Node.js demo](https://github.com/frgarciames/privategpt-nodejs)\n\n## Installation web\n\n```\nnpm install privategpt-sdk-web\n```\n\n## Installation node\n\n```\nnpm install privategpt-sdk-node\n```\n\n## Usage (js or ts)\n\n### Initialize client\n\nFirst you need to initalize the `PrivategptApiClient`:\n```ts\nconst pgptApiClient = new PrivategptApiClient({ environment: 'http://localhost:8001' });\n```\n\n### Ingest file\n\n```ts\nimport { pgptApiClient } from 'your/path';\n\nconst file = getFileFromSomewhere();\nconst ingestResponse = await pgptApiClient.ingestion.ingestFile(file);\n```\n\n### Get ingested files\n\n```ts\nimport { pgptApiClient } from 'your/path';\n\nconst ingestResponse = await pgptApiClient.ingestion.listIngested();\n```\n\n### Delete ingested file\n\n```ts\nimport { pgptApiClient } from 'your/path';\n\nawait pgptApiClient.ingestion.deleteIngested(docId);\n```\n\n### Chat completion\n\n```ts\nimport { pgptApiClient } from 'your/path';\n\n// stream way\nconst stream = await pgptApiClient.completion.chatCompletionStream({\n  messages: [\n    {\n      content: 'How are you',\n      role: 'user'\n    }\n  ],\n  includeSources: true,\n  useContext: true\n});\nconst readableStream = streamToReadableStream(stream);\nconst reader = readableStream.getReader();\nconst decoder = createChunkDecoder();\nconst loopRunner = true;\nlet result = '';\n\nwhile (loopRunner) {\n  const { value, done } = await reader.read();\n  if (done) {\n    break;\n  }\n  const decodedChunk = decoder(value);\n  if (!decodedChunk) continue;\n  result += decoder(value);\n  onNewMessage?.(result);\n}\nreturn result;\n\n// async way\nconst openAiCompletionResponse = await pgptApiClient.completion.chatCompletionStream({\n  messages: [\n    {\n      content: 'How are you',\n      role: 'user'\n    }\n  ],\n  includeSources: true,\n  useContext: true\n});\n```\n\n### Prompt completion\n\n```ts\nimport { pgptApiClient } from 'your/path';\n\n// stream way\nconst stream = await pgptApiClient.completion.promptCompletionStream({\n  promt: 'Hello! Make a joke',\n  includeSources: true,\n  useContext: true\n});\nconst readableStream = streamToReadableStream(stream);\nconst reader = readableStream.getReader();\nconst decoder = createChunkDecoder();\nconst loopRunner = true;\nlet result = '';\n\nwhile (loopRunner) {\n  const { value, done } = await reader.read();\n  if (done) {\n    break;\n  }\n  const decodedChunk = decoder(value);\n  if (!decodedChunk) continue;\n  result += decoder(value);\n  onNewMessage?.(result);\n}\nreturn result;\n\n// async way\nconst openAiCompletionResponse = await pgptApiClient.completion.promptCompletion({\n  promt: 'Hello! Make a joke',\n  includeSources: true,\n  useContext: true\n});\n```\n\n\n### Get ingested files\n\n```ts\nimport { pgptApiClient } from 'your/path';\n\nconst ingestResponse = await pgptApiClient.ingestion.listIngested();\n```\n\n### Delete ingested file\n\n```ts\nimport { pgptApiClient } from 'your/path';\n\nawait pgptApiClient.ingestion.deleteIngested(docId);\n```\n\n### Chat completion\n\n```ts\nimport { pgptApiClient } from 'your/path';\n\n// stream way\nconst stream = await pgptApiClient.completion.chatCompletionStream({\n  messages: [\n    {\n      content: 'How are you',\n      role: 'user'\n    }\n  ],\n  includeSources: true,\n  useContext: true\n});\nconst readableStream = streamToReadableStream(stream);\nconst reader = readableStream.getReader();\nconst decoder = createChunkDecoder();\nconst loopRunner = true;\nlet result = '';\n\nwhile (loopRunner) {\n  const { value, done } = await reader.read();\n  if (done) {\n    break;\n  }\n  const decodedChunk = decoder(value);\n  if (!decodedChunk) continue;\n  result += decoder(value);\n  onNewMessage?.(result);\n}\nreturn result;\n\n// async way\nconst openAiCompletionResponse = await pgptApiClient.completion.chatCompletionStream({\n  messages: [\n    {\n      content: 'How are you',\n      role: 'user'\n    }\n  ],\n  includeSources: true,\n  useContext: true\n});\n```\n\n### Prompt completion\n\n```ts\nimport { pgptApiClient } from 'your/path';\n\n// stream way\nconst stream = await pgptApiClient.completion.promptCompletionStream({\n  promt: 'Hello! Make a joke',\n  includeSources: true,\n  useContext: true\n});\nconst readableStream = streamToReadableStream(stream);\nconst reader = readableStream.getReader();\nconst decoder = createChunkDecoder();\nconst loopRunner = true;\nlet result = '';\n\nwhile (loopRunner) {\n  const { value, done } = await reader.read();\n  if (done) {\n    break;\n  }\n  const decodedChunk = decoder(value);\n  if (!decodedChunk) continue;\n  result += decoder(value);\n  onNewMessage?.(result);\n}\nreturn result;\n\n// async way\nconst openAiCompletionResponse = await pgptApiClient.completion.promptCompletion({\n  promt: 'Hello! Make a joke',\n  includeSources: true,\n  useContext: true\n});\n```\n\n## Usage (react adapter)\n\n### Initialize client\n\nFirst you need to initalize the `PrivategptApiClient`:\n```ts\nconst pgptApiClient = new PrivategptApiClient({ environment: 'http://localhost:8001' });\n```\n\n### useFiles (ingest file, delete file, get ingested files)\n\n```tsx\nimport { pgptApiClient } from 'your/path';\n\nconst YourComponent = () =\u003e {\n  const {\n    addFile,\n    isUploadingFile,\n    isDeletingFile,\n    files,\n    deleteFile,\n    isFetchingFiles,\n    errorDeletingFile,\n    errorFetchingFiles,\n    errorUploadingFile,\n  } = useFiles({\n    client: pgptApiClient,\n    fetchFiles: true // in case you don't want to fetch files automatically when using this hook\n  });\n}\n```\n\n### useChat (chat completion) \n\n```tsx\nimport { pgptApiClient } from 'your/path';\n\nconst YourComponent = () =\u003e {\n  const {\n    stop,\n    isLoading,\n    completion,\n    setCompletion\n  } = useChat({\n    messages: [\n      {\n        content: 'Hello, how are you?',\n        role: 'user'\n      }\n    ],\n    includeSources: true,\n    useContext: true,\n    onFinish: () =\u003e {\n      console.log('finished streaming');\n    },\n    client: pgptApiClient,\n    systemPrompt: 'You are a character from Battlestar Galactica'\n  });\n}\n```\n\n### usePrompt (prompt completion) \n\n```tsx\nimport { pgptApiClient } from 'your/path';\n\nconst YourComponent = () =\u003e {\n  const {\n    stop,\n    isLoading,\n    completion,\n    setCompletion\n  } = useChat({\n    prompt: 'Hello, make a joke in japanese',\n    includeSources: true,\n    useContext: true,\n    onFinish: () =\u003e {\n      console.log('finished streaming');\n    },\n    client: pgptApiClient,\n    systemPrompt: 'You are a japanese chef'\n  });\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzylon-ai%2Fprivategpt-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzylon-ai%2Fprivategpt-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzylon-ai%2Fprivategpt-ts/lists"}