symmetry-cli 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/provider.ts +62 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "symmetry-cli",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "dist/symmetry.js",
6
6
  "bin": "dist/symmetry.js",
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
- await this.joinServer();
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",