mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-12-03 10:33:17 +00:00
Merge branch 'main' into feat/agent-menu
This commit is contained in:
@@ -657,6 +657,7 @@ class Answer(Resource):
|
||||
source_log_docs = []
|
||||
tool_calls = []
|
||||
stream_ended = False
|
||||
thought = ""
|
||||
|
||||
for line in complete_stream(
|
||||
question=question,
|
||||
@@ -679,6 +680,8 @@ class Answer(Resource):
|
||||
source_log_docs = event["source"]
|
||||
elif event["type"] == "tool_calls":
|
||||
tool_calls = event["tool_calls"]
|
||||
elif event["type"] == "thought":
|
||||
thought = event["thought"]
|
||||
elif event["type"] == "error":
|
||||
logger.error(f"Error from stream: {event['error']}")
|
||||
return bad_request(500, event["error"])
|
||||
@@ -710,6 +713,7 @@ class Answer(Resource):
|
||||
conversation_id,
|
||||
question,
|
||||
response_full,
|
||||
thought,
|
||||
source_log_docs,
|
||||
tool_calls,
|
||||
llm,
|
||||
@@ -876,14 +880,7 @@ def get_attachments_content(attachment_ids, user):
|
||||
)
|
||||
|
||||
if attachment_doc:
|
||||
attachments.append(
|
||||
{
|
||||
"id": str(attachment_doc["_id"]),
|
||||
"content": attachment_doc["content"],
|
||||
"token_count": attachment_doc.get("token_count", 0),
|
||||
"path": attachment_doc.get("path", ""),
|
||||
}
|
||||
)
|
||||
attachments.append(attachment_doc)
|
||||
except Exception as e:
|
||||
logger.error(f"Error retrieving attachment {attachment_id}: {e}")
|
||||
|
||||
|
||||
@@ -2792,25 +2792,25 @@ class StoreAttachment(Resource):
|
||||
user = secure_filename(decoded_token.get("sub"))
|
||||
|
||||
try:
|
||||
attachment_id = ObjectId()
|
||||
original_filename = secure_filename(file.filename)
|
||||
folder_name = original_filename
|
||||
|
||||
save_dir = os.path.join(
|
||||
current_dir, settings.UPLOAD_FOLDER, user, "attachments", folder_name
|
||||
current_dir,
|
||||
settings.UPLOAD_FOLDER,
|
||||
user,
|
||||
"attachments",
|
||||
str(attachment_id),
|
||||
)
|
||||
os.makedirs(save_dir, exist_ok=True)
|
||||
# Create directory structure: user/attachments/filename/
|
||||
|
||||
file_path = os.path.join(save_dir, original_filename)
|
||||
|
||||
# Handle filename conflicts
|
||||
if os.path.exists(file_path):
|
||||
name_parts = os.path.splitext(original_filename)
|
||||
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
||||
new_filename = f"{name_parts[0]}_{timestamp}{name_parts[1]}"
|
||||
file_path = os.path.join(save_dir, new_filename)
|
||||
original_filename = new_filename
|
||||
|
||||
file.save(file_path)
|
||||
file_info = {"folder": folder_name, "filename": original_filename}
|
||||
file_info = {
|
||||
"filename": original_filename,
|
||||
"attachment_id": str(attachment_id),
|
||||
}
|
||||
current_app.logger.info(f"Saved file: {file_path}")
|
||||
|
||||
# Start async task to process single file
|
||||
|
||||
Reference in New Issue
Block a user