Skip to content

Commit

Permalink
feat: create humans personas (#1093)
Browse files Browse the repository at this point in the history
Co-authored-by: cpacker <[email protected]>
  • Loading branch information
goetzrobin and cpacker authored Mar 5, 2024
1 parent ccecea3 commit 23702f6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
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

0 comments on commit 23702f6

Please sign in to comment.