-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transformers.js support #479
Changes from 15 commits
7d11e02
30a5426
2fd58e3
e41a129
902ab92
21ec167
a2c569a
f706410
cc7ebb1
2191648
8e62b4c
2f5d19d
d2e94ae
9dc3e50
181a0cf
bf24ea4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: "0.2" | ||
ignorePaths: | ||
- yarn.lock | ||
dictionaryDefinitions: [] | ||
dictionaries: [] | ||
words: | ||
- testhost | ||
ignoreWords: [] | ||
import: [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,10 +45,10 @@ export class TestHost implements Host { | |
return resolve(".") | ||
} | ||
installFolder(): string { | ||
throw new Error("Method not implemented.") | ||
return this.projectFolder() | ||
} | ||
resolvePath(...segments: string[]): string { | ||
throw new Error("Method not implemented.") | ||
resolvePath(...segments: string[]) { | ||
return resolve(...segments) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method
|
||
} | ||
readSecret(name: string): Promise<string> { | ||
throw new Error("Method not implemented.") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { sentiment } from "./transformers" | ||
import { readFile } from "fs/promises" | ||
import { beforeEach, describe, test } from "node:test" | ||
import assert from "node:assert/strict" | ||
import { TestHost } from "./testhost" | ||
|
||
describe("sentiment function", () => { | ||
beforeEach(() => { | ||
TestHost.install() | ||
}) | ||
test("should process love", async () => { | ||
const result = await sentiment("i love u") | ||
assert.strictEqual(result.label, "POSITIVE") | ||
assert(result.score > 0.9) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { TextClassificationOutput, pipeline } from "@xenova/transformers" | ||
import { dotGenaiscriptPath } from "./util" | ||
|
||
export async function sentiment(text: string) { | ||
const cache_dir = dotGenaiscriptPath("cache", "transformers") | ||
console.log(cache_dir) | ||
const pipe = await pipeline("sentiment-analysis", undefined, { | ||
cache_dir, | ||
}) | ||
const out = (await pipe(text)) as TextClassificationOutput | ||
console.log(out) | ||
return out[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method
installFolder
has been changed to returnthis.projectFolder()
. Please ensure thatthis.projectFolder()
is always defined and does not throw an error. 🧐