alexanderatallah / window.ai

Use your own AI models on the web
https://windowai.io
MIT License
806 stars 70 forks source link

use ChatGPT to write hugging face connectors #12

Closed handrew closed 1 year ago

handrew commented 1 year ago

This is a fun gimmick, but you can actually just use ChatGPT to write connectors for the local Hugging Face Flask server. The prompt below should be fairly self-explanatory, but I've also updated the README with instructions on using create_hugging_face_connector.py.

The prompt to ChatGPT:

Given the description below, please write a Python function that follows the following format:
- The function should be named `import_and_return_<model_name>`.
- The function should return a tuple of three items: a model, a tokenizer, and a function that takes the model, a string, and the tokenizer as arguments and returns the output of the model on the string.
- If there is no need for, for instance, a tokenizer, then the function should return `None` for that item in the tuple. Same with the model.
- The function should be able to be called as `model, tokenizer, model_fn = import_and_return_<model_name>()`.
- If no examples are given in the description, then simply return "No examples given on the page.".

Below is an example.

def import_and_return_tk_instruct_3b_def():
    # Example import function for Huggingface model. Returns model, tokenizer,
    and code for running the model.
    tokenizer = AutoTokenizer.from_pretrained(ALLENAI_INSTRUCT3B_MODEL)
    model = AutoModelForSeq2SeqLM.from_pretrained(ALLENAI_INSTRUCT3B_MODEL)

    def model_fn(model, string, tokenizer):
        input_ids = tokenizer.encode(string, return_tensors="pt")
        output = model.generate(input_ids, max_length=10)
        output = tokenizer.decode(output[0], skip_special_tokens=True)
        return output

    return model, tokenizer, model_fn

================== DESCRIPTION ==================
{description}
=================================================
Your response:
vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
window-ai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 20, 2023 1:13am
alexanderatallah commented 1 year ago

Will check this out soon - thank you!