27 lines
622 B
TypeScript
27 lines
622 B
TypeScript
import { fetch } from 'undici';
|
|
|
|
interface BalabolaResponse {
|
|
bad_query: number,
|
|
query: string,
|
|
text: string,
|
|
error: number,
|
|
is_cached: number,
|
|
empty_zeliboba: number,
|
|
intro: number,
|
|
signature: string;
|
|
}
|
|
|
|
const BASE_URL = 'https://yandex.ru/lab/api/yalm/text3';
|
|
|
|
export async function balabola(query: string, intro: number): Promise<string> {
|
|
const result = await fetch(BASE_URL, {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
filter: 1,
|
|
intro,
|
|
query
|
|
})
|
|
}).then(res => res.json()) as BalabolaResponse;
|
|
|
|
return result.text;
|
|
} |