Skip to content

Commit

Permalink
Add possibility to change the description of a document
Browse files Browse the repository at this point in the history
  • Loading branch information
homanp committed Aug 7, 2023
1 parent 4d8c4a6 commit 3aae592
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/api/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async def create_document(body: Document, token=Depends(JWTBearer())):
document = prisma.document.create(
{
"type": body.type,
"description": body.description,
"url": body.url,
"content": body.content,
"contentHash": content_hash,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/agents/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def _get_tools(self) -> list:
embeddings = OpenAIEmbeddings()

for agent_document in self.documents:
description = (
description = agent_document.document.description or (
f"useful for finding information about {agent_document.document.name}"
)
args_schema = DocumentInput if self.type == "OPENAI" else None
Expand Down
1 change: 1 addition & 0 deletions app/lib/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class Document(BaseModel):
type: str
url: str | None = None
description: str | None = None
content: str | None = None
name: str
authorization: dict | None = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Document" ADD COLUMN "description" TEXT;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ model Profile {

model Document {
id String @id @default(cuid()) @db.VarChar(255)
description String? @db.Text()
userId String @db.VarChar(255)
user User @relation(fields: [userId], references: [id])
type DocumentType @default(TXT)
Expand Down
30 changes: 27 additions & 3 deletions ui/app/documents/client-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,20 @@ export default function DocumentsClientPage({ data, session }) {
};

const onSubmit = async (values) => {
const { type, name, url, auth_type, auth_key, auth_value, ...metadata } =
values;
const {
type,
name,
description,
url,
auth_type,
auth_key,
auth_value,
...metadata
} = values;
const payload = {
name,
metadata,
description,
type,
url,
authorization: auth_key && {
Expand All @@ -163,7 +172,6 @@ export default function DocumentsClientPage({ data, session }) {
value: auth_value,
},
};
console.log(payload);

if (selectedDocument) {
await api.patchDocument(selectedDocument, payload);
Expand Down Expand Up @@ -218,6 +226,7 @@ export default function DocumentsClientPage({ data, session }) {
setValue("name", document?.name);
setValue("url", document?.url);
setValue("type", document?.type);
setValue("description", document?.description);
onOpen();
};

Expand Down Expand Up @@ -357,6 +366,7 @@ export default function DocumentsClientPage({ data, session }) {
<FormControl isRequired isInvalid={errors?.name}>
<FormLabel>Name</FormLabel>
<Input
placeholder="My document"
type="text"
{...register("name", { required: true })}
/>
Expand All @@ -365,6 +375,20 @@ export default function DocumentsClientPage({ data, session }) {
<FormErrorMessage>Invalid name</FormErrorMessage>
)}
</FormControl>
<FormControl isRequired isInvalid={errors?.description}>
<FormLabel>Description</FormLabel>
<Input
type="text"
placeholder="Useful for finding information about..."
{...register("description", { required: true })}
/>
<FormHelperText>
What is this document useful for?
</FormHelperText>
{errors?.description && (
<FormErrorMessage>Invalid description</FormErrorMessage>
)}
</FormControl>
{documentType === "URL" ? (
<FormControl
isRequired
Expand Down

0 comments on commit 3aae592

Please sign in to comment.