@ztimson/ai-utils 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +106 -0
- package/dist/ai.d.ts +54 -0
- package/dist/antrhopic.d.ts +14 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +633 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +621 -0
- package/dist/index.mjs.map +1 -0
- package/dist/llm.d.ts +110 -0
- package/dist/ollama.d.ts +14 -0
- package/dist/open-ai.d.ts +14 -0
- package/dist/provider.d.ts +7 -0
- package/dist/tools.d.ts +42 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2023 Zakary Timson
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<!-- Header -->
|
|
2
|
+
<div id="top" align="center">
|
|
3
|
+
<br />
|
|
4
|
+
|
|
5
|
+
<!-- Logo -->
|
|
6
|
+
<img src="https://git.zakscode.com/repo-avatars/a90851ca730480ec37a5c0c2c4f1b4609eee5eadf806eaf16c83ac4cb7493aa9" alt="Logo" width="200" height="200">
|
|
7
|
+
|
|
8
|
+
<!-- Title -->
|
|
9
|
+
### @ztimson/ai-utils
|
|
10
|
+
|
|
11
|
+
<!-- Description -->
|
|
12
|
+
AI Utility Library - Unified interface for multiple AI providers
|
|
13
|
+
|
|
14
|
+
<!-- Repo badges -->
|
|
15
|
+
[](https://git.zakscode.com/ztimson/ai-utils/tags)
|
|
16
|
+
[](https://git.zakscode.com/ztimson/ai-utils/pulls)
|
|
17
|
+
[](https://git.zakscode.com/ztimson/ai-utils/issues)
|
|
18
|
+
|
|
19
|
+
<!-- Links -->
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
<div>
|
|
23
|
+
<a href="https://ai-utils.docs.zakscode.com" target="_blank">Documentation</a>
|
|
24
|
+
• <a href="https://git.zakscode.com/ztimson/ai-utils/releases" target="_blank">Release Notes</a>
|
|
25
|
+
• <a href="https://git.zakscode.com/ztimson/ai-utils/issues/new?template=.github%2fissue_template%2fbug.md" target="_blank">Report a Bug</a>
|
|
26
|
+
• <a href="https://git.zakscode.com/ztimson/ai-utils/issues/new?template=.github%2fissue_template%2fenhancement.md" target="_blank">Request a Feature</a>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
## Table of Contents
|
|
33
|
+
- [@ztimson/ai-utils](#top)
|
|
34
|
+
- [About](#about)
|
|
35
|
+
- [Features](#features)
|
|
36
|
+
- [Built With](#built-with)
|
|
37
|
+
- [Setup](#setup)
|
|
38
|
+
- [Production](#production)
|
|
39
|
+
- [Development](#development)
|
|
40
|
+
- [Documentation](https://ai-utils.docs.zakscode.com/)
|
|
41
|
+
- [License](#license)
|
|
42
|
+
|
|
43
|
+
## About
|
|
44
|
+
|
|
45
|
+
A TypeScript library that provides a unified interface for working with multiple AI providers, making it easy to integrate various AI capabilities into your applications.
|
|
46
|
+
|
|
47
|
+
### Features
|
|
48
|
+
|
|
49
|
+
- **Multi-Provider LLM Support**: Seamlessly work with OpenAI, Anthropic (Claude), and Self-hosted (Ollama) models
|
|
50
|
+
- **Audio Speech Recognition (ASR)**: Convert audio to text using Whisper models
|
|
51
|
+
- **Optical Character Recognition (OCR)**: Extract text from images using Tesseract
|
|
52
|
+
- **Semantic Similarity**: Compare text similarity using tensor-based cosine similarity
|
|
53
|
+
- **Provider Abstraction**: Switch between AI providers without changing your code
|
|
54
|
+
|
|
55
|
+
### Built With
|
|
56
|
+
[](https://anthropic.com/)
|
|
57
|
+
[](https://openai.com/)
|
|
58
|
+
[](https://ollama.com/)
|
|
59
|
+
[](https://tensorflow.org/)
|
|
60
|
+
[](https://tesseract-ocr.github.io/)
|
|
61
|
+
[](https://typescriptlang.org/)
|
|
62
|
+
[](https://github.com/ggerganov/whisper.cpp)
|
|
63
|
+
|
|
64
|
+
## Setup
|
|
65
|
+
|
|
66
|
+
<details>
|
|
67
|
+
<summary>
|
|
68
|
+
<h3 id="production" style="display: inline">
|
|
69
|
+
Production
|
|
70
|
+
</h3>
|
|
71
|
+
</summary>
|
|
72
|
+
|
|
73
|
+
#### Prerequisites
|
|
74
|
+
- [Node.js](https://nodejs.org/en/download)
|
|
75
|
+
|
|
76
|
+
#### Instructions
|
|
77
|
+
1. Install the package: `npm i @ztimson/ai-utils`
|
|
78
|
+
|
|
79
|
+
</details>
|
|
80
|
+
|
|
81
|
+
<details>
|
|
82
|
+
<summary>
|
|
83
|
+
<h3 id="development" style="display: inline">
|
|
84
|
+
Development
|
|
85
|
+
</h3>
|
|
86
|
+
</summary>
|
|
87
|
+
|
|
88
|
+
#### Prerequisites
|
|
89
|
+
- [Node.js](https://nodejs.org/en/download)
|
|
90
|
+
|
|
91
|
+
#### Instructions
|
|
92
|
+
1. Install the dependencies: `npm i`
|
|
93
|
+
2. Build library: `npm build`
|
|
94
|
+
3. Run unit tests: `npm test`
|
|
95
|
+
|
|
96
|
+
</details>
|
|
97
|
+
|
|
98
|
+
## Documentation
|
|
99
|
+
|
|
100
|
+
[Available Here](https://ai-utils.docs.zakscode.com/)
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
Copyright © 2023 Zakary Timson | Available under MIT Licensing
|
|
105
|
+
|
|
106
|
+
See the [license](_media/LICENSE) for more information.
|
package/dist/ai.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { LLM, LLMOptions } from './llm';
|
|
2
|
+
export type AiOptions = LLMOptions & {
|
|
3
|
+
whisper?: {
|
|
4
|
+
/** Whisper binary location */
|
|
5
|
+
binary: string;
|
|
6
|
+
/** Model */
|
|
7
|
+
model: WhisperModel;
|
|
8
|
+
/** Working directory for models and temporary files */
|
|
9
|
+
path: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type WhisperModel = 'tiny' | 'base' | 'small' | 'medium' | 'large';
|
|
13
|
+
export declare class Ai {
|
|
14
|
+
readonly options: AiOptions;
|
|
15
|
+
private downloads;
|
|
16
|
+
private whisperModel;
|
|
17
|
+
/** Large Language Models */
|
|
18
|
+
llm: LLM;
|
|
19
|
+
constructor(options: AiOptions);
|
|
20
|
+
/**
|
|
21
|
+
* Convert audio to text using Auditory Speech Recognition
|
|
22
|
+
* @param {string} path Path to audio
|
|
23
|
+
* @param model Whisper model
|
|
24
|
+
* @returns {Promise<any>} Extracted text
|
|
25
|
+
*/
|
|
26
|
+
asr(path: string, model?: WhisperModel): Promise<string | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Downloads the specified Whisper model if it is not already present locally.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} model Whisper model that will be downloaded
|
|
31
|
+
* @return {Promise<void>} A promise that resolves once the model is downloaded and saved locally.
|
|
32
|
+
*/
|
|
33
|
+
downloadAsrModel(model: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Convert image to text using Optical Character Recognition
|
|
36
|
+
* @param {string} path Path to image
|
|
37
|
+
* @returns {{abort: Function, response: Promise<string | null>}} Abort function & Promise of extracted text
|
|
38
|
+
*/
|
|
39
|
+
ocr(path: string): {
|
|
40
|
+
abort: () => void;
|
|
41
|
+
response: Promise<string | null>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Compare the difference between two strings using tensor math
|
|
45
|
+
* @param target Text that will checked
|
|
46
|
+
* @param {string} searchTerms Multiple search terms to check against target
|
|
47
|
+
* @returns {{avg: number, max: number, similarities: number[]}} Similarity values 0-1: 0 = unique, 1 = identical
|
|
48
|
+
*/
|
|
49
|
+
semanticSimilarity(target: string, ...searchTerms: string[]): {
|
|
50
|
+
avg: number;
|
|
51
|
+
max: number;
|
|
52
|
+
similarities: number[];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Anthropic as anthropic } from '@anthropic-ai/sdk';
|
|
2
|
+
import { Ai } from './ai.ts';
|
|
3
|
+
import { LLMMessage, LLMRequest } from './llm.ts';
|
|
4
|
+
import { AbortablePromise, LLMProvider } from './provider.ts';
|
|
5
|
+
export declare class Anthropic extends LLMProvider {
|
|
6
|
+
readonly ai: Ai;
|
|
7
|
+
readonly apiToken: string;
|
|
8
|
+
model: string;
|
|
9
|
+
client: anthropic;
|
|
10
|
+
constructor(ai: Ai, apiToken: string, model: string);
|
|
11
|
+
private toStandard;
|
|
12
|
+
private fromStandard;
|
|
13
|
+
ask(message: string, options?: LLMRequest): AbortablePromise<LLMMessage[]>;
|
|
14
|
+
}
|
package/dist/index.d.ts
ADDED