Skip to content

Commit

Permalink
feat(sse): switch to external dependency (#54)
Browse files Browse the repository at this point in the history
Ref: #113

Signed-off-by: Tomas Dvorak <[email protected]>
Co-authored-by: Tomas Dvorak <[email protected]>
  • Loading branch information
Tomas2D and Tomas2D-IBM authored Oct 11, 2023
1 parent ca540b7 commit d565e81
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 414 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"@commitlint/config-conventional": "^17.4.4",
"@types/lodash": "^4.14.194",
"@types/node": "^18.15.5",
"@types/node-fetch": "^2.6.4",
"@types/promise-retry": "^1.1.3",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
Expand All @@ -95,9 +94,9 @@
"vitest": "^0.31.1"
},
"dependencies": {
"@ai-zen/node-fetch-event-source": "^2.1.2",
"axios": "^1.3.4",
"axios-cache-interceptor": "^1.0.1",
"cross-fetch": "^3.1.6",
"form-data": "^4.0.0",
"promise-retry": "^2.0.1",
"yaml": "^2.3.0",
Expand Down
10 changes: 6 additions & 4 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import {
setupCache,
} from 'axios-cache-interceptor';
import promiseRetry from 'promise-retry';
import {
EventStreamContentType,
fetchEventSource,
} from '@ai-zen/node-fetch-event-source';
import { ZodSchema } from 'zod';
import { Request } from 'cross-fetch';

import * as ApiTypes from '../api-types.js';
import {
Expand All @@ -37,9 +40,7 @@ import {
import { TypedReadable } from '../utils/stream.js';
import { lookupApiKey, lookupEndpoint } from '../helpers/config.js';
import { RETRY_ATTEMPTS_DEFAULT } from '../constants.js';
import { EventStreamContentType, fetchEventSource } from '../utils/sse/sse.js';

import { CacheDiscriminator, generateCacheKey } from './cache.js';
import {
GenerateConfigInput,
GenerateConfigOptions,
Expand Down Expand Up @@ -92,6 +93,7 @@ import {
FileDeleteOutput,
PromptTemplateDeleteOutput,
} from './types.js';
import { CacheDiscriminator, generateCacheKey } from './cache.js';

type FetchConfig<R, D> = Omit<CacheRequestConfig<R, D>, 'signal'> & {
retries?: number;
Expand Down Expand Up @@ -216,7 +218,7 @@ export class Client {
input.url ?? this.#options.endpoint,
this.#options.endpoint,
);
fetchEventSource(new Request(url), {
fetchEventSource(url.toString(), {
method: 'POST',
body: JSON.stringify(input.data),
headers: {
Expand Down
21 changes: 0 additions & 21 deletions src/utils/sse/LICENSE

This file was deleted.

200 changes: 0 additions & 200 deletions src/utils/sse/parse.ts

This file was deleted.

Loading

0 comments on commit d565e81

Please sign in to comment.