Skip to content

Commit

Permalink
feat(server):libro notebook show python flow
Browse files Browse the repository at this point in the history
  • Loading branch information
yhjun1026 committed Nov 18, 2024
1 parent e2bd343 commit b6543c2
Show file tree
Hide file tree
Showing 393 changed files with 1,814 additions and 2,062 deletions.
1 change: 1 addition & 0 deletions dbgpt/agent/core/plan/awel/agent_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ async def get_agent(
prompt_template = None
if self.awel_agent.agent_prompt:
from dbgpt.serve.prompt.api.endpoints import get_service

prompt_service = get_service()
prompt_template = prompt_service.get_template(
self.awel_agent.agent_prompt.code
Expand Down
2 changes: 2 additions & 0 deletions dbgpt/agent/core/plan/awel/agent_operator_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ResourceCategory,
register_resource,
)

from ....resource.base import AgentResource, ResourceType
from ....resource.manage import get_resource_manager
from ....util.llm.llm import LLMConfig, LLMStrategyType
Expand All @@ -20,6 +21,7 @@

def _agent_resource_prompt_values() -> List[OptionValue]:
from dbgpt.serve.prompt.api.endpoints import get_service

prompt_service = get_service()
prompts = prompt_service.get_target_prompt()
return [
Expand Down
132 changes: 67 additions & 65 deletions dbgpt/app/knowledge/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import os
import shutil
import tempfile
from typing import List
from pathlib import Path
from typing import List

from fastapi import APIRouter, Depends, File, Form, UploadFile, HTTPException
from fastapi import APIRouter, Depends, File, Form, HTTPException, UploadFile

from dbgpt._private.config import Config
from dbgpt.app.knowledge.request.request import (
Expand Down Expand Up @@ -333,70 +333,72 @@ def document_delete(space_name: str, query_request: DocumentQueryRequest):

@router.post("/knowledge/{space_name}/document/upload")
async def document_upload(
space_name: str,
doc_name: str = Form(...),
doc_type: str = Form(...),
doc_file: UploadFile = File(...),
space_name: str,
doc_name: str = Form(...),
doc_type: str = Form(...),
doc_file: UploadFile = File(...),
):
print(f"/document/upload params: {space_name}")
try:
if doc_file:
# Sanitize inputs to prevent path traversal
safe_space_name = os.path.basename(space_name)
safe_filename = os.path.basename(doc_file.filename)

# Create absolute paths and verify they are within allowed directory
upload_dir = os.path.abspath(os.path.join(KNOWLEDGE_UPLOAD_ROOT_PATH, safe_space_name))
target_path = os.path.abspath(os.path.join(upload_dir, safe_filename))

if not os.path.abspath(KNOWLEDGE_UPLOAD_ROOT_PATH) in target_path:
raise HTTPException(status_code=400, detail="Invalid path detected")

if not os.path.exists(upload_dir):
os.makedirs(upload_dir)

# Create temp file
tmp_fd, tmp_path = tempfile.mkstemp(dir=upload_dir)

try:
with os.fdopen(tmp_fd, "wb") as tmp:
tmp.write(await doc_file.read())

shutil.move(tmp_path, target_path)

request = KnowledgeDocumentRequest()
request.doc_name = doc_name
request.doc_type = doc_type
request.content = target_path

space_res = knowledge_space_service.get_knowledge_space(
KnowledgeSpaceRequest(name=safe_space_name)
)
if len(space_res) == 0:
# create default space
if "default" != safe_space_name:
raise Exception(f"you have not create your knowledge space.")
knowledge_space_service.create_knowledge_space(
KnowledgeSpaceRequest(
name=safe_space_name,
desc="first db-gpt rag application",
owner="dbgpt",
)
)
return Result.succ(
knowledge_space_service.create_knowledge_document(
space=safe_space_name, request=request
)
)
except Exception as e:
# Clean up temp file if anything goes wrong
if os.path.exists(tmp_path):
os.unlink(tmp_path)
raise e

return Result.failed(code="E000X", msg=f"doc_file is None")
except Exception as e:
return Result.failed(code="E000X", msg=f"document add error {e}")
print(f"/document/upload params: {space_name}")
try:
if doc_file:
# Sanitize inputs to prevent path traversal
safe_space_name = os.path.basename(space_name)
safe_filename = os.path.basename(doc_file.filename)

# Create absolute paths and verify they are within allowed directory
upload_dir = os.path.abspath(
os.path.join(KNOWLEDGE_UPLOAD_ROOT_PATH, safe_space_name)
)
target_path = os.path.abspath(os.path.join(upload_dir, safe_filename))

if not os.path.abspath(KNOWLEDGE_UPLOAD_ROOT_PATH) in target_path:
raise HTTPException(status_code=400, detail="Invalid path detected")

if not os.path.exists(upload_dir):
os.makedirs(upload_dir)

# Create temp file
tmp_fd, tmp_path = tempfile.mkstemp(dir=upload_dir)

try:
with os.fdopen(tmp_fd, "wb") as tmp:
tmp.write(await doc_file.read())

shutil.move(tmp_path, target_path)

request = KnowledgeDocumentRequest()
request.doc_name = doc_name
request.doc_type = doc_type
request.content = target_path

space_res = knowledge_space_service.get_knowledge_space(
KnowledgeSpaceRequest(name=safe_space_name)
)
if len(space_res) == 0:
# create default space
if "default" != safe_space_name:
raise Exception(f"you have not create your knowledge space.")
knowledge_space_service.create_knowledge_space(
KnowledgeSpaceRequest(
name=safe_space_name,
desc="first db-gpt rag application",
owner="dbgpt",
)
)
return Result.succ(
knowledge_space_service.create_knowledge_document(
space=safe_space_name, request=request
)
)
except Exception as e:
# Clean up temp file if anything goes wrong
if os.path.exists(tmp_path):
os.unlink(tmp_path)
raise e

return Result.failed(code="E000X", msg=f"doc_file is None")
except Exception as e:
return Result.failed(code="E000X", msg=f"document add error {e}")


@router.post("/knowledge/{space_name}/document/sync")
Expand Down
2 changes: 1 addition & 1 deletion dbgpt/app/static/web/404.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="icon" href="/favicon.ico"/><meta name="description" content="Revolutionizing Database Interactions with Private LLM Technology"/><meta property="og:description" content="eosphoros-ai"/><meta property="og:title" content="DB-GPT"/><link rel="preload" href="/_next/static/css/56abd552837c60f9.css" as="style"/><link rel="stylesheet" href="/_next/static/css/56abd552837c60f9.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-78c92fac7aa8fdd8.js"></script><script src="/_next/static/chunks/webpack-3257fddca97289f9.js" defer=""></script><script src="/_next/static/chunks/framework-fb9c0d50ace2b075.js" defer=""></script><script src="/_next/static/chunks/main-fd0d7e13da40ad83.js" defer=""></script><script src="/_next/static/chunks/pages/_app-e3c58054813ebb2b.js" defer=""></script><script src="/_next/static/chunks/pages/_error-4fa9991a75118e6f.js" defer=""></script><script src="/_next/static/ujdCH5HCMF0OXSAWRqVTP/_buildManifest.js" defer=""></script><script src="/_next/static/ujdCH5HCMF0OXSAWRqVTP/_ssgManifest.js" defer=""></script><link rel="stylesheet" href="/_next/static/css/antd-output/antd.min.7d5365b5.css"/></head><body><div id="__next"><div></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"ujdCH5HCMF0OXSAWRqVTP","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="icon" href="/favicon.ico"/><meta name="description" content="Revolutionizing Database Interactions with Private LLM Technology"/><meta property="og:description" content="eosphoros-ai"/><meta property="og:title" content="DB-GPT"/><link rel="preload" href="/_next/static/css/56abd552837c60f9.css" as="style"/><link rel="stylesheet" href="/_next/static/css/56abd552837c60f9.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-78c92fac7aa8fdd8.js"></script><script src="/_next/static/chunks/webpack-f9489bc48c5d1540.js" defer=""></script><script src="/_next/static/chunks/framework-8b06d32cbb857e0e.js" defer=""></script><script src="/_next/static/chunks/main-6c4c7f5b8c9b1320.js" defer=""></script><script src="/_next/static/chunks/pages/_app-7c76237d5662964a.js" defer=""></script><script src="/_next/static/chunks/pages/_error-8095ba9e1bf12f30.js" defer=""></script><script src="/_next/static/QHtMdHeCAaKO8ydZbTior/_buildManifest.js" defer=""></script><script src="/_next/static/QHtMdHeCAaKO8ydZbTior/_ssgManifest.js" defer=""></script><link rel="stylesheet" href="/_next/static/css/antd-output/antd.min.7d5365b5.css"/></head><body><div id="__next"><div></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"QHtMdHeCAaKO8ydZbTior","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
2 changes: 1 addition & 1 deletion dbgpt/app/static/web/404/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="icon" href="/favicon.ico"/><meta name="description" content="Revolutionizing Database Interactions with Private LLM Technology"/><meta property="og:description" content="eosphoros-ai"/><meta property="og:title" content="DB-GPT"/><link rel="preload" href="/_next/static/css/56abd552837c60f9.css" as="style"/><link rel="stylesheet" href="/_next/static/css/56abd552837c60f9.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-78c92fac7aa8fdd8.js"></script><script src="/_next/static/chunks/webpack-3257fddca97289f9.js" defer=""></script><script src="/_next/static/chunks/framework-fb9c0d50ace2b075.js" defer=""></script><script src="/_next/static/chunks/main-fd0d7e13da40ad83.js" defer=""></script><script src="/_next/static/chunks/pages/_app-e3c58054813ebb2b.js" defer=""></script><script src="/_next/static/chunks/pages/_error-4fa9991a75118e6f.js" defer=""></script><script src="/_next/static/ujdCH5HCMF0OXSAWRqVTP/_buildManifest.js" defer=""></script><script src="/_next/static/ujdCH5HCMF0OXSAWRqVTP/_ssgManifest.js" defer=""></script><link rel="stylesheet" href="/_next/static/css/antd-output/antd.min.7d5365b5.css"/></head><body><div id="__next"><div></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"ujdCH5HCMF0OXSAWRqVTP","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="icon" href="/favicon.ico"/><meta name="description" content="Revolutionizing Database Interactions with Private LLM Technology"/><meta property="og:description" content="eosphoros-ai"/><meta property="og:title" content="DB-GPT"/><link rel="preload" href="/_next/static/css/56abd552837c60f9.css" as="style"/><link rel="stylesheet" href="/_next/static/css/56abd552837c60f9.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-78c92fac7aa8fdd8.js"></script><script src="/_next/static/chunks/webpack-f9489bc48c5d1540.js" defer=""></script><script src="/_next/static/chunks/framework-8b06d32cbb857e0e.js" defer=""></script><script src="/_next/static/chunks/main-6c4c7f5b8c9b1320.js" defer=""></script><script src="/_next/static/chunks/pages/_app-7c76237d5662964a.js" defer=""></script><script src="/_next/static/chunks/pages/_error-8095ba9e1bf12f30.js" defer=""></script><script src="/_next/static/QHtMdHeCAaKO8ydZbTior/_buildManifest.js" defer=""></script><script src="/_next/static/QHtMdHeCAaKO8ydZbTior/_ssgManifest.js" defer=""></script><link rel="stylesheet" href="/_next/static/css/antd-output/antd.min.7d5365b5.css"/></head><body><div id="__next"><div></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"QHtMdHeCAaKO8ydZbTior","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
Loading

0 comments on commit b6543c2

Please sign in to comment.