geminiwrapper


Namegeminiwrapper JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/Osbertt-19/gemini-wrapper
SummaryLibrary for generating consistent Gemini API outputs and wrapping them with json and python objects
upload_time2024-04-21 15:48:20
maintainerNone
docs_urlNone
authorMin Htet Naing
requires_pythonNone
licenseNone
keywords gemini object json wrapper consistent
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## GeminiWrapper

GeminiWrapper is a library for generating consistent Gemini API outputs and wrapping them with json and python objects. It takes python dictionaries(for json format) or python objects as few-shot examples to output valid json or python objects.

### Getting Started

**Installation**

```console
pip install geminiwrapper
```

**Basic Usage**

1. Import:

```python
import geminiwrapper
```

2. Obtain Gemini AI API key:
   [Get Gemini AI API key](https://ai.google.dev/tutorials/setup)

3. Create example objects:

- For json output, create a few python dictionaries. For example,

```python
json1 = {
    "name": "England",
    "capital": "London",
    "population": "56.3 million",
    "neighbouring_countries": ["Scotland", "Wales"],
}
json2 = {
    "name": "Thailand",
    "capital": "Bangkok",
    "population": "70.4 million",
    "neighbouring_countries": ["Myanmar (Burma)", "Laos", "Cambodia", "Malaysia"],
}
```

- For python object output, create a class and a few objects. For example,

```python
class Country:
    def __init__(self, name, capital, population, neighbouring_countries) -> None:
        self.name = name
        self.capital = capital
        self.population = population
        self.neighbouring_countries = neighbouring_countries
country1 = Country("England", "London", "56.3 million", ["Scotland", "Wales"])
country2 = Country(
    "Thailand",
    "Bangkok",
    "70.4 million",
    ["Myanmar (Burma)", "Laos", "Cambodia", "Malaysia"],
)
```

4. Instantiate the wrapper:

- For json output,

```python
json_model = JsonWrapper(api_key, [json1, json2])
```

api_key is the Gemini API key obtained from [this link](https://ai.google.dev/tutorials/setup)

- For python object output,

```python
object_model = ObjectWrapper(api_key, __name__, [country1, country2])
```

api_key is the Gemini API key obtained from [this link](https://ai.google.dev/tutorials/setup)
\_\_name\_\_ is to pass the name of the module.

5. Generate Content:

- For json output,

```python
prompt = "Write about Myanmar, Singapore, United States and Germany"
response = json_model.generate_content(prompt)
```

response is a list of dictionaries that can be processed as follow.

```python
for country in response:
    print(f"The name of the country: {country['name']}")
    print(f"The capital of the country: {country['capital']}")
    print(f"The population of the country: {country['population']}")
    print(f"The neighbouring countries: {country['neighbouring_countries']}")
```

- For python object output,

```python
prompt = "Write about Myanmar, Singapore, United States and Germany"
response: List[Country] = object_model.generate_content(prompt)
```

response is a list of Country objects that can be processed as follow.

```python
for country in response:
    print(f"The name of the country: {country.name}")
    print(f"The capital of the country: {country.capital}")
    print(f"The population of the country: {country.population}")
    print(f"The neighbouring countries: {country.neighbouring_countries}")
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Osbertt-19/gemini-wrapper",
    "name": "geminiwrapper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "gemini, object, json, wrapper, consistent",
    "author": "Min Htet Naing",
    "author_email": "minhtetnaing25mhn@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8a/a2/ff46a51be35a26028f7f7191cebde86f742ea2e4b858bbced3a99b82d114/geminiwrapper-0.1.0.tar.gz",
    "platform": null,
    "description": "## GeminiWrapper\r\n\r\nGeminiWrapper is a library for generating consistent Gemini API outputs and wrapping them with json and python objects. It takes python dictionaries(for json format) or python objects as few-shot examples to output valid json or python objects.\r\n\r\n### Getting Started\r\n\r\n**Installation**\r\n\r\n```console\r\npip install geminiwrapper\r\n```\r\n\r\n**Basic Usage**\r\n\r\n1. Import:\r\n\r\n```python\r\nimport geminiwrapper\r\n```\r\n\r\n2. Obtain Gemini AI API key:\r\n   [Get Gemini AI API key](https://ai.google.dev/tutorials/setup)\r\n\r\n3. Create example objects:\r\n\r\n- For json output, create a few python dictionaries. For example,\r\n\r\n```python\r\njson1 = {\r\n    \"name\": \"England\",\r\n    \"capital\": \"London\",\r\n    \"population\": \"56.3 million\",\r\n    \"neighbouring_countries\": [\"Scotland\", \"Wales\"],\r\n}\r\njson2 = {\r\n    \"name\": \"Thailand\",\r\n    \"capital\": \"Bangkok\",\r\n    \"population\": \"70.4 million\",\r\n    \"neighbouring_countries\": [\"Myanmar (Burma)\", \"Laos\", \"Cambodia\", \"Malaysia\"],\r\n}\r\n```\r\n\r\n- For python object output, create a class and a few objects. For example,\r\n\r\n```python\r\nclass Country:\r\n    def __init__(self, name, capital, population, neighbouring_countries) -> None:\r\n        self.name = name\r\n        self.capital = capital\r\n        self.population = population\r\n        self.neighbouring_countries = neighbouring_countries\r\ncountry1 = Country(\"England\", \"London\", \"56.3 million\", [\"Scotland\", \"Wales\"])\r\ncountry2 = Country(\r\n    \"Thailand\",\r\n    \"Bangkok\",\r\n    \"70.4 million\",\r\n    [\"Myanmar (Burma)\", \"Laos\", \"Cambodia\", \"Malaysia\"],\r\n)\r\n```\r\n\r\n4. Instantiate the wrapper:\r\n\r\n- For json output,\r\n\r\n```python\r\njson_model = JsonWrapper(api_key, [json1, json2])\r\n```\r\n\r\napi_key is the Gemini API key obtained from [this link](https://ai.google.dev/tutorials/setup)\r\n\r\n- For python object output,\r\n\r\n```python\r\nobject_model = ObjectWrapper(api_key, __name__, [country1, country2])\r\n```\r\n\r\napi_key is the Gemini API key obtained from [this link](https://ai.google.dev/tutorials/setup)\r\n\\_\\_name\\_\\_ is to pass the name of the module.\r\n\r\n5. Generate Content:\r\n\r\n- For json output,\r\n\r\n```python\r\nprompt = \"Write about Myanmar, Singapore, United States and Germany\"\r\nresponse = json_model.generate_content(prompt)\r\n```\r\n\r\nresponse is a list of dictionaries that can be processed as follow.\r\n\r\n```python\r\nfor country in response:\r\n    print(f\"The name of the country: {country['name']}\")\r\n    print(f\"The capital of the country: {country['capital']}\")\r\n    print(f\"The population of the country: {country['population']}\")\r\n    print(f\"The neighbouring countries: {country['neighbouring_countries']}\")\r\n```\r\n\r\n- For python object output,\r\n\r\n```python\r\nprompt = \"Write about Myanmar, Singapore, United States and Germany\"\r\nresponse: List[Country] = object_model.generate_content(prompt)\r\n```\r\n\r\nresponse is a list of Country objects that can be processed as follow.\r\n\r\n```python\r\nfor country in response:\r\n    print(f\"The name of the country: {country.name}\")\r\n    print(f\"The capital of the country: {country.capital}\")\r\n    print(f\"The population of the country: {country.population}\")\r\n    print(f\"The neighbouring countries: {country.neighbouring_countries}\")\r\n```\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Library for generating consistent Gemini API outputs and wrapping them with json and python objects",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/Osbertt-19/gemini-wrapper"
    },
    "split_keywords": [
        "gemini",
        " object",
        " json",
        " wrapper",
        " consistent"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e0d243d779412684714a9d5f5fcf38d26d574439dd6b7f5bb39351c3f104f49b",
                "md5": "eeca99be47cab1ae5aed4023ea18f5eb",
                "sha256": "5944408865da83f1e709403c1861e98479bf09faa75c9439854a4f40046e46fb"
            },
            "downloads": -1,
            "filename": "geminiwrapper-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eeca99be47cab1ae5aed4023ea18f5eb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4212,
            "upload_time": "2024-04-21T15:48:18",
            "upload_time_iso_8601": "2024-04-21T15:48:18.090366Z",
            "url": "https://files.pythonhosted.org/packages/e0/d2/43d779412684714a9d5f5fcf38d26d574439dd6b7f5bb39351c3f104f49b/geminiwrapper-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8aa2ff46a51be35a26028f7f7191cebde86f742ea2e4b858bbced3a99b82d114",
                "md5": "e329d0c85a2f2f6c03b121d6f49008fd",
                "sha256": "206d9f32748896422f9d460b3b359ad5417689ccb92189c74bd320a67a8c2a3b"
            },
            "downloads": -1,
            "filename": "geminiwrapper-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e329d0c85a2f2f6c03b121d6f49008fd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3411,
            "upload_time": "2024-04-21T15:48:20",
            "upload_time_iso_8601": "2024-04-21T15:48:20.169871Z",
            "url": "https://files.pythonhosted.org/packages/8a/a2/ff46a51be35a26028f7f7191cebde86f742ea2e4b858bbced3a99b82d114/geminiwrapper-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-21 15:48:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Osbertt-19",
    "github_project": "gemini-wrapper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "geminiwrapper"
}
        
Elapsed time: 0.24249s