mirror of
https://github.com/Warky-Devs/artemis-kit.git
synced 2025-05-19 03:37:30 +00:00
Split export. Added llm and better readme
This commit is contained in:
parent
2b20d0122d
commit
c80c6f3588
102
README.md
102
README.md
@ -5,29 +5,131 @@ A comprehensive TypeScript/JavaScript utility library focused on precision and e
|
|||||||
## Features
|
## Features
|
||||||
|
|
||||||
### String Tools
|
### String Tools
|
||||||
|
|
||||||
- Advanced string manipulation
|
- Advanced string manipulation
|
||||||
- Pattern matching and validation
|
- Pattern matching and validation
|
||||||
- Text transformation utilities
|
- Text transformation utilities
|
||||||
- Unicode handling
|
- Unicode handling
|
||||||
|
- i18n support
|
||||||
|
|
||||||
### Blob Tools
|
### Blob Tools
|
||||||
|
|
||||||
- Blob creation and modification
|
- Blob creation and modification
|
||||||
- Binary data handling
|
- Binary data handling
|
||||||
- Stream processing
|
- Stream processing
|
||||||
- MIME type management
|
- MIME type management
|
||||||
|
|
||||||
### File Conversion Tools
|
### File Conversion Tools
|
||||||
|
|
||||||
- Format conversions
|
- Format conversions
|
||||||
- File type transformations
|
- File type transformations
|
||||||
- Encoding/decoding utilities
|
- Encoding/decoding utilities
|
||||||
- Batch processing capabilities
|
- Batch processing capabilities
|
||||||
|
|
||||||
|
### Data Queue Tools
|
||||||
|
|
||||||
|
- Efficient data processing
|
||||||
|
- Batch operations support
|
||||||
|
|
||||||
|
### DOM
|
||||||
|
|
||||||
|
- DOM shortcuts like opening file links
|
||||||
|
|
||||||
|
### LLM
|
||||||
|
|
||||||
|
- LLM tools for text processing and generation
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm install @warkypublic/artemis-kit
|
pnpm install @warkypublic/artemis-kit
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Usage/Import examples
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { getNestedValue } from "@warkypublic/artemis-kit/object";
|
||||||
|
import { NestedQueue } from "@warkypublic/artemis-kit/dataqueue";
|
||||||
|
import { camelCase, formatPercent } from "@warkypublic/artemis-kit/strings";
|
||||||
|
import {
|
||||||
|
b64DecodeUnicode,
|
||||||
|
b64EncodeUnicode,
|
||||||
|
} from "@warkypublic/artemis-kit/base64";
|
||||||
|
```
|
||||||
|
|
||||||
|
## Available Methods
|
||||||
|
|
||||||
|
### Strings
|
||||||
|
|
||||||
|
- trimLeft
|
||||||
|
- trimRight
|
||||||
|
- replaceStr
|
||||||
|
- replaceStrAll
|
||||||
|
- formatNumber
|
||||||
|
- formatCurrency
|
||||||
|
- formatDate
|
||||||
|
- getPlural
|
||||||
|
- formatPercent
|
||||||
|
- titleCase
|
||||||
|
- initCaps
|
||||||
|
- camelCase
|
||||||
|
- snakeCase
|
||||||
|
- reverseSnakeCase
|
||||||
|
- splitCamelCase
|
||||||
|
- humanFileSize
|
||||||
|
- getUUID
|
||||||
|
- newUUID
|
||||||
|
- blankValue
|
||||||
|
- ...
|
||||||
|
|
||||||
|
### i18n
|
||||||
|
|
||||||
|
- createI18nManager
|
||||||
|
- \_t
|
||||||
|
- \_tt
|
||||||
|
- ...
|
||||||
|
|
||||||
|
### Base64
|
||||||
|
|
||||||
|
- b64DecodeUnicode
|
||||||
|
- b64EncodeUnicode
|
||||||
|
- base64ToBlob
|
||||||
|
- blobToBase64
|
||||||
|
- FileToBase64
|
||||||
|
- FileToBlob
|
||||||
|
- BlobToString
|
||||||
|
|
||||||
|
### Object
|
||||||
|
|
||||||
|
- getNestedValue
|
||||||
|
- setNestedValue
|
||||||
|
- objectCompare
|
||||||
|
- createSelectOptions
|
||||||
|
|
||||||
|
### Queue
|
||||||
|
|
||||||
|
- NestedQueue
|
||||||
|
|
||||||
|
### Dom
|
||||||
|
|
||||||
|
- openFileLink
|
||||||
|
|
||||||
|
### Mime
|
||||||
|
|
||||||
|
- getExtFromMime
|
||||||
|
- getExtFromFilename
|
||||||
|
- getMimeFromExt
|
||||||
|
- isValidExtForMime
|
||||||
|
- getAllExtensionsForMime
|
||||||
|
|
||||||
|
### LLM
|
||||||
|
|
||||||
|
These are still work in progress.
|
||||||
|
|
||||||
|
## Requests
|
||||||
|
|
||||||
|
Requests are welcome! Please read our contributing guidelines and send me a message on Discord or add a github issue.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
|
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
|
||||||
|
83
package.json
83
package.json
@ -9,7 +9,15 @@
|
|||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts",
|
".": "./src/index.ts",
|
||||||
"./dataqueue": "./src/dataqueue/index.ts",
|
"./dataqueue": "./src/dataqueue/index.ts",
|
||||||
"./object": "./src/object/index.ts"
|
"./object": "./src/object/index.ts",
|
||||||
|
"./strings": "./src/strings/index.ts",
|
||||||
|
"./mime": "./src/mime/index.ts",
|
||||||
|
"./base64": "./src/base64/index.ts",
|
||||||
|
"./promise": "./src/promise/index.ts",
|
||||||
|
"./dom": "./src/dom/index.ts",
|
||||||
|
"./i18n": "./src/i18n/index.ts",
|
||||||
|
"./logger": "./src/logger/index.ts",
|
||||||
|
"./llm": "./src/llm/index.ts"
|
||||||
},
|
},
|
||||||
"typesVersions": {
|
"typesVersions": {
|
||||||
"*": {
|
"*": {
|
||||||
@ -21,6 +29,30 @@
|
|||||||
],
|
],
|
||||||
"object": [
|
"object": [
|
||||||
"./src/object/index.ts"
|
"./src/object/index.ts"
|
||||||
|
],
|
||||||
|
"strings": [
|
||||||
|
"./src/strings/index.ts"
|
||||||
|
],
|
||||||
|
"mime": [
|
||||||
|
"./src/mime/index.ts"
|
||||||
|
],
|
||||||
|
"base64": [
|
||||||
|
"./src/base64/index.ts"
|
||||||
|
],
|
||||||
|
"promise": [
|
||||||
|
"./src/promise/index.ts"
|
||||||
|
],
|
||||||
|
"dom": [
|
||||||
|
"./src/dom/index.ts"
|
||||||
|
],
|
||||||
|
"i18n": [
|
||||||
|
"./src/i18n/index.ts"
|
||||||
|
],
|
||||||
|
"logger": [
|
||||||
|
"./src/logger/index.ts"
|
||||||
|
],
|
||||||
|
"llm": [
|
||||||
|
"./src/llm/index.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -32,7 +64,15 @@
|
|||||||
"exports": {
|
"exports": {
|
||||||
".": "./dist/index.js",
|
".": "./dist/index.js",
|
||||||
"./dataqueue": "./dist/dataqueue.js",
|
"./dataqueue": "./dist/dataqueue.js",
|
||||||
"./object": "./dist/object.js"
|
"./object": "./dist/object.js",
|
||||||
|
"./strings": "./dist/strings.js",
|
||||||
|
"./mime": "./dist/mime.js",
|
||||||
|
"./base64": "./dist/base64.js",
|
||||||
|
"./promise": "./dist/promise.js",
|
||||||
|
"./dom": "./dist/dom.js",
|
||||||
|
"./i18n": "./dist/i18n.js",
|
||||||
|
"./logger": "./dist/logger.js",
|
||||||
|
"./llm": "./dist/llm.js"
|
||||||
},
|
},
|
||||||
"typesVersions": {
|
"typesVersions": {
|
||||||
"*": {
|
"*": {
|
||||||
@ -40,10 +80,34 @@
|
|||||||
"./dist/index.d.ts"
|
"./dist/index.d.ts"
|
||||||
],
|
],
|
||||||
"dataqueue": [
|
"dataqueue": [
|
||||||
"./dist/dataqueue..d.ts"
|
"./dist/dataqueue.d.ts"
|
||||||
],
|
],
|
||||||
"object": [
|
"object": [
|
||||||
"./dist/object.d.ts"
|
"./dist/object.d.ts"
|
||||||
|
],
|
||||||
|
"strings": [
|
||||||
|
"./dist/strings.d.ts"
|
||||||
|
],
|
||||||
|
"mime": [
|
||||||
|
"./dist/mime.d.ts"
|
||||||
|
],
|
||||||
|
"base64": [
|
||||||
|
"./dist/base64.d.ts"
|
||||||
|
],
|
||||||
|
"promise": [
|
||||||
|
"./dist/promise.d.ts"
|
||||||
|
],
|
||||||
|
"dom": [
|
||||||
|
"./dist/dom.d.ts"
|
||||||
|
],
|
||||||
|
"i18n": [
|
||||||
|
"./dist/i18n.d.ts"
|
||||||
|
],
|
||||||
|
"logger": [
|
||||||
|
"./dist/logger.d.ts"
|
||||||
|
],
|
||||||
|
"llm": [
|
||||||
|
"./dist/llm.d.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,14 +126,17 @@
|
|||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"string",
|
"string",
|
||||||
|
"trim",
|
||||||
|
"queue",
|
||||||
"blob",
|
"blob",
|
||||||
"dependencies",
|
"base64",
|
||||||
"workspace",
|
"file",
|
||||||
"package",
|
"replace",
|
||||||
|
"tools",
|
||||||
|
"llm",
|
||||||
|
"clarion",
|
||||||
"cli",
|
"cli",
|
||||||
"tools",
|
"tools",
|
||||||
"npm",
|
|
||||||
"yarn",
|
|
||||||
"pnpm"
|
"pnpm"
|
||||||
],
|
],
|
||||||
"author": "Hein (Warkanum) Puth",
|
"author": "Hein (Warkanum) Puth",
|
||||||
|
0
src/llm/index.test.ts
Normal file
0
src/llm/index.test.ts
Normal file
9
src/llm/index.ts
Normal file
9
src/llm/index.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { getTextCompletion } from "./openapi";
|
||||||
|
|
||||||
|
export const OpenAPI = {
|
||||||
|
getTextCompletion,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
OpenAPI,
|
||||||
|
};
|
82
src/llm/openapi.ts
Normal file
82
src/llm/openapi.ts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
interface OpenAICompletionResponse {
|
||||||
|
choices: {
|
||||||
|
text: string;
|
||||||
|
index: number;
|
||||||
|
logprobs: any;
|
||||||
|
finish_reason: string;
|
||||||
|
}[];
|
||||||
|
created: number;
|
||||||
|
id: string;
|
||||||
|
model: string;
|
||||||
|
object: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CompletionOptions {
|
||||||
|
prompt: string;
|
||||||
|
options?: {
|
||||||
|
url?: string;
|
||||||
|
apiKey?: string;
|
||||||
|
maxTokens?: number;
|
||||||
|
temperature?: number;
|
||||||
|
topP?: number;
|
||||||
|
n?: number;
|
||||||
|
stream?: boolean;
|
||||||
|
stop?: string | string[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getTextCompletion({
|
||||||
|
prompt,
|
||||||
|
options: {
|
||||||
|
url = "https://api.openai.com/v1/completions",
|
||||||
|
apiKey = "x-demo",
|
||||||
|
maxTokens = 50,
|
||||||
|
temperature = 0.7,
|
||||||
|
topP = 1,
|
||||||
|
n = 1,
|
||||||
|
stream = false,
|
||||||
|
stop = null,
|
||||||
|
},
|
||||||
|
}: CompletionOptions): Promise<string> {
|
||||||
|
try {
|
||||||
|
if (!prompt) {
|
||||||
|
throw new Error("Blank prompt");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!url) {
|
||||||
|
throw new Error("OpenAI API URL is not set");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!apiKey) {
|
||||||
|
throw new Error("OpenAI API key is not set");
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${apiKey}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: "text-davinci-003",
|
||||||
|
prompt,
|
||||||
|
max_tokens: maxTokens,
|
||||||
|
temperature,
|
||||||
|
top_p: topP,
|
||||||
|
n,
|
||||||
|
stream,
|
||||||
|
stop,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`OpenAI API error: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: OpenAICompletionResponse = await response.json();
|
||||||
|
return data.choices[0].text.trim();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,14 @@ export default defineConfig({
|
|||||||
index: resolve(__dirname, "src/index.ts"),
|
index: resolve(__dirname, "src/index.ts"),
|
||||||
object: resolve(__dirname, "src/object/index.ts"),
|
object: resolve(__dirname, "src/object/index.ts"),
|
||||||
dataqueue: resolve(__dirname, "src/dataqueue/index.ts"),
|
dataqueue: resolve(__dirname, "src/dataqueue/index.ts"),
|
||||||
|
strings: resolve(__dirname, "src/strings/index.ts"),
|
||||||
|
mime: resolve(__dirname, "src/mime/index.ts"),
|
||||||
|
base64: resolve(__dirname, "src/base64/index.ts"),
|
||||||
|
promise: resolve(__dirname, "src/promise/index.ts"),
|
||||||
|
dom: resolve(__dirname, "src/dom/index.ts"),
|
||||||
|
i18n: resolve(__dirname, "src/i18n/index.ts"),
|
||||||
|
logger: resolve(__dirname, "src/logger/index.ts"),
|
||||||
|
llm: resolve(__dirname, "src/llm/index.ts"),
|
||||||
},
|
},
|
||||||
formats: ["es"],
|
formats: ["es"],
|
||||||
fileName: (format, entryname) => {
|
fileName: (format, entryname) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user