-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0e0be6
commit 71ae7c1
Showing
24 changed files
with
404 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from retk import core | ||
from retk.controllers import schemas | ||
from retk.controllers.node.node_ops import get_node_data | ||
from retk.controllers.utils import maybe_raise_json_exception | ||
from retk.models.tps import AuthedUser | ||
|
||
|
||
async def get_extended_nodes( | ||
au: AuthedUser, | ||
) -> schemas.ai.GetExtendedNodesResponse: | ||
docs = await core.ai.llm.knowledge.extended.get_extended_nodes(uid=au.u.id) | ||
return schemas.ai.GetExtendedNodesResponse( | ||
requestId=au.request_id, | ||
nodes=[schemas.ai.GetExtendedNodesResponse.Node( | ||
id=str(doc["_id"]), | ||
sourceNid=doc["sourceNid"], | ||
sourceTitle=doc["sourceMd"].split("\n", 1)[0].strip(), | ||
md=doc["extendMd"], | ||
) for doc in docs] | ||
) | ||
|
||
|
||
async def accept_extended_node( | ||
au: AuthedUser, | ||
eid: str, | ||
) -> schemas.node.NodeResponse: | ||
n, code = await core.ai.llm.knowledge.extended.accept_extended_node( | ||
au=au, | ||
eid=eid, | ||
) | ||
maybe_raise_json_exception(au=au, code=code) | ||
return schemas.node.NodeResponse( | ||
requestId=au.request_id, | ||
node=get_node_data(n), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
manager, | ||
statistic, | ||
notice, | ||
ai, | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import List | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class GetExtendedNodesResponse(BaseModel): | ||
class Node(BaseModel): | ||
id: str | ||
sourceNid: str | ||
sourceTitle: str | ||
md: str | ||
|
||
requestId: str | ||
nodes: List[Node] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ | |
self_hosted, | ||
notice, | ||
analysis, | ||
ai, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import List, Tuple | ||
|
||
from bson import ObjectId | ||
|
||
from retk import core | ||
from retk.config import is_local_db | ||
from retk.const import CodeEnum | ||
from retk.models.client import client | ||
from retk.models.tps import AuthedUser | ||
from retk.models.tps.llm import ExtendedNode | ||
from retk.models.tps.node import Node | ||
from retk.utils import get_at_node_md_link | ||
|
||
|
||
async def get_extended_nodes( | ||
uid: str, | ||
) -> List[ExtendedNode]: | ||
docs = await client.coll.llm_extended_node.find({"uid": uid}).to_list(None) | ||
return docs | ||
|
||
|
||
async def accept_extended_node( | ||
au: AuthedUser, | ||
eid: str, | ||
) -> Tuple[Node, CodeEnum]: | ||
if not is_local_db(): | ||
doc = await client.coll.llm_extended_node.find_one_and_delete( | ||
{"_id": ObjectId(eid)}, | ||
) | ||
else: | ||
doc = await client.coll.llm_extended_node.find_one( | ||
{"_id": ObjectId(eid)}, | ||
) | ||
await client.coll.llm_extended_node.delete_one( | ||
{"_id": ObjectId(eid)}, | ||
) | ||
title = doc["sourceMd"].split("\n", 1)[0].strip() | ||
at_node = get_at_node_md_link(title, doc["sourceNid"]) | ||
md = doc["extendMd"] + "\n\n" + at_node | ||
n, code = await core.node.post( | ||
au=au, | ||
md=md, | ||
from_nid=doc["sourceNid"], | ||
) | ||
return n, code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.