MCPcopy Create free account
hub / github.com/HKUDS/DeepTutor / chat

Function chat

deeptutor_cli/chat.py:42–76  ·  view source on GitHub ↗

Enter interactive chat REPL. Use `deeptutor run` for single-turn execution.

(
        ctx: typer.Context,
        session: str | None = typer.Option(None, "--session", help="Resume an existing session."),
        tool: list[str] = typer.Option([], "--tool", "-t", help="Pre-enable tool(s)."),
        capability: str = typer.Option("chat", "--capability", "-c", help="Initial capability."),
        kb: list[str] = typer.Option([], "--kb", help="Pre-attach knowledge base(s)."),
        notebook_ref: list[str] = typer.Option([], "--notebook-ref", help="Notebook references."),
        history_ref: list[str] = typer.Option([], "--history-ref", help="Referenced session ids."),
        language: str = typer.Option("en", "--language", "-l", help="Response language."),
        config: list[str] = typer.Option([], "--config", help="Initial config key=value."),
        config_json: str | None = typer.Option(
            None, "--config-json", help="Initial config as JSON."
        ),
    )

Source from the content-addressed store, hash-verified

40def register(app: typer.Typer) -> None:
41 @app.callback(invoke_without_command=True)
42 def chat(
43 ctx: typer.Context,
44 session: str | None = typer.Option(None, "--session", help="Resume an existing session."),
45 tool: list[str] = typer.Option([], "--tool", "-t", help="Pre-enable tool(s)."),
46 capability: str = typer.Option("chat", "--capability", "-c", help="Initial capability."),
47 kb: list[str] = typer.Option([], "--kb", help="Pre-attach knowledge base(s)."),
48 notebook_ref: list[str] = typer.Option([], "--notebook-ref", help="Notebook references."),
49 history_ref: list[str] = typer.Option([], "--history-ref", help="Referenced session ids."),
50 language: str = typer.Option("en", "--language", "-l", help="Response language."),
51 config: list[str] = typer.Option([], "--config", help="Initial config key=value."),
52 config_json: str | None = typer.Option(
53 None, "--config-json", help="Initial config as JSON."
54 ),
55 ) -> None:
56 """Enter interactive chat REPL. Use `deeptutor run` for single-turn execution."""
57 if ctx.invoked_subcommand is not None:
58 return
59
60 try:
61 initial_config = parse_json_object(config_json)
62 initial_config.update(parse_config_items(config))
63 except ValueError as exc:
64 raise typer.BadParameter(str(exc)) from exc
65
66 state = ChatState(
67 session_id=session,
68 capability=capability,
69 tools=list(tool),
70 knowledge_bases=list(kb),
71 language=language,
72 notebook_references=_parse_notebook_refs(notebook_ref),
73 history_references=[item.strip() for item in history_ref if item.strip()],
74 config=initial_config,
75 )
76 maybe_run(_chat_repl(state))
77
78
79async def _chat_repl(state: ChatState) -> None:

Callers

nothing calls this directly

Calls 8

parse_json_objectFunction · 0.85
parse_config_itemsFunction · 0.85
_parse_notebook_refsFunction · 0.85
maybe_runFunction · 0.85
_chat_replFunction · 0.85
ChatStateClass · 0.70
strFunction · 0.50
updateMethod · 0.45

Tested by

no test coverage detected