Giter VIP home page Giter VIP logo

langchain-service's Introduction

langchain-service

This repository is a template for creating a LangChain service. The code is generated from langchain-cli, documents how to develop the service, and deploys it to the LangServe project.

We guess that there are certain rules on how to name the LangChain template. We tried to create the repository with the name LangChain-template but Python does not play nicely with this name (probably because of the name conflict or it tries to refer to Langchain-template (c and C) ).

Anyhow, we do suggest you name your package with all lowercases and - in between.

How this is created?

The project is created with langchain-cli

$ langchain template new .

The command will generate these files.

.
├── langchain_service/. # All the agent/chain is here
│   ├── __init__.py
│   ├── chain.py
├── tests/              # We will write a test script in here
│   ├── __init__.py
├── .gitignore/         # initially, only __pyccache__ is ignored
├── pyproject.toml/     # package manager with `poetry`
└── README.md/          # renamed to READMD_fromLangChain.md

We have to add the package to the editable Python package

$ pip install -e .

Or you can add the path to PYTHON_PATH... i guess.

To run the package

$ langchain template serve

How to develop

This repository is set as a template. You can always create a new repository based on this one easily. Or if you want to fork, feel free to do so.

Codespaces

The template is created with GitHub Codespaces. We recommend you use Codespaces to develop.

Once you spawn the Codespaces, you have to run

$ pip install -e .

This will at ``

$ pip list
...
langchain-service        0.0.1      /workspaces/langchain-service
...

From here, you can spawn a web server with

$ langchain template serve

Then, all you have to do is to at your OPENAI_API_KEY to the environment. You can do this by at it to the .env file. Then run,

$ source .env

Local Development

We tested the .devcontainer on Macbook Pro M3 pro with Docker Desktop version 4.27.2. It seems to work just like Codespaces.

We have not yet tested this on Windows and Linux/Ubuntu but they should just work fine too.

How to deploy

To deploy, we create a docker-compose.yml that will build the Dockerfile. What you will need to provide is the .env file.

LANGCHAIN_TRACING_V2="false"
LANGCHAIN_API_KEY="<YOUR-API-KEY>"  # Update to your API key
LANGCHAIN_PROJECT="default"
LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
OPENAI_API_KEY="<YOUR-API-KEY>"
OPEN_AI_ORG="<YOUR-API-KEY>" # Optional

If you need more environment variables, you can add the .env file or create another one and append the list to env_files in docker-compose.yml

To build and run Docker.

$ docker compose up -d --build

This will spawn a Docker container that only runs the project (similar to the Production). If this works fine, you should be safe to deploy.

How to test

Test code

Run

$ poetry run pytest --cov=langchain_service/ tests/

Test with container (like production)

Run

$ docker compose build 
$ docker compose run --rm langchain poetry run pytest --cov=langchain_service/ tests/

Resources

langchain-service's People

Contributors

akraradets avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.