Skip to content

Learn the entire LangChain tech-stack fast πŸƒβ€β™€οΈ

Notifications You must be signed in to change notification settings

Cutwell/langchain-in-Y-seconds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Learn LangChain in Y seconds

Learn the entire LangChain tech-stack fast πŸƒβ€β™€οΈ

License: MIT

Prerequisites

  1. Install Python (3.11.6 used in video).
  2. Install Poetry.
  3. Install DirEnv (or use another secret manager).
  4. Get your OpenAI API key.
  5. Sign up for LangSmith and get your LangSmith API key (https://smith.langchain.com/ and access API keys via the πŸ”‘ icon on the bottom left).

Tutorial walkthrough

  1. If using a secret file (e.g.: .envrc), create a .gitignore file similar to the one in this repository, to prevent accidentally sharing your API keys.

  2. Create a .envrc file and populate it with this template:

export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
export LANGCHAIN_API_KEY=<your-langsmith-api-key>
export LANGCHAIN_PROJECT=langchain-quickstart  # if not specified, defaults to "default"

export OPENAI_API_KEY=<your-openai-api-key>
  1. Open a new terminal and run these commands:
poetry init -n --python=3.11.6 && poetry add langchain-cli
source ./.venv/bin/activate
poetry run langchain app new api --package pirate-speak

Type 'Y' when prompted to install pirate-speak as a mirrored module

  1. Replace the NotImplemented route in api/app/server.py with a route for your component chain:
from pirate_speak.chain import chain as pirate_speak_chain

add_routes(app, pirate_speak_chain, path="/pirate-speak")
  1. Update the project name in api/pyproject.toml:
name = "api"

This can be any name other than __app_name__

  1. Open a new terminal in /api and run these commands:
poetry install
source ./.venv/bin/activate
poetry run langchain serve
  1. Visit http://127.0.0.1:8000/pirate-speak/playground/ in your web browser and play with your chain.

  2. Open LangSmith (https://smith.langchain.com/) and visit the project page. View one of your traces (created when you tested the playground demo) and use it to create a dataset.

  3. View the dataset and click New Test Run to get a code snippet:

client = langsmith.Client()
chain_results = client.run_on_dataset(
	dataset_name="quickstart-dataset",	# this will change if you use a different dataset name.
	llm_or_chain_factory=chain,
	project_name="test-formal-project-4",
	concurrency_level=5,
	verbose=True,
)
  1. Create a new PyTest file test_chain.py in api/packages/pirate-speak/tests/:
from pirate_assistant.chain import chain
import langsmith
from datetime import datetime # import datetime module to get a timestamp

def test_chain():
	client = langsmith.Client()

	chain_results = client.run_on_dataset(
		dataset_name="quickstart-dataset",
		llm_or_chain_factory=chain,
		project_name=f"quickstart-dataset-test-{int(datetime.now().strftime('%Y%m%d%H%M%S'))}", # use a timestamped unique project name each re-run
		concurrency_level=5,
		verbose=True,
	)

To enable PyTest re-runs, we want to use a timestamped unique project name to store each successive test result.

  1. Open a terminal in /api and run these commands:
poetry add pytest --group=dev
poetry run python -m pytest -s .
  1. View your dataset test runs, and add the trace to a new annotation queue.

  2. View your annotation queue and explore the review interface.

πŸŽ‰πŸŽ‰ Congratulations! πŸŽ‰πŸŽ‰ You've completed this tutorial and now have a complete LangChain project. If you need more help with navigating the LangSmith interface, go view the video version of this tutorial on Youtube.

License

MIT

About

Learn the entire LangChain tech-stack fast πŸƒβ€β™€οΈ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published