update_260202-3
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -118,4 +118,51 @@ async def init_db():
|
|||||||
)
|
)
|
||||||
session.add(gemini_config)
|
session.add(gemini_config)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
print("✅ Default Gemini AI configuration created")
|
print("✅ Default Gemini AI configuration created")
|
||||||
|
|
||||||
|
# 4. 检查并初始化 AI Roles
|
||||||
|
ai_roles_data = [
|
||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"name": 'Reflective Assistant',
|
||||||
|
"description": 'Helps you dive deep into your thoughts and feelings through meaningful reflection.',
|
||||||
|
"systemPrompt": 'You are a helpful journal assistant. Help the user reflect on their thoughts and feelings.',
|
||||||
|
"icon": 'journal-outline',
|
||||||
|
"iconFamily": 'Ionicons',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": 'Creative Spark',
|
||||||
|
"description": 'A partner for brainstorming, creative writing, and exploring new ideas.',
|
||||||
|
"systemPrompt": 'You are a creative brainstorming partner. Help the user explore new ideas, write stories, or look at things from a fresh perspective.',
|
||||||
|
"icon": 'bulb-outline',
|
||||||
|
"iconFamily": 'Ionicons',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": 'Action Planner',
|
||||||
|
"description": 'Focused on turning thoughts into actionable plans and organized goals.',
|
||||||
|
"systemPrompt": 'You are a productivity coach. Help the user break down their thoughts into actionable steps and clear goals.',
|
||||||
|
"icon": 'list-outline',
|
||||||
|
"iconFamily": 'Ionicons',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": 'Empathetic Guide',
|
||||||
|
"description": 'Provides a safe, non-judgmental space for emotional support and empathy.',
|
||||||
|
"systemPrompt": 'You are a supportive and empathetic friend. Listen to the user\'s concerns and provide emotional support without judgment.',
|
||||||
|
"icon": 'heart-outline',
|
||||||
|
"iconFamily": 'Ionicons',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
for role_data in ai_roles_data:
|
||||||
|
result = await session.execute(
|
||||||
|
select(models.AIRole).where(models.AIRole.id == role_data["id"])
|
||||||
|
)
|
||||||
|
if not result.scalars().first():
|
||||||
|
new_role = models.AIRole(**role_data)
|
||||||
|
session.add(new_role)
|
||||||
|
print(f"✅ AI Role '{role_data['name']}' created")
|
||||||
|
|
||||||
|
await session.commit()
|
||||||
48
app/main.py
48
app/main.py
@@ -99,9 +99,18 @@ async def get_my_assets(
|
|||||||
db: AsyncSession = Depends(database.get_db)
|
db: AsyncSession = Depends(database.get_db)
|
||||||
):
|
):
|
||||||
result = await db.execute(
|
result = await db.execute(
|
||||||
select(models.Asset).where(models.Asset.author_id == current_user.id)
|
select(models.Asset)
|
||||||
|
.options(selectinload(models.Asset.heir))
|
||||||
|
.where(models.Asset.author_id == current_user.id)
|
||||||
)
|
)
|
||||||
return result.scalars().all()
|
assets = result.scalars().all()
|
||||||
|
# Populate heir_email for the schema
|
||||||
|
for asset in assets:
|
||||||
|
if asset.heir:
|
||||||
|
asset.heir_email = asset.heir.email
|
||||||
|
else:
|
||||||
|
asset.heir_email = None
|
||||||
|
return assets
|
||||||
|
|
||||||
|
|
||||||
@app.post("/assets/create", response_model=schemas.AssetOut)
|
@app.post("/assets/create", response_model=schemas.AssetOut)
|
||||||
@@ -235,6 +244,30 @@ async def get_designated_assets(
|
|||||||
)
|
)
|
||||||
return result.scalars().all()
|
return result.scalars().all()
|
||||||
|
|
||||||
|
@app.post("/assets/delete")
|
||||||
|
async def delete_asset(
|
||||||
|
asset_del: schemas.AssetDelete,
|
||||||
|
current_user: models.User = Depends(auth.get_current_user),
|
||||||
|
db: AsyncSession = Depends(database.get_db)
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Delete an asset owned by the current user.
|
||||||
|
"""
|
||||||
|
result = await db.execute(
|
||||||
|
select(models.Asset).where(models.Asset.id == asset_del.asset_id)
|
||||||
|
)
|
||||||
|
asset = result.scalars().first()
|
||||||
|
|
||||||
|
if not asset:
|
||||||
|
raise HTTPException(status_code=404, detail="Asset not found")
|
||||||
|
|
||||||
|
if asset.author_id != current_user.id:
|
||||||
|
raise HTTPException(status_code=403, detail="Not authorized to delete this asset")
|
||||||
|
|
||||||
|
await db.delete(asset)
|
||||||
|
await db.commit()
|
||||||
|
return {"message": "Asset deleted successfully"}
|
||||||
|
|
||||||
@app.get("/users/search", response_model=List[schemas.UserOut])
|
@app.get("/users/search", response_model=List[schemas.UserOut])
|
||||||
async def search_users(
|
async def search_users(
|
||||||
query: str,
|
query: str,
|
||||||
@@ -416,6 +449,17 @@ async def ai_proxy(
|
|||||||
detail=f"An error occurred while requesting AI provider: {str(e)}"
|
detail=f"An error occurred while requesting AI provider: {str(e)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@app.get("/get_ai_roles", response_model=List[schemas.AIRoleOut])
|
||||||
|
async def get_ai_roles(
|
||||||
|
current_user: models.User = Depends(auth.get_current_user),
|
||||||
|
db: AsyncSession = Depends(database.get_db)
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Get all available AI roles for the logged-in user.
|
||||||
|
"""
|
||||||
|
result = await db.execute(select(models.AIRole).order_by(models.AIRole.id))
|
||||||
|
return result.scalars().all()
|
||||||
|
|
||||||
# 用于测试热加载
|
# 用于测试热加载
|
||||||
@app.post("/post1")
|
@app.post("/post1")
|
||||||
async def test1():
|
async def test1():
|
||||||
|
|||||||
@@ -84,4 +84,14 @@ class UserTokenUsage(Base):
|
|||||||
tokens_used = Column(Integer, default=0)
|
tokens_used = Column(Integer, default=0)
|
||||||
last_reset_at = Column(DateTime)
|
last_reset_at = Column(DateTime)
|
||||||
|
|
||||||
user = relationship("User", backref="token_usage", uselist=False)
|
user = relationship("User", backref="token_usage", uselist=False)
|
||||||
|
|
||||||
|
class AIRole(Base):
|
||||||
|
__tablename__ = "ai_roles"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
|
name = Column(String, index=True)
|
||||||
|
description = Column(Text)
|
||||||
|
systemPrompt = Column(Text)
|
||||||
|
icon = Column(String)
|
||||||
|
iconFamily = Column(String)
|
||||||
@@ -58,6 +58,8 @@ class AssetOut(AssetBase):
|
|||||||
content_outer_encrypted: str
|
content_outer_encrypted: str
|
||||||
created_at: Optional[datetime] = None
|
created_at: Optional[datetime] = None
|
||||||
updated_at: Optional[datetime] = None
|
updated_at: Optional[datetime] = None
|
||||||
|
heir_id: Optional[int] = None
|
||||||
|
heir_email: Optional[str] = None
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
class AssetClaim(BaseModel):
|
class AssetClaim(BaseModel):
|
||||||
@@ -72,6 +74,9 @@ class AssetAssign(BaseModel):
|
|||||||
asset_id: int
|
asset_id: int
|
||||||
heir_email: str
|
heir_email: str
|
||||||
|
|
||||||
|
class AssetDelete(BaseModel):
|
||||||
|
asset_id: int
|
||||||
|
|
||||||
class DeclareGuale(BaseModel):
|
class DeclareGuale(BaseModel):
|
||||||
username: str
|
username: str
|
||||||
|
|
||||||
@@ -105,4 +110,16 @@ class SubscriptionPlansBase(BaseModel):
|
|||||||
|
|
||||||
class SubscriptionPlansOut(SubscriptionPlansBase):
|
class SubscriptionPlansOut(SubscriptionPlansBase):
|
||||||
id: int
|
id: int
|
||||||
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
# AI Role Schemas
|
||||||
|
class AIRoleBase(BaseModel):
|
||||||
|
id: int
|
||||||
|
name: str
|
||||||
|
description: str
|
||||||
|
systemPrompt: str
|
||||||
|
icon: str
|
||||||
|
iconFamily: str
|
||||||
|
|
||||||
|
class AIRoleOut(AIRoleBase):
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
@@ -14,7 +14,8 @@ async def test_ai_proxy_integration():
|
|||||||
print(f"1. Registering user: {username}")
|
print(f"1. Registering user: {username}")
|
||||||
reg_res = await client.post("/register", json={
|
reg_res = await client.post("/register", json={
|
||||||
"username": username,
|
"username": username,
|
||||||
"password": "testpassword"
|
"password": "testpassword",
|
||||||
|
"email": f"user_{int(time.time())}@example.com"
|
||||||
})
|
})
|
||||||
if reg_res.status_code != 200:
|
if reg_res.status_code != 200:
|
||||||
print(f"Registration failed: {reg_res.text}")
|
print(f"Registration failed: {reg_res.text}")
|
||||||
@@ -22,7 +23,7 @@ async def test_ai_proxy_integration():
|
|||||||
|
|
||||||
# 2. Login to get token
|
# 2. Login to get token
|
||||||
print("2. Logging in...")
|
print("2. Logging in...")
|
||||||
login_res = await client.post("/token", json={
|
login_res = await client.post("/login", json={
|
||||||
"username": username,
|
"username": username,
|
||||||
"password": "testpassword"
|
"password": "testpassword"
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user