jsvelox 1.0.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/README.md +28 -0
- package/package.json +16 -0
- package/src/index.js +63 -0
- package/test.html +27 -0
- package/test.js +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Velox
|
|
2
|
+
|
|
3
|
+
Lightweight JavaScript library for AI integration.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
```bash
|
|
7
|
+
npm install velox
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
```js
|
|
12
|
+
import { VeloxAI } from 'velox'
|
|
13
|
+
|
|
14
|
+
const ai = new VeloxAI({
|
|
15
|
+
provider: 'claude', // or 'openai'
|
|
16
|
+
apiKey: 'your-api-key'
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const reply = await ai.send('Hello!')
|
|
20
|
+
console.log(reply)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Providers
|
|
24
|
+
- `claude` — Anthropic Claude
|
|
25
|
+
- `openai` — OpenAI GPT
|
|
26
|
+
|
|
27
|
+
## Note
|
|
28
|
+
Use in Node.js backend only. Not for browser use.
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jsvelox",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Lightweight JS library for AI integration and developer utilities",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"ai",
|
|
9
|
+
"claude",
|
|
10
|
+
"openai",
|
|
11
|
+
"utility",
|
|
12
|
+
"velox"
|
|
13
|
+
],
|
|
14
|
+
"author": "senin-adin",
|
|
15
|
+
"license": "MIT"
|
|
16
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export class VeloxAI {
|
|
2
|
+
constructor(config) {
|
|
3
|
+
if (!config.apiKey) {
|
|
4
|
+
throw new Error('API key zorunlu!')
|
|
5
|
+
}
|
|
6
|
+
if (!config.provider) {
|
|
7
|
+
throw new Error('Provider zorunlu! claude veya openai kullan.')
|
|
8
|
+
}
|
|
9
|
+
this.provider = config.provider
|
|
10
|
+
this.apiKey = config.apiKey
|
|
11
|
+
this.model = config.model || null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async send(message) {
|
|
15
|
+
if (this.provider === 'claude') {
|
|
16
|
+
return await this._sendClaude(message)
|
|
17
|
+
} else if (this.provider === 'openai') {
|
|
18
|
+
return await this._sendOpenAI(message)
|
|
19
|
+
} else {
|
|
20
|
+
throw new Error('Geçersiz provider. claude veya openai kullan.')
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async _sendClaude(message) {
|
|
25
|
+
const response = await fetch('https://api.anthropic.com/v1/messages', {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
headers: {
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
'x-api-key': this.apiKey,
|
|
30
|
+
'anthropic-version': '2023-06-01'
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
model: this.model || 'claude-3-5-sonnet-20241022',
|
|
34
|
+
max_tokens: 1024,
|
|
35
|
+
messages: [{ role: 'user', content: message }]
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
const data = await response.json()
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new Error(`Claude hata: ${data.error?.message || 'Bilinmeyen hata'}`)
|
|
41
|
+
}
|
|
42
|
+
return data.content[0].text
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async _sendOpenAI(message) {
|
|
46
|
+
const response = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
'Content-Type': 'application/json',
|
|
50
|
+
'Authorization': `Bearer ${this.apiKey}`
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify({
|
|
53
|
+
model: this.model || 'gpt-4o-mini',
|
|
54
|
+
messages: [{ role: 'user', content: message }]
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
const data = await response.json()
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
throw new Error(`OpenAI hata: ${data.error?.message || 'Bilinmeyen hata'}`)
|
|
60
|
+
}
|
|
61
|
+
return data.choices[0].message.content
|
|
62
|
+
}
|
|
63
|
+
}
|
package/test.html
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="tr">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Velox Test</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<input type="text" id="userInput" placeholder="Mesajını yaz...">
|
|
9
|
+
<button onclick="gonder()">Gönder</button>
|
|
10
|
+
<p id="cevap"></p>
|
|
11
|
+
|
|
12
|
+
<script type="module">
|
|
13
|
+
import { VeloxAI } from './src/index.js'
|
|
14
|
+
|
|
15
|
+
const ai = new VeloxAI({
|
|
16
|
+
provider: 'claude',
|
|
17
|
+
apiKey: 'BURAYA-API-KEY-GELECEK'
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
window.gonder = async function() {
|
|
21
|
+
const mesaj = document.getElementById('userInput').value
|
|
22
|
+
const cevap = await ai.send(mesaj)
|
|
23
|
+
document.getElementById('cevap').innerText = cevap
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|