-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf682e1
commit b11a362
Showing
1 changed file
with
1 addition
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1 @@ | ||
import api from '@api/edenai' | ||
|
||
import type { | ||
TextModerationCreateBodyParam, | ||
TextModerationCreateResponse200, | ||
} from '@api/edenai/types' | ||
import { ResultAsync, err, ok } from 'neverthrow' | ||
|
||
export default class Client { | ||
constructor(token: string) { | ||
api.auth(token) | ||
} | ||
|
||
public textModeration( | ||
params: TextModerationCreateBodyParam, | ||
): ResultAsync<TextModerationResult, Error> { | ||
return ResultAsync.fromPromise( | ||
api.text_moderation_create(params), | ||
(originalError) => new Error('issue', { cause: originalError }), | ||
).andThen((response) => { | ||
if (response.status !== 200) err(response.data) | ||
return ok(response.data) | ||
}) | ||
} | ||
} | ||
|
||
export class TextModerationError extends Error {} | ||
|
||
export type TextModerationResult = TextModerationCreateResponse200 | ||
export * from './generated/typescript' |