symmetry-cli 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/node.js.yml +31 -0
- package/dist/provider.js +59 -8
- package/install.ps1 +1 -0
- package/install.sh +3 -4
- package/package.json +1 -1
- package/readme.md +1 -0
- package/src/provider.ts +62 -2
@@ -0,0 +1,31 @@
|
|
1
|
+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
3
|
+
|
4
|
+
name: Node.js CI
|
5
|
+
|
6
|
+
on:
|
7
|
+
push:
|
8
|
+
branches: [ "master" ]
|
9
|
+
pull_request:
|
10
|
+
branches: [ "master" ]
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
build:
|
14
|
+
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
|
17
|
+
strategy:
|
18
|
+
matrix:
|
19
|
+
node-version: [18.x, 20.x, 22.x]
|
20
|
+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
21
|
+
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v4
|
24
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
25
|
+
uses: actions/setup-node@v4
|
26
|
+
with:
|
27
|
+
node-version: ${{ matrix.node-version }}
|
28
|
+
cache: 'npm'
|
29
|
+
- run: npm ci
|
30
|
+
- run: npm run build --if-present
|
31
|
+
- run: npm test
|
package/dist/provider.js
CHANGED
@@ -50,7 +50,7 @@ class SymmetryProvider {
|
|
50
50
|
if (this._isPublic) {
|
51
51
|
logger_1.logger.info(chalk_1.default.white(`🔑 Server key: ${this._config.get("serverKey")}`));
|
52
52
|
logger_1.logger.info(chalk_1.default.white("🔗 Joining server, please wait."));
|
53
|
-
|
53
|
+
this.testProviderCall();
|
54
54
|
}
|
55
55
|
process.on("SIGINT", async () => {
|
56
56
|
var _a;
|
@@ -63,6 +63,50 @@ class SymmetryProvider {
|
|
63
63
|
}
|
64
64
|
});
|
65
65
|
}
|
66
|
+
async testProviderCall() {
|
67
|
+
logger_1.logger.info(chalk_1.default.white(`👋 Saying hello to your provider...`));
|
68
|
+
const testMessages = [
|
69
|
+
{ role: "user", content: "Hello, this is a test message." },
|
70
|
+
];
|
71
|
+
const req = this.buildStreamRequest(testMessages);
|
72
|
+
if (!req) {
|
73
|
+
logger_1.logger.error(chalk_1.default.red("❌ Failed to build test request"));
|
74
|
+
throw new Error("Failed to build test request");
|
75
|
+
}
|
76
|
+
const { requestOptions, requestBody } = req;
|
77
|
+
const { protocol, hostname, port, path, method, headers } = requestOptions;
|
78
|
+
const url = `${protocol}://${hostname}:${port}${path}`;
|
79
|
+
logger_1.logger.info(chalk_1.default.white(`🚀 Sending test request to ${url}`));
|
80
|
+
try {
|
81
|
+
const response = await fetch(url, {
|
82
|
+
method,
|
83
|
+
headers,
|
84
|
+
body: JSON.stringify(requestBody),
|
85
|
+
});
|
86
|
+
if (!response.ok) {
|
87
|
+
logger_1.logger.error(chalk_1.default.red(`❌ Server responded with status code: ${response.status}`));
|
88
|
+
throw new Error(`Server responded with status code: ${response.status}`);
|
89
|
+
}
|
90
|
+
if (!response.body) {
|
91
|
+
logger_1.logger.error(chalk_1.default.red("❌ Failed to get a ReadableStream from the response"));
|
92
|
+
throw new Error("Failed to get a ReadableStream from the response");
|
93
|
+
}
|
94
|
+
logger_1.logger.info(chalk_1.default.white(`📡 Got response, checking stream...`));
|
95
|
+
const reader = response.body.getReader();
|
96
|
+
const { done } = await reader.read();
|
97
|
+
if (done) {
|
98
|
+
logger_1.logger.error(chalk_1.default.red("❌ Stream ended without data"));
|
99
|
+
throw new Error("Stream ended without data");
|
100
|
+
}
|
101
|
+
logger_1.logger.info(chalk_1.default.green(`✅ Test inference call successful!`));
|
102
|
+
}
|
103
|
+
catch (error) {
|
104
|
+
logger_1.logger.error(chalk_1.default.red(`❌ Error during test inference call: ${error}`));
|
105
|
+
throw error;
|
106
|
+
}
|
107
|
+
logger_1.logger.info(chalk_1.default.white(`🔗 Proceeding to join server...`));
|
108
|
+
await this.joinServer();
|
109
|
+
}
|
66
110
|
async joinServer() {
|
67
111
|
const serverSwarm = new hyperswarm_1.default();
|
68
112
|
const serverKey = Buffer.from(this._config.get("serverKey"));
|
@@ -147,16 +191,20 @@ class SymmetryProvider {
|
|
147
191
|
}
|
148
192
|
});
|
149
193
|
}
|
150
|
-
|
151
|
-
const
|
152
|
-
|
153
|
-
const req = this.buildStreamRequest(data === null || data === void 0 ? void 0 : data.data.messages);
|
154
|
-
if (messages.length === 2) {
|
194
|
+
getMessagesWithSystem(messages) {
|
195
|
+
const systemMessage = this._config.get("systemMessage");
|
196
|
+
if (messages.length === 2 && systemMessage) {
|
155
197
|
messages.unshift({
|
156
198
|
role: "system",
|
157
|
-
content:
|
199
|
+
content: systemMessage,
|
158
200
|
});
|
159
201
|
}
|
202
|
+
return messages;
|
203
|
+
}
|
204
|
+
async handleInferenceRequest(data, peer) {
|
205
|
+
const emitterKey = data.data.key;
|
206
|
+
const messages = this.getMessagesWithSystem(data === null || data === void 0 ? void 0 : data.data.messages);
|
207
|
+
const req = this.buildStreamRequest(messages);
|
160
208
|
if (!req)
|
161
209
|
return;
|
162
210
|
const { requestOptions, requestBody } = req;
|
@@ -199,7 +247,10 @@ class SymmetryProvider {
|
|
199
247
|
});
|
200
248
|
await Promise.resolve(peerPipeline);
|
201
249
|
peer.write((0, utils_1.createMessage)(constants_1.serverMessageKeys.inferenceEnded, data === null || data === void 0 ? void 0 : data.data.key));
|
202
|
-
this.
|
250
|
+
if (this._config.get("dataCollectionEnabled") &&
|
251
|
+
data.data.key === constants_1.serverMessageKeys.inference) {
|
252
|
+
this.saveCompletion(completion, peer, data.data.messages);
|
253
|
+
}
|
203
254
|
}
|
204
255
|
catch (error) {
|
205
256
|
let errorMessage = "An error occurred during inference";
|
package/install.ps1
CHANGED
@@ -44,6 +44,7 @@ modelName: llama3.1:latest
|
|
44
44
|
name: $env:USERNAME
|
45
45
|
path: $config_dir
|
46
46
|
public: true
|
47
|
+
systemMessage:
|
47
48
|
serverKey: 4b4a9cc325d134dee6679e9407420023531fd7e96c563f6c5d00fd5549b77435
|
48
49
|
"@ | Set-Content $provider_yaml
|
49
50
|
Print-Color $GREEN "provider.yaml created successfully at $provider_yaml"
|
package/install.sh
CHANGED
@@ -46,7 +46,9 @@ modelName: llama3.1:latest
|
|
46
46
|
name: $(whoami)
|
47
47
|
path: $config_dir
|
48
48
|
public: true
|
49
|
+
systemMessage:
|
49
50
|
serverKey: 4b4a9cc325d134dee6679e9407420023531fd7e96c563f6c5d00fd5549b77435
|
51
|
+
|
50
52
|
EOF
|
51
53
|
print_color "$GREEN" "provider.yaml created successfully at $provider_yaml"
|
52
54
|
else
|
@@ -54,7 +56,4 @@ else
|
|
54
56
|
fi
|
55
57
|
|
56
58
|
print_color "$GREEN" "Installation complete! You can now run 'symmetry-cli' to start your node."
|
57
|
-
print_color "$YELLOW" "Please edit $provider_yaml to customize your provider settings
|
58
|
-
print_color "$YELLOW" " - apiKey: Add your API key if required"
|
59
|
-
print_color "$YELLOW" " - name: Currently set to your system username, change if needed"
|
60
|
-
print_color "$YELLOW" " - public: Set to true by default, change to false if you don't want to be publicly accessible"
|
59
|
+
print_color "$YELLOW" "Please edit $provider_yaml to customize your provider settings:"
|
package/package.json
CHANGED
package/readme.md
CHANGED
@@ -58,6 +58,7 @@ name: twinnydotdev # Your chosen name as a provider on the Symmetry network.
|
|
58
58
|
path: /home/twinnydotdev/.config/symmetry/data # The local path where Symmetry will store its configuration and data files.
|
59
59
|
public: true # Whether this provider is publicly accessible on the Symmetry network.
|
60
60
|
serverKey: 4b4a9cc325d134dee6679e9407420023531fd7e96c563f6c5d00fd5549b77435 # The unique key for connecting to the Symmetry server.
|
61
|
+
systemMessage: "I'm a system message" # An optional system message for each conversation.
|
61
62
|
```
|
62
63
|
|
63
64
|
Adjust these settings according to your preferences and setup.
|
package/src/provider.ts
CHANGED
@@ -63,7 +63,7 @@ export class SymmetryProvider {
|
|
63
63
|
chalk.white(`🔑 Server key: ${this._config.get("serverKey")}`)
|
64
64
|
);
|
65
65
|
logger.info(chalk.white("🔗 Joining server, please wait."));
|
66
|
-
|
66
|
+
this.testProviderCall();
|
67
67
|
}
|
68
68
|
|
69
69
|
process.on("SIGINT", async () => {
|
@@ -78,6 +78,66 @@ export class SymmetryProvider {
|
|
78
78
|
});
|
79
79
|
}
|
80
80
|
|
81
|
+
private async testProviderCall(): Promise<void> {
|
82
|
+
logger.info(chalk.white(`👋 Saying hello to your provider...`));
|
83
|
+
const testMessages: Message[] = [
|
84
|
+
{ role: "user", content: "Hello, this is a test message." },
|
85
|
+
];
|
86
|
+
const req = this.buildStreamRequest(testMessages);
|
87
|
+
|
88
|
+
if (!req) {
|
89
|
+
logger.error(chalk.red("❌ Failed to build test request"));
|
90
|
+
throw new Error("Failed to build test request");
|
91
|
+
}
|
92
|
+
|
93
|
+
const { requestOptions, requestBody } = req;
|
94
|
+
const { protocol, hostname, port, path, method, headers } = requestOptions;
|
95
|
+
const url = `${protocol}://${hostname}:${port}${path}`;
|
96
|
+
|
97
|
+
logger.info(chalk.white(`🚀 Sending test request to ${url}`));
|
98
|
+
|
99
|
+
try {
|
100
|
+
const response = await fetch(url, {
|
101
|
+
method,
|
102
|
+
headers,
|
103
|
+
body: JSON.stringify(requestBody),
|
104
|
+
});
|
105
|
+
|
106
|
+
if (!response.ok) {
|
107
|
+
logger.error(
|
108
|
+
chalk.red(`❌ Server responded with status code: ${response.status}`)
|
109
|
+
);
|
110
|
+
throw new Error(
|
111
|
+
`Server responded with status code: ${response.status}`
|
112
|
+
);
|
113
|
+
}
|
114
|
+
|
115
|
+
if (!response.body) {
|
116
|
+
logger.error(
|
117
|
+
chalk.red("❌ Failed to get a ReadableStream from the response")
|
118
|
+
);
|
119
|
+
throw new Error("Failed to get a ReadableStream from the response");
|
120
|
+
}
|
121
|
+
|
122
|
+
logger.info(chalk.white(`📡 Got response, checking stream...`));
|
123
|
+
|
124
|
+
const reader = response.body.getReader();
|
125
|
+
const { done } = await reader.read();
|
126
|
+
if (done) {
|
127
|
+
logger.error(chalk.red("❌ Stream ended without data"));
|
128
|
+
throw new Error("Stream ended without data");
|
129
|
+
}
|
130
|
+
|
131
|
+
logger.info(chalk.green(`✅ Test inference call successful!`));
|
132
|
+
} catch (error) {
|
133
|
+
logger.error(chalk.red(`❌ Error during test inference call: ${error}`));
|
134
|
+
throw error;
|
135
|
+
}
|
136
|
+
|
137
|
+
logger.info(chalk.white(`🔗 Proceeding to join server...`));
|
138
|
+
await this.joinServer();
|
139
|
+
}
|
140
|
+
|
81
141
|
async joinServer(): Promise<void> {
|
82
142
|
const serverSwarm = new Hyperswarm();
|
83
143
|
const serverKey = Buffer.from(this._config.get("serverKey"));
|
@@ -191,7 +251,7 @@ export class SymmetryProvider {
|
|
191
251
|
}
|
192
252
|
|
193
253
|
private getMessagesWithSystem(messages: Message[]): Message[] {
|
194
|
-
const systemMessage = this._config.get("systemMessage")
|
254
|
+
const systemMessage = this._config.get("systemMessage");
|
195
255
|
if (messages.length === 2 && systemMessage) {
|
196
256
|
messages.unshift({
|
197
257
|
role: "system",
|