Skip to content

Commit

Permalink
chore(internal): update APIResource structure (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Nov 14, 2023
1 parent a46da67 commit c85a2e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 42 deletions.
21 changes: 0 additions & 21 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,27 +564,6 @@ export abstract class APIClient {
}
}

export class APIResource {
protected client: APIClient;
constructor(client: APIClient) {
this.client = client;

this.get = client.get.bind(client);
this.post = client.post.bind(client);
this.patch = client.patch.bind(client);
this.put = client.put.bind(client);
this.delete = client.delete.bind(client);
this.getAPIList = client.getAPIList.bind(client);
}

protected get: APIClient['get'];
protected post: APIClient['post'];
protected patch: APIClient['patch'];
protected put: APIClient['put'];
protected delete: APIClient['delete'];
protected getAPIList: APIClient['getAPIList'];
}

export type PageInfo = { url: URL } | { params: Record<string, unknown> | null };

export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
Expand Down
19 changes: 3 additions & 16 deletions src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,9 @@
import type { AnthropicBedrock } from './index';

export class APIResource {
protected client: AnthropicBedrock;
constructor(client: AnthropicBedrock) {
this.client = client;
protected _client: AnthropicBedrock;

this.get = client.get.bind(client);
this.post = client.post.bind(client);
this.patch = client.patch.bind(client);
this.put = client.put.bind(client);
this.delete = client.delete.bind(client);
this.getAPIList = client.getAPIList.bind(client);
constructor(client: AnthropicBedrock) {
this._client = client;
}

protected get: AnthropicBedrock['get'];
protected post: AnthropicBedrock['post'];
protected patch: AnthropicBedrock['patch'];
protected put: AnthropicBedrock['put'];
protected delete: AnthropicBedrock['delete'];
protected getAPIList: AnthropicBedrock['getAPIList'];
}
9 changes: 4 additions & 5 deletions src/resources/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ export class Completions extends APIResource {
options?: Core.RequestOptions,
): APIPromise<Completion> | APIPromise<Stream<Completion>> {
const { model, stream, ...body } = params;
return this.post(stream ? `/model/${model}/invoke-with-response-stream` : `/model/${model}/invoke`, {
body: { anthropic_version: 'bedrock-2023-05-31', ...body },
...options,
stream: stream ?? false,
}) as APIPromise<Completion> | APIPromise<Stream<Completion>>;
return this._client.post(
stream ? `/model/${model}/invoke-with-response-stream` : `/model/${model}/invoke`,
{ body: { anthropic_version: 'bedrock-2023-05-31', ...body }, ...options, stream: stream ?? false },
) as APIPromise<Completion> | APIPromise<Stream<Completion>>;
}
}

Expand Down

0 comments on commit c85a2e3

Please # to comment.