@axvaich/ai-lib 1.0.3 → 1.0.5
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/README.md +43 -0
- package/dist/index.js +10 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
# @axvaich/ai-lib
|
|
2
2
|
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @axvaich/ai-lib
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Create a `.env` file by copying `.env.example`:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
cp .env.example .env
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then set your GROQ API key from [console.groq.com/keys](https://console.groq.com/keys):
|
|
16
|
+
|
|
17
|
+
```env
|
|
18
|
+
GROQ_API_KEY=your_api_key_here
|
|
19
|
+
```
|
|
20
|
+
|
|
3
21
|
## Using
|
|
4
22
|
|
|
23
|
+
### example 1
|
|
24
|
+
|
|
5
25
|
code you see:
|
|
6
26
|
|
|
7
27
|
```js
|
|
@@ -24,3 +44,26 @@ export default function multiplyNumbers(numbers) {
|
|
|
24
44
|
return numbers.reduce((acc, current) => acc * current, 1);
|
|
25
45
|
}
|
|
26
46
|
```
|
|
47
|
+
|
|
48
|
+
### example 2
|
|
49
|
+
|
|
50
|
+
code you see:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
const command2 = await generate("return all numbers from arguments");
|
|
54
|
+
console.log(command2(1, 2, 3, 54));
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
generated code:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
/**
|
|
61
|
+
* Returns all numbers from the given arguments.
|
|
62
|
+
*
|
|
63
|
+
* @param args A variable number of arguments of any type.
|
|
64
|
+
* @returns An array of numbers.
|
|
65
|
+
*/
|
|
66
|
+
export default function getNumbers(...args) {
|
|
67
|
+
return args.filter((arg) => typeof arg === "number");
|
|
68
|
+
}
|
|
69
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -42,16 +42,16 @@ var store = new Storage();
|
|
|
42
42
|
|
|
43
43
|
// src/generator.ts
|
|
44
44
|
import ts from "typescript";
|
|
45
|
-
var SYSTEM_PROMPT =
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
- JSDoc
|
|
50
|
-
- Pure
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
45
|
+
var SYSTEM_PROMPT = `You are a TypeScript function generator. Strict rules:
|
|
46
|
+
- Exactly one function with export default
|
|
47
|
+
- Strict typing for all parameters and the return type
|
|
48
|
+
- Must always return a value
|
|
49
|
+
- Include a JSDoc comment with a description
|
|
50
|
+
- Pure function, no side effects
|
|
51
|
+
- Only code, with a brief explanation
|
|
52
|
+
- No imports (only built-in TypeScript types)
|
|
53
|
+
- If the user request does not explicitly specify arguments, the function must not accept any parameters and should simply return the result
|
|
54
|
+
- Follow the user's instructions strictly`;
|
|
55
55
|
var groq = new Groq({
|
|
56
56
|
apiKey: process.env.GROQ_API_KEY
|
|
57
57
|
});
|
|
@@ -81,10 +81,6 @@ async function generate(prompt) {
|
|
|
81
81
|
const filePath = await store.createFunction(fileName, compileTs(code));
|
|
82
82
|
return await loadFunction(filePath);
|
|
83
83
|
}
|
|
84
|
-
(async () => {
|
|
85
|
-
const command = await generate("\u0432\u044B\u0432\u043E\u0434\u0438\u0442\u0441\u044F \u0441\u043B\u043E\u0432\u043E \u0438\u0437 \u0430\u0440\u0433\u0443\u043C\u0435\u043D\u0442\u0430 \u0441 \u043F\u0440\u043E\u0431\u0435\u043B\u0430\u043C\u0438 \u043C\u0435\u0436\u0434\u0443 \u043A\u0430\u0436\u0434\u043E\u0439 \u0431\u0443\u043A\u0432\u043E\u0439");
|
|
86
|
-
console.log(command("\u0441\u043B\u043E\u0432\u043E \u043A\u0430\u043A\u043E\u0435-\u0442\u043E"));
|
|
87
|
-
})();
|
|
88
84
|
export {
|
|
89
85
|
compileTs,
|
|
90
86
|
generate,
|