2023-03-26 06:06:10 +00:00
|
|
|
// services
|
|
|
|
import APIService from "services/api.service";
|
2023-03-30 13:57:46 +00:00
|
|
|
import trackEventServices from "services/track-event.service";
|
|
|
|
|
2023-03-28 18:50:00 +00:00
|
|
|
// types
|
2023-06-06 16:06:00 +00:00
|
|
|
import { ICurrentUserResponse, IGptResponse } from "types";
|
2023-03-26 06:06:10 +00:00
|
|
|
|
|
|
|
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
const trackEvent =
|
|
|
|
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";
|
|
|
|
|
2023-03-26 06:06:10 +00:00
|
|
|
class AiServices extends APIService {
|
|
|
|
constructor() {
|
|
|
|
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
|
|
|
|
}
|
|
|
|
|
|
|
|
async createGptTask(
|
|
|
|
workspaceSlug: string,
|
|
|
|
projectId: string,
|
2023-06-06 16:06:00 +00:00
|
|
|
data: { prompt: string; task: string },
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-28 18:50:00 +00:00
|
|
|
): Promise<IGptResponse> {
|
2023-03-26 06:06:10 +00:00
|
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/ai-assistant/`, data)
|
2023-03-30 13:57:46 +00:00
|
|
|
.then((response) => {
|
2023-06-06 16:06:00 +00:00
|
|
|
if (trackEvent) trackEventServices.trackAskGptEvent(response?.data, "ASK_GPT", user);
|
2023-03-30 13:57:46 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-26 06:06:10 +00:00
|
|
|
.catch((error) => {
|
2023-03-30 13:15:33 +00:00
|
|
|
throw error?.response;
|
2023-03-26 06:06:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new AiServices();
|