Is there a Hugging Face (HF) model API for inference that is uniform with HF models and the Open AI interface?

I want a unified interface with Open AI’s API and Hugging Face models to have a consistent interface depending on what model I am using.

Does this exist? Wanted to check tested version before I wrote my own but here are some possibilities:

import openai
import torch
from transformers import BertTokenizer, BertForSequenceClassification

class OpenAI_HF_Interface:
    def __init__(self, openai_key, hf_model_name):
        openai.api_key = openai_key
        self.hf_model = BertForSequenceClassification.from_pretrained(hf_model_name)
        self.tokenizer = BertTokenizer.from_pretrained(hf_model_name)

    def generate_text(self, prompt):
        response = openai.Completion.create(
        return response.choices[0].text.strip()

    def classify_text(self, text):
        inputs = self.tokenizer(text, return_tensors="pt")
        outputs = self.hf_model(**inputs)
        probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
        return probabilities

# Test the class
interface = OpenAI_HF_Interface('your-openai-api-key', 'bert-base-uncased')

generated_text = interface.generate_text("Translate the following English text to French: '{}'")

probabilities = interface.classify_text(generated_text)


import openai 
from transformers import pipeline

openai.api_key = "YOUR_OPENAI_KEY"

nlp = pipeline("sentiment-analysis")

class AIAssistant:
  def generate_and_classify(self, prompt):
    completions = openai.Completion.create(
    generated_text = completions.choices[0].text.strip()
    result = nlp(generated_text)
    sentiment = result[0].get('label')
    return generated_text, sentiment

assistant = AIAssistant()

text, sentiment = assistant.generate_and_classify("How good was the movie yesterday?")

prompt = "How good was the movie yesterday?"
text, sentiment = assistant.generate_and_classify(prompt)

# "The movie yesterday was absolutely incredible! The acting, writing, and cinematography were all top-notch. It was gripping from start to finish and really moved me emotionally. Definitely one of the best films I've seen in the past year." 


note it’s not been tested.

Also avoiding lang chains due to bad reputation e.g.,

cross: huggingface transformers - Is there a Hugging Face (HF) model API for inference that is uniform with HF models and the Open AI interface? - Stack Overflow

cc @Narsil @olivierdehaene i’ve been lobbying for this for some time:)

Could be interesting