MCPcopy
hub / github.com/langchain-ai/langchain / add

Function add

libs/cli/langchain_cli/namespaces/app.py:132–286  ·  view source on GitHub ↗

Adds the specified template to the current LangServe app. e.g.: langchain app add extraction-openai-functions langchain app add git+ssh://git@github.com/efriis/simple-pirate.git

(
    dependencies: Annotated[
        Optional[List[str]], typer.Argument(help="The dependency to add")
    ] = None,
    *,
    api_path: Annotated[List[str], typer.Option(help="API paths to add")] = [],
    project_dir: Annotated[
        Optional[Path], typer.Option(help="The project directory")
    ] = None,
    repo: Annotated[
        List[str],
        typer.Option(help="Install templates from a specific github repo instead"),
    ] = [],
    branch: Annotated[
        List[str], typer.Option(help="Install templates from a specific branch")
    ] = [],
    pip: Annotated[
        bool,
        typer.Option(
            "--pip/--no-pip",
            help="Pip install the template(s) as editable dependencies",
            is_flag=True,
            prompt="Would you like to `pip install -e` the template(s)?",
        ),
    ],
)

Source from the content-addressed store, hash-verified

130
131@app_cli.command()
132def add(
133 dependencies: Annotated[
134 Optional[List[str]], typer.Argument(help="The dependency to add")
135 ] = None,
136 *,
137 api_path: Annotated[List[str], typer.Option(help="API paths to add")] = [],
138 project_dir: Annotated[
139 Optional[Path], typer.Option(help="The project directory")
140 ] = None,
141 repo: Annotated[
142 List[str],
143 typer.Option(help="Install templates from a specific github repo instead"),
144 ] = [],
145 branch: Annotated[
146 List[str], typer.Option(help="Install templates from a specific branch")
147 ] = [],
148 pip: Annotated[
149 bool,
150 typer.Option(
151 "--pip/--no-pip",
152 help="Pip install the template(s) as editable dependencies",
153 is_flag=True,
154 prompt="Would you like to `pip install -e` the template(s)?",
155 ),
156 ],
157):
158 """
159 Adds the specified template to the current LangServe app.
160
161 e.g.:
162 langchain app add extraction-openai-functions
163 langchain app add git+ssh://git@github.com/efriis/simple-pirate.git
164 """
165
166 parsed_deps = parse_dependencies(dependencies, repo, branch, api_path)
167
168 project_root = get_package_root(project_dir)
169
170 package_dir = project_root / "packages"
171
172 create_events(
173 [{"event": "serve add", "properties": dict(parsed_dep=d)} for d in parsed_deps]
174 )
175
176 # group by repo/ref
177 grouped: Dict[Tuple[str, Optional[str]], List[DependencySource]] = {}
178 for dep in parsed_deps:
179 key_tup = (dep["git"], dep["ref"])
180 lst = grouped.get(key_tup, [])
181 lst.append(dep)
182 grouped[key_tup] = lst
183
184 installed_destination_paths: List[Path] = []
185 installed_destination_names: List[str] = []
186 installed_exports: List[LangServeExport] = []
187
188 for (git, ref), group_deps in grouped.items():
189 if len(group_deps) == 1:

Callers 1

newFunction · 0.70

Calls 11

parse_dependenciesFunction · 0.90
get_package_rootFunction · 0.90
create_eventsFunction · 0.90
update_repoFunction · 0.90
get_langserve_exportFunction · 0.90
copy_repoFunction · 0.90
appendMethod · 0.80
getMethod · 0.45
existsMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected