OpenGVLab / Ask-Anything

[CVPR2024 Highlight][VideoChatGPT] ChatGPT with video understanding! And many more supported LMs such as miniGPT4, StableLM, and MOSS.
https://vchat.opengvlab.com/
MIT License
3k stars 247 forks source link

Could you please share the code to generate the instruct data? #53

Closed aixiaodewugege closed 10 months ago

aixiaodewugege commented 1 year ago

Hi, I want to generate instruct data on my dataset with GPT4. But I don't know how to write the code. And I also notice that there is rate limit from openai. So I 'd like to have some suggestion or help from you~~~

Andy1621 commented 1 year ago

The text for instruction can be found in our paper. You can follow the prompts in LLaVA to modify ~~

aixiaodewugege commented 1 year ago

Thanks for your reply~ But I mean the code that using these prompt~~~

Any suggestion?

Andy1621 commented 1 year ago

You can use it like this:

import openai
def call_chatgpt(chatgpt_messages, max_tokens=500, model="gpt-3.5-turbo"):
    response = openai.ChatCompletion.create(model=model, messages=chatgpt_messages, temperature=0.6, max_tokens=max_tokens)
    reply = response['choices'][0]['message']['content']
    total_tokens = response['usage']['total_tokens']
    return reply, total_tokens

chat = [
    {
        'role': 'system', 
        'content': "You are a good assistant. Follow the user's instructions carefully."
    },
    {
        'role': 'user', 
        'content': 'Hello"
    }
]
output = call_chatgpt(chat, max_tokens=500)[0]