Skip to content

Commit

Permalink
Readme rewrite (langchain-ai#12615)
Browse files Browse the repository at this point in the history
Co-authored-by: Lance Martin <lance@langchain.dev>
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
  • Loading branch information
3 people authored Oct 31, 2023
1 parent 00766c9 commit a1fae1f
Show file tree
Hide file tree
Showing 60 changed files with 2,638 additions and 644 deletions.
2 changes: 1 addition & 1 deletion libs/cli/langchain_cli/namespaces/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def new(
readme = destination_dir / "README.md"
readme_contents = readme.read_text()
readme.write_text(
readme_contents.replace("__package_name_last__", package_name).replace(
readme_contents.replace("__package_name__", package_name).replace(
"__app_route_code__", app_route_code
)
)
Expand Down
2 changes: 1 addition & 1 deletion libs/cli/langchain_cli/package_template/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# __package_name_last__
# __package_name__

TODO: What does this package do

Expand Down
68 changes: 67 additions & 1 deletion templates/anthropic-iterative-search/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,69 @@

# anthropic-iterative-search

Heavily inspired by [this notebook](https://github.com/anthropics/anthropic-cookbook/blob/main/long_context/wikipedia-search-cookbook.ipynb)
This template will create a virtual research assistant with the ability to search Wikipedia to find answers to your questions.

It is heavily inspired by [this notebook](https://github.com/anthropics/anthropic-cookbook/blob/main/long_context/wikipedia-search-cookbook.ipynb).

## Environment Setup

Set the `ANTHROPIC_API_KEY` environment variable to access the Anthropic models.

## Usage

To use this package, you should first have the LangChain CLI installed:

```shell
pip install -U "langchain-cli[serve]"
```

To create a new LangChain project and install this as the only package, you can do:

```shell
langchain app new my-app --package anthropic-iterative-search
```

If you want to add this to an existing project, you can just run:

```shell
langchain app add anthropic-iterative-search
```

And add the following code to your `server.py` file:
```python
from anthropic_iterative_search import chain as anthropic_iterative_search_chain

add_routes(app, anthropic_iterative_search_chain, path="/anthropic-iterative-search")
```

(Optional) Let's now configure LangSmith.
LangSmith will help us trace, monitor and debug LangChain applications.
LangSmith is currently in private beta, you can sign up [here](https://smith.langchain.com/).
If you don't have access, you can skip this section


```shell
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=<your-api-key>
export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

```shell
langchain serve
```

This will start the FastAPI app with a server is running locally at
[http://localhost:8000](http://localhost:8000)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
We can access the playground at [http://127.0.0.1:8000/anthropic-iterative-search/playground](http://127.0.0.1:8000/anthropic-iterative-search/playground)

We can access the template from code with:

```python
from langserve.client import RemoteRunnable

runnable = RemoteRunnable("http://localhost:8000/anthropic-iterative-search")
```
87 changes: 64 additions & 23 deletions templates/cassandra-entomology-rag/README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,86 @@
# RAG LangServe chain template

A basic chain template showing the RAG pattern using
a vector store on Astra DB / Apache Cassandra®.
# cassandra-entomology-rag

## Setup:
This template will perform RAG using Astra DB and Apache Cassandra®.

You need:
## Environment Setup

- an [Astra](https://astra.datastax.com) Vector Database (free tier is fine!). **You need a [Database Administrator token](https://awesome-astra.github.io/docs/pages/astra/create-token/#c-procedure)**, in particular the string starting with `AstraCS:...`;
- likewise, get your [Database ID](https://awesome-astra.github.io/docs/pages/astra/faq/#where-should-i-find-a-database-identifier) ready, you will have to enter it below;
- an **OpenAI API Key**. (More info [here](https://cassio.org/start_here/#llm-access), note that out-of-the-box this demo supports OpenAI unless you tinker with the code.)
For the setup, you will require:
- an [Astra](https://astra.datastax.com) Vector Database. You must have a [Database Administrator token](https://awesome-astra.github.io/docs/pages/astra/create-token/#c-procedure), specifically the string starting with `AstraCS:...`.
- [Database ID](https://awesome-astra.github.io/docs/pages/astra/faq/#where-should-i-find-a-database-identifier).
- an **OpenAI API Key**. (More info [here](https://cassio.org/start_here/#llm-access))

_Note:_ you can alternatively use a regular Cassandra cluster: to do so, make sure you provide the `USE_CASSANDRA_CLUSTER` entry as shown in `.env.template` and the subsequent environment variables to specify how to connect to it.
You may also use a regular Cassandra cluster. In this case, provide the `USE_CASSANDRA_CLUSTER` entry as shown in `.env.template` and the subsequent environment variables to specify how to connect to it.

You need to provide the connection parameters and secrets through environment variables. Please refer to `.env.template` for what variables are required.
The connection parameters and secrets must be provided through environment variables. Refer to `.env.template` for the required variables.

### Populate the vector store
## Usage

Make sure you have the environment variables all set (see previous section),
then, from this directory, launch the following just once:
To use this package, you should first have the LangChain CLI installed:

```shell
pip install -U "langchain-cli[serve]"
```

To create a new LangChain project and install this as the only package, you can do:

```shell
langchain app new my-app --package cassandra-entomology-rag
```

If you want to add this to an existing project, you can just run:

```shell
langchain app add cassandra-entomology-rag
```

And add the following code to your `server.py` file:
```python
from cassandra_entomology_rag import chain as cassandra_entomology_rag_chain

add_routes(app, cassandra_entomology_rag_chain, path="/cassandra-entomology-rag")
```

(Optional) Let's now configure LangSmith.
LangSmith will help us trace, monitor and debug LangChain applications.
LangSmith is currently in private beta, you can sign up [here](https://smith.langchain.com/).
If you don't have access, you can skip this section


```shell
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=<your-api-key>
export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default"
```

To populate the vector store, ensure that you have set all the environment variables, then from this directory, execute the following just once:

```shell
poetry run bash -c "cd [...]/cassandra_entomology_rag; python setup.py"
```

The output will be something like `Done (29 lines inserted).`.

> **Note**: In a full application, the vector store might be populated in other ways:
> this step is to pre-populate the vector store with some rows for the
> demo RAG chains to sensibly work.
Note: In a full application, the vector store might be populated in other ways. This step is to pre-populate the vector store with some rows for the demo RAG chains to work sensibly.

### Sample inputs
If you are inside this directory, then you can spin up a LangServe instance directly by:

The chain's prompt is engineered to stay on topic and only use the provided context.
```shell
langchain serve
```

To put this to test, experiment with these example questions:
This will start the FastAPI app with a server is running locally at
[http://localhost:8000](http://localhost:8000)

```
"Are there more coleoptera or bugs?"
"Do Odonata have wings?"
"Do birds have wings?" <-- no entomology here!
We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
We can access the playground at [http://127.0.0.1:8000/cassandra-entomology-rag/playground](http://127.0.0.1:8000/cassandra-entomology-rag/playground)

We can access the template from code with:

```python
from langserve.client import RemoteRunnable

runnable = RemoteRunnable("http://localhost:8000/cassandra-entomology-rag")
```

## Reference
Expand Down
69 changes: 63 additions & 6 deletions templates/cassandra-synonym-caching/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,76 @@
# LLM-cache LangServe chain template

A simple chain template showcasing usage of LLM Caching
backed by Astra DB / Apache Cassandra®.
# cassandra-synonym-caching

## Setup:
This template provides a simple chain template showcasing the usage of LLM Caching backed by Astra DB / Apache Cassandra®.

You need:
## Environment Setup

To set up your environment, you will need the following:

- an [Astra](https://astra.datastax.com) Vector Database (free tier is fine!). **You need a [Database Administrator token](https://awesome-astra.github.io/docs/pages/astra/create-token/#c-procedure)**, in particular the string starting with `AstraCS:...`;
- likewise, get your [Database ID](https://awesome-astra.github.io/docs/pages/astra/faq/#where-should-i-find-a-database-identifier) ready, you will have to enter it below;
- an **OpenAI API Key**. (More info [here](https://cassio.org/start_here/#llm-access), note that out-of-the-box this demo supports OpenAI unless you tinker with the code.)

_Note:_ you can alternatively use a regular Cassandra cluster: to do so, make sure you provide the `USE_CASSANDRA_CLUSTER` entry as shown in `.env.template` and the subsequent environment variables to specify how to connect to it.

You need to provide the connection parameters and secrets through environment variables. Please refer to `.env.template` for what variables are required.
## Usage

To use this package, you should first have the LangChain CLI installed:

```shell
pip install -U "langchain-cli[serve]"
```

To create a new LangChain project and install this as the only package, you can do:

```shell
langchain app new my-app --package cassandra-synonym-caching
```

If you want to add this to an existing project, you can just run:

```shell
langchain app add cassandra-synonym-caching
```

And add the following code to your `server.py` file:
```python
from cassandra_synonym_caching import chain as cassandra_synonym_caching_chain

add_routes(app, cassandra_synonym_caching_chain, path="/cassandra-synonym-caching")
```

(Optional) Let's now configure LangSmith.
LangSmith will help us trace, monitor and debug LangChain applications.
LangSmith is currently in private beta, you can sign up [here](https://smith.langchain.com/).
If you don't have access, you can skip this section


```shell
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=<your-api-key>
export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

```shell
langchain serve
```

This will start the FastAPI app with a server is running locally at
[http://localhost:8000](http://localhost:8000)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
We can access the playground at [http://127.0.0.1:8000/cassandra-synonym-caching/playground](http://127.0.0.1:8000/cassandra-synonym-caching/playground)

We can access the template from code with:

```python
from langserve.client import RemoteRunnable

runnable = RemoteRunnable("http://localhost:8000/cassandra-synonym-caching")
```

## Reference

Expand Down
68 changes: 66 additions & 2 deletions templates/csv-agent/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,69 @@

# csv-agent

This is a csv agent that uses both a Python REPL as well as a vectorstore to allow for interaction with text data.
This template uses a [csv agent](https://python.langchain.com/docs/integrations/toolkits/csv) with tools (Python REPL) and memory (vectorstore) for interaction (question-answering) with text data.

## Environment Setup

Set the `OPENAI_API_KEY` environment variable to access the OpenAI models.

To set up the environment, the `ingest.py` script should be run to handle the ingestion into a vectorstore.

## Usage

To use this package, you should first have the LangChain CLI installed:

```shell
pip install -U "langchain-cli[serve]"
```

To create a new LangChain project and install this as the only package, you can do:

```shell
langchain app new my-app --package csv-agent
```

If you want to add this to an existing project, you can just run:

```shell
langchain app add csv-agent
```

And add the following code to your `server.py` file:
```python
from csv_agent.agent import chain as csv_agent_chain

add_routes(app, csv_agent_chain, path="/csv-agent")
```

(Optional) Let's now configure LangSmith.
LangSmith will help us trace, monitor and debug LangChain applications.
LangSmith is currently in private beta, you can sign up [here](https://smith.langchain.com/).
If you don't have access, you can skip this section


```shell
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY=<your-api-key>
export LANGCHAIN_PROJECT=<your-project> # if not specified, defaults to "default"
```

If you are inside this directory, then you can spin up a LangServe instance directly by:

```shell
langchain serve
```

This will start the FastAPI app with a server is running locally at
[http://localhost:8000](http://localhost:8000)

We can see all templates at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs)
We can access the playground at [http://127.0.0.1:8000/csv-agent/playground](http://127.0.0.1:8000/csv-agent/playground)

We can access the template from code with:

```python
from langserve.client import RemoteRunnable

Set up that is required is running `ingest.py` to do the ingestion into a vectorstore.
runnable = RemoteRunnable("http://localhost:8000/csv-agent")
```
Loading

0 comments on commit a1fae1f

Please sign in to comment.