lk-geimfari / mimesis

Mimesis is a robust data generator for Python that can produce a wide range of fake data in multiple languages.
https://mimesis.name
MIT License
4.34k stars 326 forks source link

Add support of GPT provider. #1567

Open lk-geimfari opened 2 weeks ago

lk-geimfari commented 2 weeks ago

If something the user needs is not supported by Mimesis, they can generate it using OpenAI, like this:

from mimesis.plugins.gpt import ChatGPT

>>> chat_gpt = ChatGPT(api_key='API_KEY_HERE')
>>> chat_gpt.assistant_message = "You are a test data generator."
>>> chat_gpt.user_message = (
    "Generate a random {prompt}. "
    "Please make sure that nothing except the {prompt} is in the output."
)
>>> chat_gpt.chat("japanese city name", model="gpt-3.5-turbo")
'翔太'

>>> chat_gpt.image("ninja shiba pixel art") # returns image encoded in base64 (or, maybe as BytesIO object)

This is just an example; the API is not finalized yet.

lk-geimfari commented 2 weeks ago

I'm currently working on this, but help is welcome.

Rangeeshar commented 1 week ago

Hi @lk-geimfari , If you are not working on this I could create this plugin from your example code.

lk-geimfari commented 1 week ago

Hi @lk-geimfari , If you are not working on this I could create this plugin from your example code.

Sure!

Rangeeshar commented 1 week ago

Hi @lk-geimfari , couple of thoughts. For the accessibility should use free LLM to generate the results like random text, image, and audio based on the prompt. It will unlock lot of users who can test us without any subscription to chatgpt plus or to even chatgpt.

lk-geimfari commented 1 week ago

Hi @lk-geimfari , couple of thoughts. For the accessibility should use free LLM to generate the results like random text, image, and audio based on the prompt. It will unlock lot of users who can test us without any subscription to chatgpt plus or to even chatgpt.

I'd prefer to avoid a lot of optional deps, but overall the idea is a good one.

Rangeeshar commented 1 week ago

@lk-geimfari check this draft PR. https://github.com/Rangeeshar/mimesis/pull/1 Let me know if you need any other change on top of this. I can make model dynamic and other params dynamic which could be passed to hugging face by our users.

After this I can create an Image based one and audio based one. Once we push this out. I could create a plugin which you can attach any AI in future.

lk-geimfari commented 1 week ago

I like it! Looks good. A good idea would be to use try/except when importing libs that will be optional. See the example in plugins/pytest.py. Also, do not foget include optional deps to pyproject.toml so we will be able to install all optional AI-related deps like this:

> pip install mimesis[ai]
lk-geimfari commented 1 week ago

Also, don't forget the tests. Tests are good, we love them.

Rangeeshar commented 1 week ago

Hi man @lk-geimfari , added a draft PR. Please add some comments If you think something needs a change. https://github.com/lk-geimfari/mimesis/pull/1571