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
pip install geminiwrapper
Basic Usage
- Import:
import geminiwrapper
-
Obtain Gemini AI API key: Get Gemini AI API key
-
Create example objects:
- For json output, create a few python dictionaries. For example,
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,
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"],
)
- Instantiate the wrapper:
- For json output,
json_model = JsonWrapper(api_key, [json1, json2])
api_key is the Gemini API key obtained from this link
- For python object output,
object_model = ObjectWrapper(api_key, __name__, [country1, country2])
api_key is the Gemini API key obtained from this link __name__ is to pass the name of the module.
- Generate Content:
- For json output,
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.
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,
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.
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}")
Metadata
Release files for geminiwrapper 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| geminiwrapper-0.1.0.tar.gz | 3.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| geminiwrapper-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.6 kB
Release files / geminiwrapper-0.1.0.tar.gz
| Download URL | geminiwrapper-0.1.0.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
206d9f32748896422f9d460b3b359ad5417689ccb92189c74bd320a67a8c2a3b
|
|
BLAKE2b-256 checksum How to use checksums |
8aa2ff46a51be35a26028f7f7191cebde86f742ea2e4b858bbced3a99b82d114
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.4
|
Release files / geminiwrapper-0.1.0-py3-none-any.whl
| Download URL | geminiwrapper-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5944408865da83f1e709403c1861e98479bf09faa75c9439854a4f40046e46fb
|
|
BLAKE2b-256 checksum How to use checksums |
e0d243d779412684714a9d5f5fcf38d26d574439dd6b7f5bb39351c3f104f49b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.4
|