Tamsen1995 / online_llm

0 stars 0 forks source link

Online LLM Project

Overview

This project is a RESTful, OpenAI-compatible API built using Rust. It's designed to integrate with any Large Language Model (LLM) from OpenAI you input into it, providing flexibility. The application utilizes Docker and Docker Compose for easy deployment and scalability. It also features SerpApi for web scraping to enhance the context provided to the language model. The design prioritizes scalability and ease of deployment.

Features

Project Structure

online_llm/
├── Cargo.lock
├── Cargo.toml
├── Dockerfile
├── Rocket.toml
├── docker-compose.yml
├── .env
├── src/
│   ├── api.rs
│   ├── config.rs
│   ├── main.rs
│   ├── models.rs
│   ├── openai_client.rs
│   └── serpapi_client.rs
├── tests/
│   └── integration_tests.rs
└── README.md

File Descriptions

Setup and Running Locally

Prerequisites

Steps

  1. Create the .env file:

    touch .env

    Add the following lines to the .env file with your API keys:

    OPENAI_API_KEY=your_openai_api_key_here
    SERPAPI_API_KEY=your_serpapi_api_key_here
  2. Build and run the application:

    docker-compose build
    docker-compose up

    When running the application with docker-compose up, the health check endpoint is hit every 30 seconds. You should see the OK log in the terminal in which you launched the app.

  3. Verify the application is running:

    • Check the Docker container logs to ensure the Rocket server is running:
      docker-compose logs
    • You should see Rocket has launched from http://0.0.0.0:8000.

Running without Docker Compose

If you want to run the application without Docker Compose, you can use the run.sh script that is included in the repository. To do this, simply run the following command:

./run.sh

Health Check

The application includes a health check endpoint to monitor its status. The health check endpoint is /health and can be used to verify that the application is running correctly.

Example

curl http://localhost:8000/health

This should return OK if the application is running correctly.

Running Tests

To ensure the application is functioning as expected, you can run the tests included in the project. The tests are located in the tests/integration_tests.rs file.

Run the tests using the following command:

cargo test

Deployment to Heroku

This repository includes a script for deploying the application to Heroku using the Heroku Container Registry. The script is named deploy.sh.

Prerequisites

Environment Variables

Before running the script, you need to set the following environment variables:

You can set these environment variables in your shell like this:

export HEROKU_API_KEY=your_heroku_api_key_here
export HEROKU_APP_NAME=your_heroku_app_name_here

Running the Script

./deploy.sh

License

This project is licensed under the MIT License. See the LICENSE file for more details.