-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathservices.js
More file actions
149 lines (136 loc) · 4.14 KB
/
services.js
File metadata and controls
149 lines (136 loc) · 4.14 KB
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
import Cookies from "js-cookie";
import { useAxiosPrivate } from "../../service/axios-service";
import { orgStore } from "../../store/org-store";
import { useProjectStore } from "../../store/project-store";
export function useChatAIService() {
const axiosPrivate = useAxiosPrivate();
const csrfToken = Cookies.get("csrftoken");
const { selectedOrgId } = orgStore();
const { projectId } = useProjectStore();
const orgId = selectedOrgId || "default_org";
const getAllChats = async () => {
const url = `/api/v1/visitran/${orgId}/project/${projectId}/chat`;
const response = await axiosPrivate.get(url);
return response.data || [];
};
const deleteChatById = async (conversationId) => {
const url = `/api/v1/visitran/${orgId}/project/${projectId}/chat/delete/${conversationId}`;
await axiosPrivate.delete(url, {
headers: {
"Content-Type": "application/json",
"X-CSRFToken": csrfToken,
},
});
return true;
};
const updateChatName = async (chatId, newName) => {
const url = `/api/v1/visitran/${orgId}/project/${projectId}/chat/update/${chatId}`;
const response = await axiosPrivate.patch(
url,
{ chat_name: newName },
{
headers: {
"Content-Type": "application/json",
"X-CSRFToken": csrfToken,
},
}
);
return response.data;
};
const postChatPrompt = async ({
prompt,
llm_model_architect,
llm_model_developer,
chatId = null,
chatIntentId = null,
discussionStatus = null,
chatMessageId = null,
}) => {
const url = `/api/v1/visitran/${orgId}/project/${projectId}/chat`;
const response = await axiosPrivate.post(
url,
{
prompt,
llm_model_architect,
llm_model_developer,
chat_id: chatId,
chat_intent_id: chatIntentId,
discussion_status: discussionStatus,
final_discussion_id: chatMessageId,
},
{
headers: {
"Content-Type": "application/json",
"X-CSRFToken": csrfToken,
},
}
);
return response.data || {};
};
const getChatMessagesByChatId = async (chatId) => {
const url = `/api/v1/visitran/${orgId}/project/${projectId}/chat/${chatId}/chat-message`;
const response = await axiosPrivate.get(url);
return response.data || [];
};
const getChatMessageResponseByIds = async ({ chatId, chatMessageId }) => {
const url = `/api/v1/visitran/${orgId}/project/${projectId}/chat/${chatId}/${chatMessageId}/response`;
const response = await axiosPrivate.get(url, {
headers: {
"Content-Type": "application/json",
"X-CSRFToken": csrfToken,
},
});
return response.data;
};
const getChatIntents = async () => {
const url = `/api/v1/visitran/${orgId}/project/${projectId}/chat-intent`;
const response = await axiosPrivate.get(url, {
headers: {
"Content-Type": "application/json",
"X-CSRFToken": csrfToken,
},
});
return response.data;
};
const getChatLlmModels = async () => {
const url = `/api/v1/visitran/${orgId}/project/${projectId}/chat/list-llm-models`;
const response = await axiosPrivate.get(url);
return response.data;
};
const completeOnboardingTask = async (taskId) => {
const url = `/api/v1/visitran/${orgId}/project/${projectId}/onboarding/complete-task/`;
const response = await axiosPrivate.post(
url,
{ task_id: taskId },
{
headers: {
"Content-Type": "application/json",
"X-CSRFToken": csrfToken,
},
}
);
return response.data;
};
const getOnboardingStatus = async () => {
const url = `/api/v1/visitran/${orgId}/project/${projectId}/onboarding/status/`;
const response = await axiosPrivate.get(url, {
headers: {
"Content-Type": "application/json",
"X-CSRFToken": csrfToken,
},
});
return response.data;
};
return {
getAllChats,
deleteChatById,
updateChatName,
postChatPrompt,
getChatMessagesByChatId,
getChatMessageResponseByIds,
getChatIntents,
getChatLlmModels,
completeOnboardingTask,
getOnboardingStatus,
};
}