MCPcopy
hub / github.com/LAION-AI/Open-Assistant / request

Method request

website/src/lib/oasst_api_client.ts:55–95  ·  view source on GitHub ↗
(method: "GET" | "POST" | "PUT" | "DELETE", path: string, init?: RequestInit)

Source from the content-addressed store, hash-verified

53 }
54
55 private async request<T>(method: "GET" | "POST" | "PUT" | "DELETE", path: string, init?: RequestInit): Promise<T> {
56 const resp = await fetch(`${this.oasstApiUrl}${path}`, {
57 method,
58 ...init,
59 headers: {
60 ...init?.headers,
61 ...this.userHeaders,
62 "X-API-Key": this.oasstApiKey,
63 "Content-Type": "application/json",
64 },
65 });
66
67 if (resp.status === 204) {
68 return null as T;
69 }
70
71 if (resp.status >= 300) {
72 const errorText = await resp.text();
73 let error;
74 try {
75 error = JSON.parse(errorText);
76 } catch (e) {
77 throw new OasstError({
78 message: errorText,
79 errorCode: 0,
80 httpStatusCode: resp.status,
81 path,
82 method,
83 });
84 }
85 throw new OasstError({
86 message: error.message ?? error,
87 errorCode: error.error_code,
88 httpStatusCode: resp.status,
89 path,
90 method,
91 });
92 }
93
94 return resp.json();
95 }
96
97 private async post<T>(path: string, body: unknown) {
98 return this.request<T>("POST", path, {

Callers 6

postMethod · 0.95
putMethod · 0.95
getMethod · 0.95
deleteMethod · 0.95
signin.cy.tsFile · 0.45
commands.tsFile · 0.45

Calls 2

textMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected