Coder Social home page Coder Social logo

langchain_guidance's Introduction

Custom Guidance Server with LangChain Integration

The project primarily focuses on integrating the Guidance and LangChain libraries to offer a solution for querying and understanding documentation with the help of AI. A Flask server is set up that utilizes Oobabooga, LangChain, and Chroma vector store for intelligent retrieval and responses.

Project Structure

constants.py

This file defines several important constants used in the project. The constants defined include:

EMB_OPENAI_ADA: Specifies the embedding model name for OpenAI Ada.
EMB_INSTRUCTOR_XL: Specifies the embedding model name for Instructor XL.
LLM_OPENAI_GPT35: Specifies the language model name for OpenAI GPT-3.5.
OOBA: A string constant.
TEST_FILE: Specifies the path to a test file.
MODEL: Specifies the path to the custom model.

These constants are used throughout the code, especially in tools.py where the tools are defined and loaded. Installation

Before running the server, ensure the following Python libraries are installed:

Flask
Flask-CORS
nest_asyncio
dotenv
gradio
guidance
torch
LangChain
Chroma

You can install the dependencies using pip:

bash

pip install -r requirements.txt

Make also sure you have text-generation-webui running in the background with arguments as such: python server.py --listen --model your-model --api --verbose --xformers --no-stream

Running the Server

Load the model using the '/load_model' POST endpoint. The model loads into memory on startup.
Load the tools using the '/load_tools' POST endpoint. It checks if the model is loaded before loading the tools.
Use the '/run_script' POST endpoint to run the script. It checks if the tools are loaded before running the script.

To start the server, use the following command:

python gdc_server.py

This will start a Flask server listening on 0.0.0.0:5001.

Customization

The CustomAgentGuidance class is defined in the agent.py file. This class can be customized to provide different behaviors for guidance.

In tools.py, a dictionary of tool functions can be loaded for use in the server. Each tool should be a function that takes an input and returns an output. The Chroma Search tool is provided as an example.

The server script (gdc_server.py) is set up to load a custom model and toolset, and then provide guidance based on those. The loaded model and toolset can be customized as needed.

Interconnection of Guidance and LangChain

This project's key feature is the combination of the Guidance and LangChain libraries. It loads a model using the Guidance library and then uses LangChain to set up a document retrieval system.

This system is based on a Chroma vector store, which indexes and retrieves documents using AI embeddings. This allows for complex queries to be run on large amounts of documentation, with the AI providing intelligent, context-based answers.

The server offers a '/run_script' endpoint to make queries against this document retrieval system and obtain AI-guided responses.

Known Issues

If you encounter an issue where the event loop is already running, you can solve this problem by calling nest_asyncio.apply().

langchain_guidance's People

Contributors

hugothomel avatar quangbk avatar

Stargazers

 avatar  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.