Skip to content

Commit

Permalink
chore: exports
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanVor committed Dec 29, 2024
1 parent aa465ac commit 4d937e7
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 26 deletions.
1 change: 1 addition & 0 deletions clients/ai-assistants-v1/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './threadSdk';
export * from './searchIndexFileSdk';
export * from './searchIndexSdk';
export * from './userSdk';
export * from '..';
1 change: 1 addition & 0 deletions clients/ai-files-v1/sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './fileSdk';
export * from '..';
10 changes: 8 additions & 2 deletions clients/ai-foundation_models-v1/sdk/embeddingSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export type TextEmbeddingProps = Omit<TypeFromProtoc<TextEmbeddingRequest, 'text
export class EmbeddingSdk {
private embeddingClient: Client<typeof EmbeddingsServiceService, ClientCallArgs>;

constructor(session: SessionArg) {
this.embeddingClient = session.client(embeddingService.EmbeddingsServiceClient);
static ENDPOINT = 'llm.api.cloud.yandex.net:443';

constructor(session: SessionArg, endpoint = EmbeddingSdk.ENDPOINT) {
this.embeddingClient = session.client(embeddingService.EmbeddingsServiceClient, endpoint);
}

textEmbedding(params: TextEmbeddingProps, args?: ClientCallArgs) {
Expand All @@ -28,3 +30,7 @@ export class EmbeddingSdk {
);
}
}

export const initEmbeddingSdk = (session: SessionArg, endpoint = EmbeddingSdk.ENDPOINT) => {
return new EmbeddingSdk(session, endpoint);
};
11 changes: 10 additions & 1 deletion clients/ai-foundation_models-v1/sdk/imageGenerationSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export class ImageGenerationSdk {
ClientCallArgs
>;

constructor(session: SessionArg, endpoint = 'llm.api.cloud.yandex.net:443') {
static ENDPOINT = 'llm.api.cloud.yandex.net:443';

constructor(session: SessionArg, endpoint = ImageGenerationSdk.ENDPOINT) {
this.imageGenerationClient = session.client(
imageGenerationService.ImageGenerationAsyncServiceClient,
endpoint,
Expand All @@ -37,3 +39,10 @@ export class ImageGenerationSdk {
);
}
}

export const initImageGenerationSdk = (
session: SessionArg,
endpoint = ImageGenerationSdk.ENDPOINT,
) => {
return new ImageGenerationSdk(session, endpoint);
};
1 change: 1 addition & 0 deletions clients/ai-foundation_models-v1/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './embeddingSdk';
export * from './imageGenerationSdk';
export * from './textClassificationSdk';
export * from './textGenerationSdk';
export * from '..';
12 changes: 11 additions & 1 deletion clients/ai-foundation_models-v1/sdk/textClassificationSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ export class TextClassificationSdk {
ClientCallArgs
>;

constructor(session: SessionArg) {
static ENDPOINT = 'llm.api.cloud.yandex.net:443';

constructor(session: SessionArg, endpoint = TextClassificationSdk.ENDPOINT) {
this.textClassificationClient = session.client(
textClassificationService.TextClassificationServiceClient,
endpoint,
);
}

Expand Down Expand Up @@ -61,3 +64,10 @@ export class TextClassificationSdk {
);
}
}

export const initTextClassificationSdk = (
session: SessionArg,
endpoint = TextClassificationSdk.ENDPOINT,
) => {
return new TextClassificationSdk(session, endpoint);
};
18 changes: 16 additions & 2 deletions clients/ai-foundation_models-v1/sdk/textGenerationSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ export class TextGenerationSdk {
ClientCallArgs
>;

constructor(session: SessionArg) {
static ENDPOINT = 'llm.api.cloud.yandex.net:443';

constructor(session: SessionArg, endpoint = TextGenerationSdk.ENDPOINT) {
this.textGenerationClient = session.client(
textGenerationService.TextGenerationServiceClient,
endpoint,
);

this.tokenizerClient = session.client(textGenerationService.TokenizerServiceClient);
this.tokenizerClient = session.client(
textGenerationService.TokenizerServiceClient,
endpoint,
);

this.textGenerationAsyncClient = session.client(
textGenerationService.TextGenerationAsyncServiceClient,
endpoint,
);
}

Expand Down Expand Up @@ -82,3 +89,10 @@ export class TextGenerationSdk {
return operationP;
}
}

export const initTextGenerationSdk = (
session: SessionArg,
endpoint = TextGenerationSdk.ENDPOINT,
) => {
return new TextGenerationSdk(session, endpoint);
};
1 change: 1 addition & 0 deletions clients/operation/sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './operationSdk';
export * from '..';
40 changes: 20 additions & 20 deletions examples/generate-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { Session } from '@yandex-cloud/nodejs-sdk/dist/session';

import { initOperationSdk } from '@yandex-cloud/nodejs-sdk/operation/sdk';

import { ImageGenerationSdk } from '@yandex-cloud/nodejs-sdk/ai-foundation_models-v1/sdk';
import { imageGeneration } from '@yandex-cloud/nodejs-sdk/ai-foundation_models-v1';
import {
initImageGenerationSdk,
imageGeneration,
} from '@yandex-cloud/nodejs-sdk/ai-foundation_models-v1/sdk';
import { ImageGenerationResponse } from '@yandex-cloud/nodejs-sdk/ai-foundation_models-v1/generated/yandex/cloud/ai/foundation_models/v1/image_generation/image_generation_service';
import { writeFile } from 'fs';

Expand All @@ -30,34 +32,32 @@ const folderId = getEnv('YC_FOLDER_ID');

const operationSdk = initOperationSdk(session);

const imageGenerationSdk = new ImageGenerationSdk(session);
const imageGenerationSdk = initImageGenerationSdk(session);

const generateImageOperation = await imageGenerationSdk.generateImage({
folderId,
modelId: 'yandex-art/free-tier',
modelId: 'yandex-art',
generationOptions: {
mimeType: 'image/jpeg',
seed: 1165508436334210,
},
messages: [imageGeneration.Message.fromPartial({ text: 'Кот', weight: 1 })],
messages: [
imageGeneration.Message.fromPartial({
text: 'Three cats',
weight: 1,
}),
],
});

const generateImageFinalOperation = await operationSdk.pollOperation(
const imageGenerationResponse = await operationSdk.pollOperation(
generateImageOperation,
1_000,
{ operationCallback: () => console.log('In Process') },
{
operationCallback: console.log,
decoder: ImageGenerationResponse.decode,
},
);

if (generateImageFinalOperation.response) {
console.log(ImageGenerationResponse.decode(generateImageFinalOperation.response.value));

writeFile(
'./image.png',
ImageGenerationResponse.decode(generateImageFinalOperation.response.value).image,
{ encoding: 'base64' },
function (err) {
console.log('File created');
},
);
}
writeFile('./image.png', imageGenerationResponse.image, { encoding: 'base64' }, function (err) {
console.log('File created');
});
})();

0 comments on commit 4d937e7

Please sign in to comment.