Skip to content

Commit

Permalink
Merge branch 'huggingface:main' into restructure-inference-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ArsalaBangash authored Oct 30, 2023
2 parents fa6f57b + 95c509b commit 07fa24b
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 15 deletions.
3 changes: 0 additions & 3 deletions packages/hub/src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export const HUB_URL = "https://huggingface.co";
export const TEST_HUB_URL = "https://hub-ci.huggingface.co";
export const TEST_USER = "hub.js";
export const TEST_ACCESS_TOKEN = "hf_hub.js";
2 changes: 1 addition & 1 deletion packages/hub/src/lib/commit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, it, describe } from "vitest";

import { TEST_HUB_URL, TEST_ACCESS_TOKEN, TEST_USER } from "../consts";
import { TEST_HUB_URL, TEST_ACCESS_TOKEN, TEST_USER } from "../test/consts";
import type { RepoId } from "../types/public";
import type { CommitFile } from "./commit";
import { commit } from "./commit";
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/lib/create-repo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, it, describe, expect } from "vitest";

import { TEST_HUB_URL, TEST_ACCESS_TOKEN, TEST_USER } from "../consts";
import { TEST_HUB_URL, TEST_ACCESS_TOKEN, TEST_USER } from "../test/consts";
import { insecureRandomString } from "../utils/insecureRandomString";
import { createRepo } from "./create-repo";
import { deleteRepo } from "./delete-repo";
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/lib/delete-file.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, it, describe } from "vitest";

import { TEST_ACCESS_TOKEN, TEST_HUB_URL, TEST_USER } from "../consts";
import { TEST_ACCESS_TOKEN, TEST_HUB_URL, TEST_USER } from "../test/consts";
import type { RepoId } from "../types/public";
import { insecureRandomString } from "../utils/insecureRandomString";
import { createRepo } from "./create-repo";
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/lib/delete-files.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, it, describe } from "vitest";

import { TEST_HUB_URL, TEST_ACCESS_TOKEN, TEST_USER } from "../consts";
import { TEST_HUB_URL, TEST_ACCESS_TOKEN, TEST_USER } from "../test/consts";
import type { RepoId } from "../types/public";
import { insecureRandomString } from "../utils/insecureRandomString";
import { createRepo } from "./create-repo";
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/lib/upload-file.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, it, describe } from "vitest";

import { TEST_ACCESS_TOKEN, TEST_HUB_URL, TEST_USER } from "../consts";
import { TEST_ACCESS_TOKEN, TEST_HUB_URL, TEST_USER } from "../test/consts";
import type { RepoId } from "../types/public";
import { insecureRandomString } from "../utils/insecureRandomString";
import { createRepo } from "./create-repo";
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/lib/upload-files-with-progress.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, it, describe } from "vitest";

import { TEST_HUB_URL, TEST_ACCESS_TOKEN, TEST_USER } from "../consts";
import { TEST_HUB_URL, TEST_ACCESS_TOKEN, TEST_USER } from "../test/consts";
import type { RepoId } from "../types/public";
import { insecureRandomString } from "../utils/insecureRandomString";
import { createRepo } from "./create-repo";
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/lib/upload-files.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, it, describe } from "vitest";

import { TEST_ACCESS_TOKEN, TEST_HUB_URL, TEST_USER } from "../consts";
import { TEST_ACCESS_TOKEN, TEST_HUB_URL, TEST_USER } from "../test/consts";
import type { RepoId } from "../types/public";
import { insecureRandomString } from "../utils/insecureRandomString";
import { createRepo } from "./create-repo";
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/src/lib/who-am-i.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert, it, describe } from "vitest";
import { TEST_ACCESS_TOKEN, TEST_HUB_URL } from "../consts";
import { TEST_ACCESS_TOKEN, TEST_HUB_URL } from "../test/consts";
import { whoAmI } from "./who-am-i";

describe("whoAmI", () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/hub/src/test/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const TEST_HUB_URL = "https://hub-ci.huggingface.co";
export const TEST_USER = "hub.js";
export const TEST_ACCESS_TOKEN = "hf_hub.js";
10 changes: 6 additions & 4 deletions packages/inference/src/tasks/nlp/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@ export type TranslationArgs = BaseArgs & {
/**
* A string to be translated
*/
inputs: string;
inputs: string | string[];
};

export interface TranslationOutput {
export interface TranslationOutputValue {
/**
* The string after translation
*/
translation_text: string;
}

export type TranslationOutput = TranslationOutputValue | TranslationOutputValue[];

/**
* This task is well known to translate text from one language to another. Recommended model: Helsinki-NLP/opus-mt-ru-en.
*/
export async function translation(args: TranslationArgs, options?: Options): Promise<TranslationOutput> {
const res = await request<TranslationOutput[]>(args, {
const res = await request<TranslationOutputValue[]>(args, {
...options,
taskHint: "translation",
});
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x?.translation_text === "string");
if (!isValidOutput) {
throw new InferenceOutputError("Expected type Array<{translation_text: string}>");
}
return res?.[0];
return res?.length === 1 ? res?.[0] : res;
}
14 changes: 14 additions & 0 deletions packages/inference/test/HfInference.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@ describe.concurrent(
).toMatchObject({
translation_text: "Mein Name ist Wolfgang und ich lebe in Berlin",
});
// input is a list
expect(
await hf.translation({
model: "t5-base",
inputs: ["My name is Wolfgang and I live in Berlin", "I work as programmer"],
})
).toMatchObject([
{
translation_text: "Mein Name ist Wolfgang und ich lebe in Berlin",
},
{
translation_text: "Ich arbeite als Programmierer",
},
]);
});
it("zeroShotClassification", async () => {
expect.extend({
Expand Down
21 changes: 21 additions & 0 deletions packages/inference/test/tapes.json
Original file line number Diff line number Diff line change
Expand Up @@ -942,5 +942,26 @@
"vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers"
}
}
},
"f7b0286fa03058c95425a91aa758f949ce7772fbe7bd52f2b777e636251a2b8e": {
"url": "https://api-inference.huggingface.co/models/t5-base",
"init": {
"headers": {
"Content-Type": "application/json"
},
"method": "POST",
"body": "{\"inputs\":[\"My name is Wolfgang and I live in Berlin\",\"I work as programmer\"],\"options\":{}}"
},
"response": {
"body": "[{\"translation_text\":\"Mein Name ist Wolfgang und ich lebe in Berlin\"},{\"translation_text\":\"Ich arbeite als Programmierer\"}]",
"status": 200,
"statusText": "OK",
"headers": {
"access-control-allow-credentials": "true",
"connection": "keep-alive",
"content-type": "application/json",
"vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers"
}
}
}
}

0 comments on commit 07fa24b

Please sign in to comment.