Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
refactor: delete legacy and clean package import using autogen-init
Browse files Browse the repository at this point in the history
  • Loading branch information
dsdanielpark committed Mar 16, 2024
1 parent 21e1168 commit ea6b0bb
Show file tree
Hide file tree
Showing 40 changed files with 84 additions and 1,136 deletions.
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ assignees: dsdanielpark

Example
```
pip uninstall bardapi # and restart kernel
pip install bardapi==0.1.29 # check proper version
pip install -u bardapi==0.1.29 # upgrade version
pip uninstall python-gemini-api # and restart kernel
pip install python-gemini-api==2.0.0 # check proper version
pip install -u python-gemini-api==2.0.0 # upgrade version
```

```python
import bardapi
bardapi.__version__
import gemini
gemini.__version__
```

----------Please delete the content above this line, including this line.-------------
Expand Down
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ Please make sure to check for more efficient package management. *Please priorit

Example
```
pip uninstall bardapi # and restart kernel
pip install bardapi==0.1.29 # check proper version
pip install -u bardapi==0.1.29 # upgrade version
pip uninstall python-gemini-api # and restart kernel
pip install python-gemini-api==2.0.0 # check proper version
pip install -u python-gemini-api==2.0.0 # upgrade version
```

```python
import bardapi
bardapi.__version__
import gemini
gemini.__version__
```
----------Please delete the content above this line, including this line.-------------

Expand Down
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
I welcome the overall code refactoring and new features. However, please make sure to conduct QA. Before making a PR, please check the entire functionality by adding it to https://github.com/dsdanielpark/Bard-API/blob/main/func_test.ipynb. Due to various reasons, I couldn't implement test mocking code. I also welcome anyone who can provide test mocking and refactoring. But please keep the existing method names and examples. While I aim to accept PRs as quickly as possible, they may be rejected if QA is not correct.
I welcome the overall code refactoring and new features. However, please make sure to conduct QA. Before making a PR, please check the entire functionality by adding it to https://github.com/dsdanielpark/Gemini-API/blob/main/func_test.ipynb. Due to various reasons, I couldn't implement test mocking code. I also welcome anyone who can provide test mocking and refactoring. But please keep the existing method names and examples. While I aim to accept PRs as quickly as possible, they may be rejected if QA is not correct.

<!--- Provide a general summary of your changes in the Title above -->
# BARD-API Pull Request Template
# Gemini-API Pull Request Template
Please provide the necessary information as succinctly as possible. I appreciate it if you write it in an easy-to-read format as I don't have much time to dedicate to maintaining this package.

## Description
Expand Down
6 changes: 3 additions & 3 deletions documents/README_DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Development Status :: 3 - Alpha
pip install git+https://github.com/dsdanielpark/Gemini-API.git
```

This section aims to implement functionalities of the Bard API. While there are many readily portable codes, updates may be delayed.
This section aims to implement functionalities of the Gemini API. While there are many readily portable codes, updates may be delayed.


# Contents
Expand All @@ -31,7 +31,7 @@ This section aims to implement functionalities of the Bard API. While there are


### Multi-language Gemini
For commercial use cases, please refrain from using the unofficial Google Translate package included in bardapi for non-commercial purposes. Instead, kindly visit the official Google Cloud Translation website. Please use it responsibly, taking full responsibility for your actions, as bardapi package does not assume any implicit or explicit liability.
For commercial use cases, please refrain from using the unofficial Google Translate package included in `python-gemini-api` for non-commercial purposes. Instead, kindly visit the official Google Cloud Translation website. Please use it responsibly, taking full responsibility for your actions, as `python-gemini-api` package does not assume any implicit or explicit liability.
> Official Google Translation API
- Support Languages: https://cloud.google.com/translate/docs/languages?hl=ko
> Unofficial Google Trnaslator for non-profit purposes (such as feature testing)
Expand Down Expand Up @@ -90,7 +90,7 @@ GeminiAsync is not using requests library instead it is using httpx library and

### Translation to Another Programming Language
Please check the translation results in [this folder](https://github.com/dsdanielpark/Gemini-API/tree/main/translate_to).
- Copy the code of [Core.py](https://github.com/dsdanielpark/Gemini-API/blob/17d5e948d4afc535317de3964232ab82fe223521/bardapi/core.py).
- Copy the code of [Core.py](https://github.com/dsdanielpark/Gemini-API/blob/17d5e948d4afc535317de3964232ab82fe223521/`python-gemini-api`/core.py).
- Ask ChatGPT to translate like "Translate to Swift."
- Ask ChatGPT to optimize the code or provide any desired instructions until you're satisfied.<br>

Expand Down
24 changes: 19 additions & 5 deletions gemini/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
from os import environ
from .async_core import GeminiClient

from .core import Gemini
from .async_core import GeminiClient

from .src.model.image import GeminiImage
from .src.model.output import GeminiCandidate, GeminiModelOutput
from .src.misc import *
from .src.parser import *
from .src.tools import *
from .src.tools.google import *
from .src.model.parser.base import BaesParser
from .src.model.parser.custom_parser import ParseMethod1, ParseMethod2
from .src.model.parser.response_parser import ResponseParser, _parse_code

from .src.misc.constants import Tool
from .src.misc.decorator import retry, log_method, time_execution, handle_errors
from .src.misc.exceptions import PackageError, GeminiAPIError, TimeoutError
from .src.misc.utils import extract_code, upload_image, max_token, max_sentence

from .src.extension.replit import prepare_replit_data

try:
from .src.module.voice.google import google_tts, google_stt
from .src.module.voice.openai import openai_tts, openai_stt
except ImportError as e:
pass

gemini_api_key = environ.get("GEMINI_COOKIES")

Expand Down
1 change: 1 addition & 0 deletions gemini/async_core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TO-DO: Current logic contains traces of development attempts, so need to add asynchronous processing based on core.py and document it.
import os
import re
import json
Expand Down
4 changes: 2 additions & 2 deletions gemini/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from typing import Optional, Tuple, Dict, Union
from requests.exceptions import ConnectionError, RequestException

from .src.parser.custom_parser import ParseMethod1, ParseMethod2
from .src.parser.response_parser import ResponseParser
from .src.model.parser.custom_parser import ParseMethod1, ParseMethod2
from .src.model.parser.response_parser import ResponseParser
from .src.model.output import GeminiCandidate, GeminiModelOutput
from .src.misc.utils import upload_image
from .src.misc.constants import (
Expand Down
1 change: 1 addition & 0 deletions gemini/src/extension/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .replit import prepare_replit_data
25 changes: 25 additions & 0 deletions gemini/src/extension/replit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import json


def prepare_replit_data(instructions: str, code: str, filename: str) -> list:
"""
Creates and returns the input image data structure based on provided parameters.
Args:
instructions (str): The instruction text.
code (str): The code.
filename (str): The filename.
Returns:
list: The input image data structure.
"""
return [
[
[
"qACoKe",
json.dumps([instructions, 5, code, [[filename, code]]]),
None,
"generic",
]
]
]
4 changes: 4 additions & 0 deletions gemini/src/misc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .constants import Tool
from .decorator import retry, log_method, time_execution, handle_errors
from .exceptions import PackageError, GeminiAPIError, TimeoutError
from .utils import extract_code, upload_image, max_token, max_sentence
File renamed without changes.
File renamed without changes.
27 changes: 1 addition & 26 deletions gemini/src/misc/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import requests
from typing import Union
from .constants import IMAGE_PUSH_ID
from gemini.src.misc.constants import IMAGE_PUSH_ID


def extract_code(text: str) -> str:
Expand Down Expand Up @@ -68,30 +67,6 @@ def upload_image(file: Union[bytes, str]) -> str:
return response.text


def prepare_replit_data(instructions: str, code: str, filename: str) -> list:
"""
Creates and returns the input image data structure based on provided parameters.
Args:
instructions (str): The instruction text.
code (str): The code.
filename (str): The filename.
Returns:
list: The input image data structure.
"""
return [
[
[
"qACoKe",
json.dumps([instructions, 5, code, [[filename, code]]]),
None,
"generic",
]
]
]


def max_token(text: str, n: int) -> str:
"""
Return the first 'n' tokens (words) of the given text.
Expand Down
2 changes: 2 additions & 0 deletions gemini/src/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .image import GeminiImage
from .output import GeminiCandidate, GeminiModelOutput
3 changes: 3 additions & 0 deletions gemini/src/model/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .base import BaesParser
from .custom_parser import ParseMethod1, ParseMethod2
from .response_parser import ResponseParser, _parse_code
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gemini.src.parser.base import BaesParser
from gemini.src.model.parser.base import BaesParser
from typing import Dict, Any


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from typing import Dict
from gemini.src.parser.base import BaesParser
from gemini.src.model.parser.base import BaesParser
from gemini.src.misc.utils import extract_code


Expand Down
2 changes: 2 additions & 0 deletions gemini/src/module/voice/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .google import google_tts, google_stt
from .openai import openai_tts, openai_stt
Empty file removed gemini/src/parser/__init__.py
Empty file.
1 change: 0 additions & 1 deletion gemini/src/tools/__init__.py

This file was deleted.

38 changes: 0 additions & 38 deletions gemini/src/tools/citation.py

This file was deleted.

Loading

0 comments on commit ea6b0bb

Please sign in to comment.