Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix trigger task #438

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client/app/factory/edit/components/KnowledgeBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import RefreshIcon from '@/public/icons/RefreshIcon';
import { useBotTask } from './TaskContext';

type IProps = {
botId: string;
repoName: string;
onClick: () => void;
mode: 'configItem' | 'pageHeader';
};

const KnowledgeBtn = (props: IProps) => {
const { onClick, botId, mode } = props;
const { onClick, repoName, mode } = props;
const { setTaskProfile } = useBotTask();
const [shouldGetTask, setShouldGetTask] = React.useState<boolean>(!!botId);
const [shouldGetTask, setShouldGetTask] = React.useState<boolean>(!!repoName);
const [taskLoading, setTaskLoading] = React.useState<boolean>(true);
const [allowShowChunkList, setAllowShowChunkList] =
React.useState<boolean>(false);

const { data: taskList } = useGetBotRagTask(botId, shouldGetTask, true);
const { data: taskList } = useGetBotRagTask(repoName, shouldGetTask, true);
const taskCnt = taskList?.length ?? 0;

// compute task running status by taskList
Expand Down
2 changes: 1 addition & 1 deletion client/app/factory/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export default function Edit() {
)}
{isEdit && activeTab === ConfigTypeEnum.MANUAL_CONFIG && (
<KnowledgeBtn
botId={botProfile.id}
repoName={botProfile.repoName!}
onClick={() => {
setVisibleType(VisibleTypeEnum.KNOWLEDGE_DETAIL);
}}
Expand Down
6 changes: 3 additions & 3 deletions client/app/hooks/useBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ export const useBotRAGChunkList = (
};

export const useGetBotRagTask = (
botId: string,
repoName: string,
enabled: boolean = true,
refetchInterval: boolean = true,
) => {
return useQuery({
queryKey: [`rag.task`, botId],
queryFn: async () => getRagTask(botId),
queryKey: [`rag.task`, repoName],
queryFn: async () => getRagTask(repoName),
select: (data) => data,
enabled,
retry: true,
Expand Down
4 changes: 2 additions & 2 deletions client/app/services/BotsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export async function getChunkList(
return response.data;
}

export async function getRagTask(bot_id: string): Promise<RagTask[]> {
export async function getRagTask(repo_name: string): Promise<RagTask[]> {
const response = await axios.get(
`${apiDomain}/api/rag/task/latest?bot_id=${bot_id}`,
`${apiDomain}/api/rag/task/latest?repo_name=${repo_name}`,
);
return response.data.data;
}
Expand Down
12 changes: 8 additions & 4 deletions petercat_utils/rag_helper/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@
return response.data[0] if (len(response.data) > 0) else None


def get_task(task_type: TaskType, task_id: str) -> GitTask:
def get_task(
task_type: TaskType,
task_id: str,
bot_id: Optional[str],
) -> GitTask:
supabase = get_client()
response = (
supabase.table(GitTask.get_table_name(task_type))
Expand All @@ -71,7 +75,7 @@
sha=data["sha"],
repo_name=data["repo_name"],
node_type=data["node_type"],
bot_id=data["bot_id"],
bot_id=bot_id,
path=data["path"],
status=data["status"],
from_id=data["from_task_id"],
Expand All @@ -88,8 +92,8 @@
)


def trigger_task(task_type: TaskType, task_id: Optional[str]):
task = get_task(task_type, task_id) if task_id else get_oldest_task()
def trigger_task(task_type: TaskType, bot_id: Optional[str], task_id: Optional[str]):
task = get_task(task_type, bot_id, task_id) if task_id else get_oldest_task()

Check warning on line 96 in petercat_utils/rag_helper/task.py

View check run for this annotation

Codecov / codecov/patch

petercat_utils/rag_helper/task.py#L96

Added line #L96 was not covered by tests
if task is None:
return task
return task.handle()
8 changes: 4 additions & 4 deletions server/rag/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@


@router.post("/rag/trigger_task", dependencies=[Depends(verify_rate_limit)])
def trigger_task(task_type: TaskType, task_id: Optional[str] = None):
def trigger_task(task_type: TaskType, bot_id: str, task_id: Optional[str] = None):
try:
task.trigger_task(task_type, task_id)
task.trigger_task(task_type, task_id, bot_id)

Check warning on line 87 in server/rag/router.py

View check run for this annotation

Codecov / codecov/patch

server/rag/router.py#L87

Added line #L87 was not covered by tests
except Exception as e:
return json.dumps({"success": False, "message": str(e)})

Expand All @@ -98,14 +98,14 @@


@router.get("/rag/task/latest", dependencies=[Depends(verify_rate_limit)])
def get_rag_task(bot_id: str):
def get_rag_task(repo_name: str):
# TODO: Think about hot to get correct when reload knowledge task was triggered
try:
supabase = get_client()
response = (
supabase.table("rag_tasks")
.select("id,status,node_type,path,from_task_id,created_at", count="exact")
.eq("bot_id", bot_id)
.eq("repo_name", repo_name)
.order("created_at", desc=True)
.execute()
)
Expand Down
4 changes: 2 additions & 2 deletions server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ requests
pytest
httpx
urllib3>=2.2.2
petercat_utils>=0.1.31
toolz
petercat_utils>=0.1.36
toolz
2 changes: 1 addition & 1 deletion subscriber/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
petercat_utils>=0.1.32
petercat_utils>=0.1.36