@blocklet/aigne-hub 0.2.17 → 0.2.18

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.
@@ -62,6 +62,7 @@ async function callRemoteApi(input, config, options = {}) {
62
62
  url: (0, ufo_1.joinURL)(url, config.endpoint),
63
63
  headers,
64
64
  timeout: options === null || options === void 0 ? void 0 : options.timeout,
65
+ responseType: options === null || options === void 0 ? void 0 : options.responseType,
65
66
  };
66
67
  if (method === 'GET') {
67
68
  requestConfig.params = input;
@@ -72,16 +73,17 @@ async function callRemoteApi(input, config, options = {}) {
72
73
  return (0, api_1.catchAndRethrowUpstreamError)(axios_1.default.request(requestConfig));
73
74
  }
74
75
  async function chatCompletionsV2(input, options = {}) {
75
- const response = await callRemoteApi(input, {
76
+ const params = {
76
77
  endpoint: 'api/v2/chat/completions',
77
78
  isStreamEndpoint: true,
78
- }, options);
79
+ };
80
+ const response = await callRemoteApi(input, params, { ...options, responseType: 'stream' });
79
81
  if ((options === null || options === void 0 ? void 0 : options.responseType) === 'stream')
80
82
  return response;
81
83
  return new web_1.ReadableStream({
82
84
  async start(controller) {
83
85
  try {
84
- const stream = (0, event_stream_1.readableToWeb)(response.data)
86
+ const stream = (0, event_stream_1.readableToWeb)((await response).data)
85
87
  .pipeThrough(new web_1.TextDecoderStream())
86
88
  .pipeThrough(new event_stream_1.EventSourceParserStream());
87
89
  for await (const chunk of stream) {
@@ -110,26 +112,19 @@ async function chatCompletionsV2(input, options = {}) {
110
112
  });
111
113
  }
112
114
  async function imageGenerationsV2(input, options = {}) {
113
- const response = await callRemoteApi(input, {
114
- endpoint: 'api/v2/image/generations',
115
- }, options);
115
+ const response = await callRemoteApi(input, { endpoint: 'api/v2/image/generations' }, options);
116
116
  if ((options === null || options === void 0 ? void 0 : options.responseType) === 'stream')
117
117
  return response;
118
118
  return response.data;
119
119
  }
120
120
  async function embeddingsV2(input, options = {}) {
121
- const response = await callRemoteApi(input, {
122
- endpoint: 'api/v2/embeddings',
123
- }, options);
121
+ const response = await callRemoteApi(input, { endpoint: 'api/v2/embeddings' }, options);
124
122
  if ((options === null || options === void 0 ? void 0 : options.responseType) === 'stream') {
125
123
  return response;
126
124
  }
127
125
  return response.data;
128
126
  }
129
127
  async function getUserCreditInfo() {
130
- const response = await callRemoteApi({}, {
131
- endpoint: 'api/user/info',
132
- method: 'GET',
133
- });
128
+ const response = await callRemoteApi({}, { endpoint: 'api/user/info', method: 'GET' });
134
129
  return response.data;
135
130
  }
@@ -52,6 +52,7 @@ export async function callRemoteApi(input, config, options = {}) {
52
52
  url: joinURL(url, config.endpoint),
53
53
  headers,
54
54
  timeout: options === null || options === void 0 ? void 0 : options.timeout,
55
+ responseType: options === null || options === void 0 ? void 0 : options.responseType,
55
56
  };
56
57
  if (method === 'GET') {
57
58
  requestConfig.params = input;
@@ -62,16 +63,17 @@ export async function callRemoteApi(input, config, options = {}) {
62
63
  return catchAndRethrowUpstreamError(axios.request(requestConfig));
63
64
  }
64
65
  export async function chatCompletionsV2(input, options = {}) {
65
- const response = await callRemoteApi(input, {
66
+ const params = {
66
67
  endpoint: 'api/v2/chat/completions',
67
68
  isStreamEndpoint: true,
68
- }, options);
69
+ };
70
+ const response = await callRemoteApi(input, params, { ...options, responseType: 'stream' });
69
71
  if ((options === null || options === void 0 ? void 0 : options.responseType) === 'stream')
70
72
  return response;
71
73
  return new ReadableStream({
72
74
  async start(controller) {
73
75
  try {
74
- const stream = readableToWeb(response.data)
76
+ const stream = readableToWeb((await response).data)
75
77
  .pipeThrough(new TextDecoderStream())
76
78
  .pipeThrough(new EventSourceParserStream());
77
79
  for await (const chunk of stream) {
@@ -100,26 +102,19 @@ export async function chatCompletionsV2(input, options = {}) {
100
102
  });
101
103
  }
102
104
  export async function imageGenerationsV2(input, options = {}) {
103
- const response = await callRemoteApi(input, {
104
- endpoint: 'api/v2/image/generations',
105
- }, options);
105
+ const response = await callRemoteApi(input, { endpoint: 'api/v2/image/generations' }, options);
106
106
  if ((options === null || options === void 0 ? void 0 : options.responseType) === 'stream')
107
107
  return response;
108
108
  return response.data;
109
109
  }
110
110
  export async function embeddingsV2(input, options = {}) {
111
- const response = await callRemoteApi(input, {
112
- endpoint: 'api/v2/embeddings',
113
- }, options);
111
+ const response = await callRemoteApi(input, { endpoint: 'api/v2/embeddings' }, options);
114
112
  if ((options === null || options === void 0 ? void 0 : options.responseType) === 'stream') {
115
113
  return response;
116
114
  }
117
115
  return response.data;
118
116
  }
119
117
  export async function getUserCreditInfo() {
120
- const response = await callRemoteApi({}, {
121
- endpoint: 'api/user/info',
122
- method: 'GET',
123
- });
118
+ const response = await callRemoteApi({}, { endpoint: 'api/user/info', method: 'GET' });
124
119
  return response.data;
125
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/aigne-hub",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "The react.js component library for AIGNE Hub",
5
5
  "publishConfig": {
6
6
  "access": "public"