Skip to content

Commit 17afc42

Browse files
authored
Merge pull request #37 from pattern-tech/refactor/repo-structure
Refactor/repo structure
2 parents 3b214f6 + e75320a commit 17afc42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1274
-4019
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,6 @@ pyrightconfig.json
332332
# End of https://www.toptal.com/developers/gitignore/api/node,python,yarn
333333

334334

335-
.vscode
335+
.vscode
336+
337+
config.json

api/.env.sample

+15-37
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#------------------------
2+
# DATABASE
3+
#------------------------
14
POSTGRES_HOST=postgres
25
POSTGRES_PORT=5432
36
POSTGRES_DB=pattern-core
@@ -6,40 +9,15 @@ POSTGRES_PASSWORD=postgres
69

710
JWT_SECRET_KEY=mysecretkey
811

9-
QDRANT_URL=http://qdrant:6333
10-
QDRANT_COLLECTION=pattern-core
11-
12-
LANGCHAIN_API_KEY=
13-
14-
#functions
15-
GOOGLE_SEARCH_URL=https://google.serper.dev/search
16-
REDDIT_SEARCH_URL=https://reddit-scraper2.p.rapidapi.com/search_posts
17-
LINKEDIN_SEARCH_URL=https://linkedin-data-api.p.rapidapi.com/search-posts
18-
WEATHER_URL=https://api.weatherapi.com/v1/current.json
19-
ETH_RPC=https://ethereum-rpc.publicnode.com
20-
GOLDRUSH_URL=https://api.covalenthq.com
21-
EXA_URL=https://api.exa.ai
22-
PERPLEXITY_URL=https://api.perplexity.ai
23-
TAVILY_URL=https://api.tavily.com
24-
25-
SECRET_KEY=
26-
27-
#llm
28-
# +-------------+------------------------------------------------+
29-
# | Provider | Model |
30-
# +-------------+------------------------------------------------+
31-
# | openai | gpt4o-mini |
32-
# | google | gemini-2.0-flash |
33-
# | together | deepseek-ai/DeepSeek-R1-Distill-Llama-70B-free |
34-
# | ollama | llama3.3 |
35-
# | groq | llama-3.3-70b-versatile |
36-
# | firework | accounts/fireworks/models/firefunction-v2 |
37-
# | huggingface | meta-llama/Llama-3.3-70B-Instruct |
38-
# +-------------+------------------------------------------------+
39-
40-
LLM_SERVICE=openai
41-
LLM_MODEL=gpt-4o-mini
42-
LLM_API_KEY=
43-
44-
OLLAMA_HOST=
45-
OLLAMA_MODELS=
12+
#------------------------
13+
# LOGGING
14+
#------------------------
15+
app_name=pattern-core
16+
log_file_path=api_logs
17+
log_backup_count=5
18+
log_max_bytes=5242880 # 5 * 1024 * 1024
19+
20+
#------------------------
21+
# SENTRY (Optional)
22+
#------------------------
23+
SENTRY_DSN=

api/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dist/
1515

1616
# Log files
1717
*.log
18+
/api_logs
1819

1920
# Package files
2021
*.jar

api/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ EXPOSE 8000
1616

1717
ENV MODULE_NAME="src.main"
1818

19-
CMD ["sh", "-c", "uvicorn $MODULE_NAME:app --host 0.0.0.0"]
19+
CMD ["sh", "-c", "make watch prod"]

api/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
watch:
2-
python3 scripts/create_qdrant_collection.py
32
python3 scripts/create_postgres_database.py
43
python3 -m uvicorn src.main:app --host 0.0.0.0 --reload
54

65
prod:
7-
python3 scripts/create_qdrant_collection.py
86
python3 scripts/create_postgres_database.py
97
python3 -m uvicorn src.main:app --host 0.0.0.0

api/config.json.sample

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"services": [
3+
{
4+
"name": "etherscan",
5+
"url": "https://api.etherscan.io/v2/api",
6+
"api_key": ""
7+
},
8+
{
9+
"name": "goldrush",
10+
"url": "https://api.covalenthq.com",
11+
"api_key": ""
12+
},
13+
{
14+
"name": "exa",
15+
"url": "https://api.exa.ai",
16+
"api_key": ""
17+
},
18+
{
19+
"name": "perplexity",
20+
"url": "https://api.perplexity.ai",
21+
"api_key": ""
22+
},
23+
{
24+
"name": "tavily",
25+
"url": "https://api.tavily.com",
26+
"api_key": ""
27+
}
28+
],
29+
"llm": {
30+
"provider": "openai",
31+
"model": "gpt-4o-mini",
32+
"api_key": "",
33+
"extra_params": {
34+
"host": "",
35+
"models": ""
36+
}
37+
},
38+
"agents": [
39+
"etherscan",
40+
"goldrush"
41+
]
42+
}

api/docker-compose.yml

-25
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
version: "3.9"
22

33
services:
4-
qdrant:
5-
image: qdrant/qdrant:v1.11.2
6-
restart: always
7-
volumes:
8-
- /root/qdrant:/qdrant/storage
9-
networks:
10-
- pattern_core_network
11-
ports:
12-
- 6333:6333
134

145
postgres:
156
image: postgres:15.7-alpine
@@ -25,21 +16,6 @@ services:
2516
ports:
2617
- "5432:5432"
2718

28-
minio:
29-
image: minio/minio:RELEASE.2024-10-13T13-34-11Z
30-
restart: always
31-
command: server /data --console-address ":9001"
32-
environment:
33-
MINIO_ROOT_USER: ${AWS_ACCESS_KEY}
34-
MINIO_ROOT_PASSWORD: ${AWS_SECRET_KEY}
35-
volumes:
36-
- minio_data:/data
37-
ports:
38-
- "9000:9000"
39-
- "9001:9001"
40-
networks:
41-
- pattern_core_network
42-
4319
api:
4420
build: .
4521
restart: always
@@ -68,7 +44,6 @@ services:
6844

6945
volumes:
7046
pg_data:
71-
minio_data:
7247

7348
networks:
7449
pattern_core_network:

api/hello_copy/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from fastapi import APIRouter
2+
3+
from src.auth.routers import auth_router
4+
from src.user.routers import user_router
5+
from src.agent.routers import agent_router
6+
from src.project.routers import project_router
7+
from src.workspace.routers import workspace_router
8+
from src.conversation.routers import playground_conversation_router
9+
10+
api_router = APIRouter()
11+
api_router.include_router(auth_router.router, tags=["Auth"])
12+
api_router.include_router(user_router.router, tags=["User"])
13+
api_router.include_router(workspace_router.router, tags=["Workspace"])
14+
api_router.include_router(project_router.router, tags=["Project"])
15+
api_router.include_router(agent_router.router, tags=["Agent"])
16+
api_router.include_router(
17+
playground_conversation_router.router, tags=["Conversation"])

api/hello_copy/main.py

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import os
2+
import sentry_sdk
3+
4+
from dotenv import load_dotenv
5+
from fastapi.responses import JSONResponse
6+
from fastapi.openapi.utils import get_openapi
7+
from scalar_fastapi.scalar_fastapi import Layout
8+
from fastapi.middleware.cors import CORSMiddleware
9+
from scalar_fastapi import get_scalar_api_reference
10+
from fastapi import FastAPI, Request, HTTPException, status
11+
12+
from src import api_router
13+
from src.db.models import init_db
14+
from src.share.logging import Logging
15+
16+
load_dotenv()
17+
_logger = Logging().get_logger()
18+
19+
if os.environ.get("SENTRY_DSN"):
20+
# Initialize Sentry with your DSN
21+
sentry_sdk.init(
22+
dsn=os.environ.get("SENTRY_DSN"),
23+
# Add data like request headers and IP for users,
24+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
25+
send_default_pii=True,
26+
# Set traces_sample_rate to 1.0 to capture 100%
27+
# of transactions for tracing.
28+
traces_sample_rate=1.0,
29+
_experiments={
30+
# Set continuous_profiling_auto_start to True
31+
# to automatically start the profiler on when
32+
# possible.
33+
"continuous_profiling_auto_start": True,
34+
},
35+
)
36+
37+
app = FastAPI()
38+
39+
app.add_middleware(
40+
CORSMiddleware,
41+
allow_origins=["*"],
42+
allow_credentials=True,
43+
allow_methods=["*"],
44+
allow_headers=["*"],
45+
)
46+
47+
48+
# Global handler for all exceptions
49+
@app.exception_handler(Exception)
50+
async def global_exception_handler(request: Request, exc: Exception):
51+
52+
# Send the exception to Sentry
53+
if os.environ.get("SENTRY_DSN"):
54+
sentry_sdk.capture_exception(exc)
55+
56+
# You can customize the response based on the exception type
57+
if isinstance(exc, HTTPException):
58+
_logger.error(
59+
f"[{request.method}] {request.url} - {exc.status_code} - {exc.detail}")
60+
return JSONResponse(
61+
status_code=exc.status_code,
62+
content={"detail": exc.detail},
63+
)
64+
65+
# For any other exceptions, return a 500 error
66+
return JSONResponse(
67+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
68+
content={"detail": "Internal server error"},
69+
)
70+
71+
72+
@app.get("/api-doc", include_in_schema=False)
73+
async def scalar_html():
74+
return get_scalar_api_reference(
75+
openapi_url=app.openapi_url,
76+
title="Pattern-Core API",
77+
hide_models=True,
78+
layout=Layout.MODERN
79+
)
80+
81+
82+
def custom_openapi():
83+
if app.openapi_schema:
84+
return app.openapi_schema
85+
86+
openapi_schema = get_openapi(
87+
title="Pattern-Core API",
88+
version="1.0.0",
89+
description="Pattern Core API Documentation for creating user, workspace, project, tool, and conversation.",
90+
routes=app.routes,
91+
)
92+
93+
app.openapi_schema = openapi_schema
94+
return app.openapi_schema
95+
96+
97+
app.openapi = custom_openapi
98+
99+
app.include_router(api_router)
100+
101+
init_db()

api/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ psycopg==3.2.3
1616
psycopg-pool==3.2.4
1717
psycopg2-binary==2.9.10
1818
newsapi-python==0.2.7
19-
cryptography==44.0.0
2019
beautifulsoup4==4.12.3
2120
dateparser==1.2.0
2221
web3==7.6.1
@@ -30,4 +29,5 @@ langchain-fireworks==0.2.7
3029
langchain-google-genai==2.0.7
3130
langchain-google-vertexai==2.0.9
3231
langchain-groq==0.2.4
33-
langchain-huggingface==0.1.2
32+
langchain-huggingface==0.1.2
33+
sentry-sdk==2.22.0

api/scripts/create_qdrant_collection.py

-29
This file was deleted.

api/src/__init__.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
from src.auth.routers import auth_router
44
from src.user.routers import user_router
5-
from src.task.routers import task_router
6-
from src.tool.routers import tool_router
75
from src.agent.routers import agent_router
86
from src.project.routers import project_router
9-
from src.agent.routers import tool_admin_router
107
from src.workspace.routers import workspace_router
118
from src.conversation.routers import playground_conversation_router
129

@@ -15,11 +12,6 @@
1512
api_router.include_router(user_router.router, tags=["User"])
1613
api_router.include_router(workspace_router.router, tags=["Workspace"])
1714
api_router.include_router(project_router.router, tags=["Project"])
18-
# api_router.include_router(task_router.router, tags=["Task"])
1915
api_router.include_router(agent_router.router, tags=["Agent"])
20-
api_router.include_router(tool_router.router, tags=["Tool"])
2116
api_router.include_router(
22-
playground_conversation_router.router, tags=["Conversation"])
23-
24-
# Admin
25-
api_router.include_router(tool_admin_router.router, tags=["Admin | Tool"])
17+
playground_conversation_router.router, tags=["Conversation"])

api/src/agent/enum/agent_action_enum.py

-7
This file was deleted.

0 commit comments

Comments
 (0)