Skip to content

Commit 360c91d

Browse files
Merge pull request #140 from PinJinx/main
Depreciated code and warning fix
2 parents 452a278 + a97df7a commit 360c91d

File tree

10 files changed

+104
-99
lines changed

10 files changed

+104
-99
lines changed

backend/app/agents/devrel/github/github_toolkit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
2-
import os
32
import json
43
import re
4+
import config
55
from typing import Dict, Any
66
from langchain_google_genai import ChatGoogleGenerativeAI
77
from langchain_core.messages import HumanMessage
@@ -14,7 +14,7 @@
1414

1515
logger = logging.getLogger(__name__)
1616

17-
DEFAULT_ORG = os.getenv("GITHUB_ORG")
17+
DEFAULT_ORG = config.GITHUB_ORG
1818

1919

2020
def normalize_org(org_from_user: str = None) -> str:

backend/app/agents/devrel/github/services/github_mcp_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import logging
2-
import os
32
from typing import Dict, Any, Optional, List, Union
43
import aiohttp
54
import asyncio
5+
import config
66

77
logger = logging.getLogger(__name__)
88

@@ -13,7 +13,7 @@ def __init__(self, mcp_server_url: str = "http://localhost:8001"):
1313
self.mcp_server_url = mcp_server_url
1414
self.session: Optional[aiohttp.ClientSession] = None
1515
# Default org pulled from environment
16-
self.org = os.getenv("GITHUB_ORG", "Aossie-org")
16+
self.org = config.GITHUB_ORG
1717

1818
async def __aenter__(self):
1919
# Async context manager entry

backend/app/agents/devrel/github/services/github_mcp_server.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
11
import os
22
import logging
33
import asyncio
4-
from dotenv import load_dotenv, find_dotenv
4+
import config
55
from fastapi import FastAPI, HTTPException
66
from pydantic import BaseModel
77
from .github_mcp_service import GitHubMCPService
88
from typing import Optional
99

10-
dotenv_path = find_dotenv(usecwd=True)
11-
if dotenv_path:
12-
load_dotenv(dotenv_path=dotenv_path)
13-
else:
14-
load_dotenv()
1510

1611
logging.basicConfig(level=logging.INFO)
1712
logger = logging.getLogger(__name__)
1813

1914
app = FastAPI(title="GitHub MCP Server", version="1.0.0")
2015

2116
# Load env vars
22-
GITHUB_ORG = os.getenv("GITHUB_ORG")
17+
GITHUB_ORG = config.GITHUB_ORG
2318
if not GITHUB_ORG:
2419
logger.warning("GITHUB_ORG not set in .env — defaulting to manual owner input")
2520

2621
github_service: Optional[GitHubMCPService] = None
2722
try:
28-
token = os.getenv("GITHUB_TOKEN") or os.getenv("GH_TOKEN")
23+
token = config.GITHUB_TOKEN
2924
if not token:
3025
logger.warning("GITHUB_TOKEN/GH_TOKEN not set; GitHub API calls may be rate-limited or fail.")
3126
github_service = GitHubMCPService(token=token)

backend/app/agents/devrel/github/services/github_mcp_service.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
import requests
33
import asyncio
44
from typing import Optional
5-
from dotenv import load_dotenv, find_dotenv
6-
7-
dotenv_path = find_dotenv(usecwd=True)
8-
if dotenv_path:
9-
load_dotenv(dotenv_path=dotenv_path)
10-
else:
11-
load_dotenv()
5+
import config
126

137
class GitHubMCPService:
148
def __init__(self, token: str = None):
15-
self.token = token or os.getenv("GITHUB_TOKEN")
9+
self.token = token or config.GITHUB_TOKEN
1610
if not self.token:
1711
raise ValueError("GitHub token required; export as GITHUB_TOKEN or place in backend/.env file")
1812
self.base_url = "https://api.github.com"
@@ -110,7 +104,7 @@ def _headers(self):
110104

111105

112106
def _get_service(token: Optional[str] = None) -> GitHubMCPService:
113-
return GitHubMCPService(token=token or os.getenv("GITHUB_TOKEN"))
107+
return GitHubMCPService(token=token or config.GITHUB_TOKEN)
114108

115109
async def get_org_repositories(org: str):
116110
try:

backend/app/agents/devrel/github/tools/github_support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import os
1+
import config
22
import re
33
import logging
44
from typing import Optional
55
from app.agents.devrel.github.services import github_mcp_service
66

77
logger = logging.getLogger(__name__)
88

9-
DEFAULT_ORG = os.getenv("GITHUB_ORG", "Aossie-org")
9+
DEFAULT_ORG = config.GITHUB_ORG
1010

1111
GH_URL_RE = re.compile(
1212
r'(?:https?://|git@)github\.com[/:]'

backend/app/agents/state.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Dict, Any, List, Optional, Annotated
2-
from pydantic import BaseModel, Field
2+
from pydantic import BaseModel, Field, ConfigDict
33
from datetime import datetime
44
from operator import add
55

@@ -69,5 +69,6 @@ class AgentState(BaseModel):
6969
# Response
7070
final_response: Optional[str] = None
7171

72-
class Config:
72+
model_config = ConfigDict(
7373
arbitrary_types_allowed = True
74+
)

backend/app/core/config/settings.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pydantic_settings import BaseSettings
22
from dotenv import load_dotenv
3-
from pydantic import field_validator
3+
from pydantic import field_validator,ConfigDict
44
from typing import Optional
55

66
load_dotenv()
@@ -46,9 +46,10 @@ def _not_empty(cls, v, field):
4646
raise ValueError(f"{field.name} must be set")
4747
return v
4848

49-
class Config:
50-
env_file = ".env"
51-
extra = "ignore" # to prevent errors from extra env variables
49+
model_config = ConfigDict(
50+
env_file = ".env",
51+
extra = "ignore"
52+
) # to prevent errors from extra env variables
5253

5354

5455
settings = Settings()
Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic import BaseModel, Field
1+
from pydantic import BaseModel, Field, ConfigDict
22
from typing import List, Optional
33
from datetime import datetime
44

@@ -63,67 +63,66 @@ class WeaviateUserProfile(BaseModel):
6363
last_updated: datetime = Field(default_factory=datetime.now,
6464
description="The date and time the profile was last updated.")
6565

66-
class Config:
67-
"""
68-
Pydantic model configuration.
69-
"""
70-
orm_mode = True
71-
schema_extra = {
72-
"example": {
73-
"user_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
74-
"github_username": "jane-dev",
75-
"display_name": "Jane Developer",
76-
"bio": "Creator of innovative open-source tools. Full-stack developer with a passion for Rust and WebAssembly.",
77-
"location": "Berlin, Germany",
78-
"repositories": [
79-
{
80-
"name": "rust-web-framework",
81-
"description": "A high-performance web framework for Rust.",
82-
"languages": ["Rust", "TOML"],
83-
"topics": ["rust", "webdev", "performance", "framework"],
84-
"stars": 2500,
85-
"forks": 400
86-
},
87-
{
88-
"name": "data-viz-lib",
89-
"description": "A declarative data visualization library for JavaScript.",
90-
"languages": ["JavaScript", "TypeScript"],
91-
"topics": ["data-visualization", "d3", "charts"],
92-
"stars": 1200,
93-
"forks": 150
94-
}
95-
],
96-
"pull_requests": [
97-
{
98-
"title": "Add async support for database connections",
99-
"body": "This PR adds comprehensive async support for database connections, improving performance by 40%...",
100-
"state": "closed",
101-
"repository": "microsoft/vscode",
102-
"created_at": "2024-01-15T10:30:00Z",
103-
"closed_at": "2024-01-20T14:20:00Z",
104-
"merged_at": "2024-01-20T14:20:00Z",
105-
"labels": ["enhancement", "database", "performance"],
106-
"url": "https://github.com/microsoft/vscode/pull/12345",
107-
},
108-
{
109-
"title": "Fix memory leak in WebAssembly module",
110-
"body": "Fixes a critical memory leak that was causing crashes in production environments...",
111-
"state": "open",
112-
"repository": "facebook/react",
113-
"created_at": "2024-02-01T09:15:00Z",
114-
"closed_at": None,
115-
"merged_at": None,
116-
"labels": ["bug", "wasm", "critical"],
117-
"url": "https://github.com/facebook/react/pull/67890",
118-
}
119-
],
120-
"languages": ["Rust", "JavaScript", "TypeScript", "TOML"],
121-
"topics": ["rust", "webdev", "performance", "framework", "data-visualization", "d3", "charts"],
122-
"followers_count": 1800,
123-
"following_count": 250,
124-
"total_stars_received": 3700,
125-
"total_forks": 550,
126-
"profile_text_for_embedding": "Jane Developer, Creator of innovative open-source tools. Full-stack developer with a passion for Rust and WebAssembly. Repositories: rust-web-framework, A high-performance web framework for Rust. data-viz-lib, A declarative data visualization library for JavaScript. Languages: Rust, JavaScript, TypeScript. Topics: rust, webdev, performance, data-visualization.",
127-
"last_updated": "2025-06-23T12:21:00Z"
128-
}
66+
model_config = ConfigDict(
67+
from_attributes = True,
68+
json_schema_extra = {
69+
"example": {
70+
"user_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
71+
"github_username": "jane-dev",
72+
"display_name": "Jane Developer",
73+
"bio": "Creator of innovative open-source tools. Full-stack developer with a passion for Rust and WebAssembly.",
74+
"location": "Berlin, Germany",
75+
"repositories": [
76+
{
77+
"name": "rust-web-framework",
78+
"description": "A high-performance web framework for Rust.",
79+
"languages": ["Rust", "TOML"],
80+
"topics": ["rust", "webdev", "performance", "framework"],
81+
"stars": 2500,
82+
"forks": 400
83+
},
84+
{
85+
"name": "data-viz-lib",
86+
"description": "A declarative data visualization library for JavaScript.",
87+
"languages": ["JavaScript", "TypeScript"],
88+
"topics": ["data-visualization", "d3", "charts"],
89+
"stars": 1200,
90+
"forks": 150
91+
}
92+
],
93+
"pull_requests": [
94+
{
95+
"title": "Add async support for database connections",
96+
"body": "This PR adds comprehensive async support for database connections, improving performance by 40%...",
97+
"state": "closed",
98+
"repository": "microsoft/vscode",
99+
"created_at": "2024-01-15T10:30:00Z",
100+
"closed_at": "2024-01-20T14:20:00Z",
101+
"merged_at": "2024-01-20T14:20:00Z",
102+
"labels": ["enhancement", "database", "performance"],
103+
"url": "https://github.com/microsoft/vscode/pull/12345",
104+
},
105+
{
106+
"title": "Fix memory leak in WebAssembly module",
107+
"body": "Fixes a critical memory leak that was causing crashes in production environments...",
108+
"state": "open",
109+
"repository": "facebook/react",
110+
"created_at": "2024-02-01T09:15:00Z",
111+
"closed_at": None,
112+
"merged_at": None,
113+
"labels": ["bug", "wasm", "critical"],
114+
"url": "https://github.com/facebook/react/pull/67890",
115+
}
116+
],
117+
"languages": ["Rust", "JavaScript", "TypeScript", "TOML"],
118+
"topics": ["rust", "webdev", "performance", "framework", "data-visualization", "d3", "charts"],
119+
"followers_count": 1800,
120+
"following_count": 250,
121+
"total_stars_received": 3700,
122+
"total_forks": 550,
123+
"profile_text_for_embedding": "Jane Developer, Creator of innovative open-source tools. Full-stack developer with a passion for Rust and WebAssembly. Repositories: rust-web-framework, A high-performance web framework for Rust. data-viz-lib, A declarative data visualization library for JavaScript. Languages: Rust, JavaScript, TypeScript. Topics: rust, webdev, performance, data-visualization.",
124+
"last_updated": "2025-06-23T12:21:00Z"
129125
}
126+
}
127+
128+
)

backend/app/services/embedding_service/service.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import logging
2-
import os
2+
import config
33
from typing import List, Dict, Any, Optional
44
import torch
55
from pydantic import BaseModel
6-
from dotenv import load_dotenv
76
from sentence_transformers import SentenceTransformer
87
from langchain_google_genai import ChatGoogleGenerativeAI
98
from langchain_core.messages import HumanMessage
109
from app.core.config import settings
1110
from app.models.database.weaviate import WeaviateUserProfile
1211
from app.services.embedding_service.profile_summarization.prompts.summarization_prompt import PROFILE_SUMMARIZATION_PROMPT
1312

14-
load_dotenv()
1513

16-
MODEL_NAME = os.getenv("EMBEDDING_MODEL", "BAAI/bge-small-en-v1.5")
17-
MAX_BATCH_SIZE = int(os.getenv("EMBEDDING_MAX_BATCH_SIZE", "32"))
18-
EMBEDDING_DEVICE = os.getenv("EMBEDDING_DEVICE", "cpu")
14+
MODEL_NAME = config.MODEL_NAME
15+
MAX_BATCH_SIZE = config.MAX_BATCH_SIZE
16+
EMBEDDING_DEVICE = config.EMBEDDING_DEVICE
17+
1918

2019
logger = logging.getLogger(__name__)
2120

backend/config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from dotenv import load_dotenv, find_dotenv
2+
import os
3+
4+
5+
dotenv_path = find_dotenv(usecwd=True)
6+
if dotenv_path:
7+
load_dotenv(dotenv_path=dotenv_path)
8+
else:
9+
load_dotenv()
10+
11+
GITHUB_ORG = os.getenv("GITHUB_ORG", "Aossie-org")
12+
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") or os.getenv("GH_TOKEN")
13+
14+
MODEL_NAME = os.getenv("EMBEDDING_MODEL", "BAAI/bge-small-en-v1.5")
15+
MAX_BATCH_SIZE = int(os.getenv("EMBEDDING_MAX_BATCH_SIZE", "32"))
16+
EMBEDDING_DEVICE = os.getenv("EMBEDDING_DEVICE", "cpu")

0 commit comments

Comments
 (0)