flare / flare-ui /src /app /services /api.service.ts
ciyidogan's picture
Upload 18 files
3b93905 verified
raw
history blame
5.74 kB
import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
// Models
export interface Environment {
work_mode: string;
cloud_token: string;
spark_endpoint: string;
}
export interface Project {
id: number;
name: string;
caption: string;
enabled: boolean;
last_version_number: number;
version_id_counter: number;
versions: Version[];
deleted: boolean;
created_date: string;
created_by: string;
last_update_date: string;
last_update_user: string;
}
export interface Version {
id: number;
caption: string;
published: boolean;
general_prompt: string;
llm: LLMConfig;
intents: Intent[];
created_date: string;
created_by: string;
last_update_date: string;
last_update_user: string;
publish_date?: string;
published_by?: string;
deleted?: boolean;
}
export interface LLMConfig {
repo_id: string;
generation_config: {
max_new_tokens: number;
temperature: number;
top_p: number;
repetition_penalty: number;
};
use_fine_tune: boolean;
fine_tune_zip: string;
}
export interface Intent {
name: string;
caption: string;
locale: string;
detection_prompt: string;
examples: string[];
parameters: Parameter[];
action: string;
fallback_timeout_prompt?: string;
fallback_error_prompt?: string;
}
export interface Parameter {
name: string;
caption: string;
type: string;
required: boolean;
variable_name: string;
extraction_prompt: string;
validation_regex?: string;
invalid_prompt?: string;
type_error_prompt?: string;
}
export interface API {
name: string;
url: string;
method: string;
headers: Record<string, string>;
body_template: any;
timeout_seconds: number;
retry: {
retry_count: number;
backoff_seconds: number;
strategy: string;
};
proxy?: string;
auth?: APIAuth;
response_prompt?: string;
deleted: boolean;
created_date: string;
created_by: string;
last_update_date: string;
last_update_user: string;
}
export interface APIAuth {
enabled: boolean;
token_endpoint?: string;
response_token_path?: string;
token_request_body?: any;
token_refresh_endpoint?: string;
token_refresh_body?: any;
}
@Injectable({
providedIn: 'root'
})
export class ApiService {
private http = inject(HttpClient);
private baseUrl = '/api';
// Environment
getEnvironment(): Observable<Environment> {
return this.http.get<Environment>(`${this.baseUrl}/environment`);
}
updateEnvironment(env: Environment): Observable<any> {
return this.http.put(`${this.baseUrl}/environment`, env);
}
// Projects
getProjects(includeDeleted = false): Observable<Project[]> {
return this.http.get<Project[]>(`${this.baseUrl}/projects?include_deleted=${includeDeleted}`);
}
createProject(project: { name: string; caption: string }): Observable<Project> {
return this.http.post<Project>(`${this.baseUrl}/projects`, project);
}
updateProject(id: number, update: { caption: string; last_update_date: string }): Observable<Project> {
return this.http.put<Project>(`${this.baseUrl}/projects/${id}`, update);
}
deleteProject(id: number): Observable<any> {
return this.http.delete(`${this.baseUrl}/projects/${id}`);
}
toggleProject(id: number): Observable<{ enabled: boolean }> {
return this.http.patch<{ enabled: boolean }>(`${this.baseUrl}/projects/${id}/toggle`, {});
}
exportProject(id: number): Observable<any> {
return this.http.get(`${this.baseUrl}/projects/${id}/export`);
}
importProject(data: any): Observable<any> {
return this.http.post(`${this.baseUrl}/projects/import`, data);
}
// Versions
createVersion(projectId: number, sourceVersionId: number, caption: string): Observable<Version> {
return this.http.post<Version>(`${this.baseUrl}/projects/${projectId}/versions`, {
source_version_id: sourceVersionId,
caption
});
}
updateVersion(projectId: number, versionId: number, update: any): Observable<Version> {
return this.http.put<Version>(`${this.baseUrl}/projects/${projectId}/versions/${versionId}`, update);
}
publishVersion(projectId: number, versionId: number): Observable<any> {
return this.http.post(`${this.baseUrl}/projects/${projectId}/versions/${versionId}/publish`, {});
}
deleteVersion(projectId: number, versionId: number): Observable<any> {
return this.http.delete(`${this.baseUrl}/projects/${projectId}/versions/${versionId}`);
}
// APIs
getAPIs(includeDeleted = false): Observable<API[]> {
return this.http.get<API[]>(`${this.baseUrl}/apis?include_deleted=${includeDeleted}`);
}
createAPI(api: Partial<API>): Observable<API> {
return this.http.post<API>(`${this.baseUrl}/apis`, api);
}
updateAPI(name: string, update: any): Observable<API> {
return this.http.put<API>(`${this.baseUrl}/apis/${name}`, update);
}
deleteAPI(name: string): Observable<any> {
return this.http.delete(`${this.baseUrl}/apis/${name}`);
}
testAPI(api: Partial<API>): Observable<any> {
return this.http.post(`${this.baseUrl}/apis/test`, api);
}
// Testing
runTests(testType: string): Observable<any> {
return this.http.post(`${this.baseUrl}/test/run-all`, { test_type: testType });
}
// Validation
validateRegex(pattern: string, testValue: string): Observable<{ valid: boolean; matches?: boolean; error?: string }> {
return this.http.post<any>(`${this.baseUrl}/validate/regex`, { pattern, test_value: testValue });
}
}