Skip to content

Commit

Permalink
Bring back codelangchain (#944)
Browse files Browse the repository at this point in the history
* move to sandboxes, get running again

* rework as a Python agent

* Refactor to focus on sandboxes

* text updates

* minor text fixes

* fix sample commands, rename, text fixes for langserve

---------

Co-authored-by: Peyton Walters <[email protected]>
  • Loading branch information
charlesfrye and pawalt authored Nov 1, 2024
1 parent 87237d0 commit 418dcc5
Show file tree
Hide file tree
Showing 13 changed files with 514 additions and 292 deletions.
63 changes: 0 additions & 63 deletions 06_gpu_and_ml/langchains/codelangchain/agent.py

This file was deleted.

61 changes: 0 additions & 61 deletions 06_gpu_and_ml/langchains/codelangchain/app.py

This file was deleted.

56 changes: 0 additions & 56 deletions 06_gpu_and_ml/langchains/codelangchain/common.py

This file was deleted.

33 changes: 0 additions & 33 deletions 06_gpu_and_ml/langchains/codelangchain/sandbox.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
This example deploys a "code agent": a language model that can write and execute
code in a flexible control flow aimed at completing a task or goal.

The agent is designed to help write programs in the LangChain Expression
Language (LCEL). And, naturally, it is implemented in LangChain, using the
LangGraph library to structure the agent and the LangServe framework to turn it
into a FastAPI app.
It is implemented in LangChain, using the LangGraph library to structure the agent
and the LangServe framework to turn it into a FastAPI app.

We use Modal to turn that app into a web endpoint. We also use Modal to
"sandbox" the agent's code execution, so that it can't accidentally (or when
Expand All @@ -21,19 +19,19 @@ the project's context and implementation. Check it out if you're curious!
To run this app, you need to `pip install modal` and then create the following
[secrets](https://modal.com/docs/guide/secrets):

- `my-openai-secret` with an OpenAI API key, so that we can query OpenAI's
- `openai-secret` with an OpenAI API key, so that we can query OpenAI's
models to power the agent,
- and `my-langsmith-secret` with a LangSmith API key, so that we can monitor the
agent's behavior with LangSmith.

Head to the
[secret creation dashboard](https://modal.com/charles-modal-labs/secrets/create)
[secret creation dashboard](https://modal.com/secrets/)
and follow the instructions for each secret type.

Then, you can deploy the app with:

```bash
modal deploy app.py
modal deploy codelangchain.py
```

Navigate to the URL that appears in the output and you'll be dropped into an
Expand All @@ -44,23 +42,20 @@ You can also navigate to the `/docs` path to see OpenAPI/Swagger docs, for
everything you'd need to see how to incorporate the agent into your downstream
applications via API requests.

When developing the app, use `modal serve app.py` to get a hot-reloading server.
When developing the app, use `modal serve codelangchain.py` to get a hot-reloading server.

## Repo structure

The web application is defined in `app.py`.
The web application is defined in `codelangchain.py`.

It wraps the `agent.py` module, which contains the LangChain agent's definition.
To test the agent in isolation, run `modal run agent.py` in the terminal and
provide a `--question` about LCEL as input.
provide a `--question` about Python programming as input.

Because the agent is a graph, it is defined by specifying nodes and edges, which
are found in `nodes.py` and `edges.py`, respectively.

The logic for spinning up a `modal.Sandbox` to contain the agent's actions is in
`sandbox.py`.

The retrieval logic is very simple: all of the data from the LCEL docs is
The retrieval logic is very simple: all of the data from the relevant docs is
retrieved and put at the beginning of the language model's prompt. You can find
it in `retrieval.py`.

Expand Down
File renamed without changes.
Loading

0 comments on commit 418dcc5

Please sign in to comment.