mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-09-11 11:50:17 +08:00
fix: retrieval of valid_labels from API to populate the TEXT_LABEL_FLAGS in FlaggableElements.tsx
This commit is contained in:
@@ -48,6 +48,33 @@ export class OasstApiClient {
|
||||
return await resp.json();
|
||||
}
|
||||
|
||||
private async get(path: string): Promise<any> {
|
||||
const resp = await fetch(`${this.oasstApiUrl}${path}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"X-API-Key": this.oasstApiKey,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (resp.status == 204) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (resp.status >= 300) {
|
||||
const errorText = await resp.text();
|
||||
let error: any;
|
||||
try {
|
||||
error = JSON.parse(errorText);
|
||||
} catch (e) {
|
||||
throw new OasstError(errorText, 0, resp.status);
|
||||
}
|
||||
throw new OasstError(error.message ?? error, error.error_code, resp.status);
|
||||
}
|
||||
|
||||
return await resp.json();
|
||||
}
|
||||
|
||||
// TODO return a strongly typed Task?
|
||||
// This method is used to store a task in RegisteredTask.task.
|
||||
// This is a raw Json type, so we can't use it to strongly type the task.
|
||||
@@ -96,6 +123,12 @@ export class OasstApiClient {
|
||||
...content,
|
||||
});
|
||||
}
|
||||
|
||||
//Fetch valid labels. This is called every task. though the call may be redundant
|
||||
//keeping this for future where the valid labels may change per task
|
||||
async fetch_valid_text(): Promise<void> {
|
||||
return this.get(`/api/v1/text_labels/valid_labels`);
|
||||
}
|
||||
}
|
||||
|
||||
export const oasstApiClient =
|
||||
|
||||
Reference in New Issue
Block a user