Giter Club home page Giter Club logo

openai_text_generation_inference_server's Introduction

HuggingChat with OpenAI Integration

This repository contains code that enables the integration of the Hugging Chat UI with the OpenAI API. The provided Python FastAPI code allows you to generate chat completions using the OpenAI GPT-3.5-turbo model and stream the results to the Hugging Chat UI in real-time.

Features

  • Integration of the Hugging Chat UI with the OpenAI API for chat completions.
  • Streaming of chat completion results to the UI in real-time.
  • Customizable parameters for generating chat completions.
  • Easy setup and deployment with FastAPI.

Requirements

To run the code in this repository, you need the following:

  • Python 3.7 or higher
  • FastAPI
  • Pydantic
  • OpenAI Python SDK
  • asyncio

You will also need a valid OpenAI API key to authenticate your requests.

Installation

  1. Clone the repository

  2. install the required dependencies: pip install -r requirements.txt

  3. Set up your OpenAI API key:

    Sign up for an OpenAI account and obtain an API key.

    Set your API key as the OPENAI_API_KEY env variable.

Usage

  1. Start the FastAPI server by running the following command:

    uvicorn server:app --reload

    The server will start running on http://localhost:8000 by default.

  2. Update the .env.local file on your HuggingChat UI installation to include:

    MODELS=`[
    {
        "name": "ChatGPT 3.5 Model",
        "endpoints": [{"url": "http://127.0.0.1:8000/generate_stream"}],
        "userMessageToken": "User: ",
        "assistantMessageToken": "Assistant: ",
        "messageEndToken": "\n",
        "preprompt": "You are a helpful assistant.",
        "parameters": {
        "temperature": 0.9,
        "max_new_tokens": 50,
        "truncate": 1000
        }
    }
    ]`

Testing

Make a POST request to http://localhost:8000/generate_stream with the following JSON payload:

{
"inputs": "User input message",
    "parameters": {
        "temperature": 0.7,
        "max_tokens": 100
    }
}

The chat completions generated by the OpenAI GPT-3.5-turbo model will be streamed to the UI in real-time.

  1. Using Curl, you can test via:
    curl 127.0.0.1:8000/generate_stream \
        -X POST \
        -d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17}}' \
        -H 'Content-Type: application/json'

License

This project is licensed under the GPL3 License.

openai_text_generation_inference_server's People

Contributors

bulletproofmedic avatar gururise avatar secondtruth 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.