Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create humans personas #1093

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions memgpt/server/rest_api/humans/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from functools import partial
from typing import List

from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, Body
from pydantic import BaseModel, Field

from memgpt.models.pydantic_models import HumanModel
from memgpt.server.rest_api.auth_token import get_current_user
from memgpt.server.rest_api.interface import QueuingInterface
from memgpt.server.server import SyncServer
from memgpt.models.pydantic_models import HumanModel

router = APIRouter()

Expand All @@ -17,6 +17,11 @@ class ListHumansResponse(BaseModel):
humans: List[HumanModel] = Field(..., description="List of human configurations.")


class CreateHumanRequest(BaseModel):
text: str = Field(..., description="The human text.")
name: str = Field(..., description="The name of the human.")


def setup_humans_index_router(server: SyncServer, interface: QueuingInterface, password: str):
get_current_user_with_server = partial(partial(get_current_user, server), password)

Expand All @@ -29,4 +34,14 @@ async def list_humans(
humans = server.ms.list_humans(user_id=user_id)
return ListHumansResponse(humans=humans)

@router.post("/humans", tags=["humans"], response_model=HumanModel)
async def create_persona(
request: CreateHumanRequest = Body(...),
user_id: uuid.UUID = Depends(get_current_user_with_server),
):
interface.clear()
new_human = HumanModel(text=request.text, name=request.name, user_id=user_id)
server.ms.add_human(new_human)
return new_human

return router
19 changes: 17 additions & 2 deletions memgpt/server/rest_api/personas/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from functools import partial
from typing import List

from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, Body
from pydantic import BaseModel, Field

from memgpt.models.pydantic_models import PersonaModel
from memgpt.server.rest_api.auth_token import get_current_user
from memgpt.server.rest_api.interface import QueuingInterface
from memgpt.server.server import SyncServer
from memgpt.models.pydantic_models import PersonaModel

router = APIRouter()

Expand All @@ -17,6 +17,11 @@ class ListPersonasResponse(BaseModel):
personas: List[PersonaModel] = Field(..., description="List of persona configurations.")


class CreatePersonaRequest(BaseModel):
text: str = Field(..., description="The persona text.")
name: str = Field(..., description="The name of the persona.")


def setup_personas_index_router(server: SyncServer, interface: QueuingInterface, password: str):
get_current_user_with_server = partial(partial(get_current_user, server), password)

Expand All @@ -30,4 +35,14 @@ async def list_personas(
personas = server.ms.list_personas(user_id=user_id)
return ListPersonasResponse(personas=personas)

@router.post("/personas", tags=["personas"], response_model=PersonaModel)
async def create_persona(
request: CreatePersonaRequest = Body(...),
user_id: uuid.UUID = Depends(get_current_user_with_server),
):
interface.clear()
new_persona = PersonaModel(text=request.text, name=request.name, user_id=user_id)
server.ms.add_persona(new_persona)
return new_persona

return router
Loading