import axios, { AxiosInstance, CreateAxiosDefaults } from 'axios';
import { AuthenticationError } from './exceptions';
import {
get_balance,
get_image,
get_model,
get_models,
get_file,
get_files,
get_batch,
get_batches,
get_batch_status,
post_ai_check,
post_auth,
post_batch,
post_chat,
post_embeddings,
post_files,
post_files_delete,
post_token,
post_tokens_count,
stream_chat,
stream_chat_readable,
} from './api';
import {
AccessToken,
AICheckResult,
Balance,
Batch,
BATCH_METHOD,
BatchRequest,
BatchStatus,
BatchStatuses,
Chat,
ChatCompletion,
ChatCompletionChunk,
DeletedFile,
Embeddings,
Image,
Model,
Models,
Token,
Tokens,
UploadedFile,
UploadedFiles,
WithXHeaders,
} from './interfaces';
import { getDefaultSettings, Settings } from './settings';
import { EventEmitter } from 'events';
import { isRunningInBrowser } from './api/utils';
const GIGACHAT_MODEL = 'GigaChat';
export interface GigaChatClientConfig {
/** Адрес относительно которого выполняются запросы */
baseUrl?: string;
/** Адрес для запроса токена доступа OAuth 2.0 */
authUrl?: string;
/** Авторизационные данные */
credentials?: string;
/** Версия API, к которой предоставляется доступ */
scope?: string;
/** JWE токен */
accessToken?: string;
/** Название модели, от которой нужно получить ответ */
model?: string;
/** Параметр цензуры */
profanityCheck?: boolean;
/** Имя пользователя */
user?: string;
/** Пароль */
password?: string;
/** Таймаут в секундах */
timeout?: number;
/** Детализация запросов в консоли */
verbose?: boolean;
/** Флаги, включающие особенные фичи */
flags?: string[];
/** HTTPS Agent, который прокидывается в Axios клиент */
httpsAgent?: any;
/** Включает работу библиотеку в браузере */
dangerouslyAllowBrowser?: boolean;
}
export interface DetectedImage {
uuid?: string;
postfix?: string;
}
export interface DetectedVideo {
uuid?: string;
cover_uuid?: string;
postfix?: string;
}
export function detectImage(message: string): DetectedImage | null {
const regex = /
.+?)"\sfuse="true"\/>(?.*)?/ms;
const match = regex.exec(message);
if (!match || !match.groups) return null;
return {
uuid: match.groups['uuid'],
postfix: match.groups['postfix'],
};
}
export function detectVideo(message: string): DetectedVideo | null {
const regex = /