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, REDACTED_TOKEN_name):
        openai.api_key = openai_key
        self.REDACTED_TOKEN = BertForSequenceClassification.from_pretrained(REDACTED_TOKEN_name)
        self.tokenizer = BertTokenizer.from_pretrained(REDACTED_TOKEN_name)

    def generate_text(self, prompt):
        response = openai.Completion.create(
          engine="text-davinci-002",
          prompt=prompt,
          max_tokens=60
        )
        return response.choices[0].text.strip()

    def classify_text(self, text):
        inputs = self.tokenizer(text, return_tensors="pt")
        outputs = self.REDACTED_TOKEN(**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: '{}'")
print(generated_text)

probabilities = interface.classify_text(generated_text)
print(probabilities)orimport 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(
      engine="text-davinci-002", 
      prompt=prompt, 
      max_tokens=100
    )
    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?")
print(text) 
print(sentiment)

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

print(text)
# "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." 

print(sentiment)
# 'POSITIVE'note it’s not been tested.Also avoiding lang chains due to bad reputation e.g.,https://twitter.com/AravSrinivas/status/1677884199183994881?t=K7ngp0m3GmRgnj0RjqThZw&s=19Langchain Is Pointless | Hacker Newscross: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
2023-07-14T14:06:45Z
cc@Narsil@olivierdehaenei’ve been lobbying for this for some time:)Could be interesting