Spaces:
Running
Running
File size: 5,738 Bytes
3b93905 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
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 });
}
} |