Add a person/human
(
option: str, # [human, persona]
name: Annotated[str, typer.Option(help="Name of human/persona")],
text: Annotated[Optional[str], typer.Option(help="Text of human/persona")] = None,
filename: Annotated[Optional[str], typer.Option("-f", help="Specify filename")] = None,
)
| 153 | |
| 154 | @app.command() |
| 155 | def add( |
| 156 | option: str, # [human, persona] |
| 157 | name: Annotated[str, typer.Option(help="Name of human/persona")], |
| 158 | text: Annotated[Optional[str], typer.Option(help="Text of human/persona")] = None, |
| 159 | filename: Annotated[Optional[str], typer.Option("-f", help="Specify filename")] = None, |
| 160 | ): |
| 161 | """Add a person/human""" |
| 162 | from letta.client.client import create_client |
| 163 | |
| 164 | client = create_client(base_url=os.getenv("MEMGPT_BASE_URL"), token=os.getenv("MEMGPT_SERVER_PASS")) |
| 165 | if filename: # read from file |
| 166 | assert text is None, "Cannot specify both text and filename" |
| 167 | with open(filename, "r", encoding="utf-8") as f: |
| 168 | text = f.read() |
| 169 | else: |
| 170 | assert text is not None, "Must specify either text or filename" |
| 171 | if option == "persona": |
| 172 | persona_id = client.get_persona_id(name) |
| 173 | if persona_id: |
| 174 | client.get_persona(persona_id) |
| 175 | # config if user wants to overwrite |
| 176 | if not questionary.confirm(f"Persona {name} already exists. Overwrite?").ask(): |
| 177 | return |
| 178 | client.update_persona(persona_id, text=text) |
| 179 | else: |
| 180 | client.create_persona(name=name, text=text) |
| 181 | |
| 182 | elif option == "human": |
| 183 | human_id = client.get_human_id(name) |
| 184 | if human_id: |
| 185 | human = client.get_human(human_id) |
| 186 | # config if user wants to overwrite |
| 187 | if not questionary.confirm(f"Human {name} already exists. Overwrite?").ask(): |
| 188 | return |
| 189 | client.update_human(human_id, text=text) |
| 190 | else: |
| 191 | human = client.create_human(name=name, text=text) |
| 192 | else: |
| 193 | raise ValueError(f"Unknown kind {option}") |
| 194 | |
| 195 | |
| 196 | @app.command() |
nothing calls this directly
no test coverage detected