Skip to content

Commit

Permalink
feat: [SC-25948] ✨ Add new endpoint to NameGraph: findCollectionsByCo…
Browse files Browse the repository at this point in the history
…llections (#482)
  • Loading branch information
FrancoAguzzi authored Dec 5, 2024
1 parent cbc0649 commit 3f80c06
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-hats-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@namehash/namegraph-sdk": minor
---

Add new endpoint to NameGraph: findCollectionsByCollection
79 changes: 54 additions & 25 deletions packages/namegraph-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export interface Collection {
avatar_image: string;
}

export interface FindCollectionsByStringResponse {
export interface FindCollectionsResponse {
metadata: {
total_number_of_matched_collections: number;
processing_time_ms: number;
Expand Down Expand Up @@ -163,9 +163,39 @@ export class NameGraph {
this.abortController = new AbortController();
}

public groupedByCategory(
label: string,
): Promise<NameGraphGroupedByCategoryResponse> {
const sorter = "weighted-sampling";
const min_suggestions = 100;
const max_suggestions = 100;
const min_primary_fraction = 0.1;
const mode = "full";
const enable_learning_to_rank = true;
const name_diversity_ratio = 0.5;
const max_per_type = 2;

const payload = {
label,
metadata: DEFAULT_METADATA,
sorter,
min_suggestions,
max_suggestions,
min_primary_fraction,
params: {
mode,
enable_learning_to_rank,
name_diversity_ratio,
max_per_type,
},
};

return this.rawRequest(`grouped-by-category`, "POST", payload);
}

public findCollectionsByString(
query: string,
): Promise<FindCollectionsByStringResponse> {
): Promise<FindCollectionsResponse> {
const offset = 0;
const mode = "instant";
const limit_names = 10;
Expand Down Expand Up @@ -194,34 +224,33 @@ export class NameGraph {
return this.rawRequest("find_collections_by_string", "POST", payload);
}

public groupedByCategory(
label: string,
): Promise<NameGraphGroupedByCategoryResponse> {
const sorter = "weighted-sampling";
const min_suggestions = 100;
const max_suggestions = 100;
const min_primary_fraction = 0.1;
const mode = "full";
const enable_learning_to_rank = true;
public findCollectionsByCollection(
collection_id: string,
): Promise<FindCollectionsResponse> {
const limit_names = 10;
const offset = 0;
const sort_order = "AI";
const max_related_collections = 3;
const max_per_type = 3;
const name_diversity_ratio = 0.5;
const max_per_type = 2;
const min_other_collections = 0;
const max_other_collections = 3;
const max_total_collections = 6;

const payload = {
label,
metadata: DEFAULT_METADATA,
sorter,
min_suggestions,
max_suggestions,
min_primary_fraction,
params: {
mode,
enable_learning_to_rank,
name_diversity_ratio,
max_per_type,
},
limit_names,
offset,
sort_order,
max_related_collections,
max_per_type,
name_diversity_ratio,
min_other_collections,
max_other_collections,
max_total_collections,
collection_id,
};

return this.rawRequest(`grouped-by-category`, "POST", payload);
return this.rawRequest("find_collections_by_collection", "POST", payload);
}

public fetchTopCollectionMembers(
Expand Down

0 comments on commit 3f80c06

Please sign in to comment.