This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: 1.0.4 refactoring and add parser
- Loading branch information
1 parent
591ff30
commit 83673df
Showing
36 changed files
with
161 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,15 @@ | ||
# Copyright 2024 Daniel Park, Antonio Cheang, MIT License | ||
from os import environ | ||
from gemini.core import Gemini | ||
from gemini.constants import ( | ||
HEADERS, | ||
REPLIT_SUPPORT_PROGRAM_LANGUAGES, | ||
Tool, | ||
) | ||
from gemini.client import GeminiClient | ||
from gemini.utils import max_token, max_sentence, build_replit_data, extract_code | ||
from .client import GeminiClient | ||
from .core import Gemini | ||
from .src.misc import * | ||
from .src.parser import * | ||
from .src.tools import * | ||
from .src.tools.google import * | ||
|
||
gemini_api_key = environ.get("GEMINI_COOKIES") | ||
|
||
__all__ = [ | ||
"GeminiClient", | ||
"Gemini", | ||
"max_token", | ||
"max_sentence", | ||
"HEADERS", | ||
"REPLIT_SUPPORT_PROGRAM_LANGUAGES", | ||
"Tool", | ||
"build_replit_data", | ||
"extract_code", | ||
] | ||
__version__ = "1.0.3" | ||
__version__ = "1.0.4" | ||
__author__ = ( | ||
"daniel park <parkminwoo1991@gmail.com>, antonio cheang <teapotv8@proton.me>" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import httpx | ||
from pathlib import Path | ||
from loguru import logger | ||
from typing import List, Optional, Dict | ||
from pydantic import BaseModel, HttpUrl | ||
|
||
|
||
class GeminiImage(BaseModel): | ||
url: HttpUrl | ||
title: str = "[Image]" | ||
alt: str = "" | ||
|
||
def __str__(self): | ||
return f"{self.title}({self.url}) - {self.alt}" | ||
|
||
async def save( | ||
self, | ||
path: str = "temp", | ||
filename: Optional[str] = None, | ||
cookies: Optional[dict] = None, | ||
) -> Optional[Path]: | ||
filename = filename or Path(self.url).name | ||
save_path = Path(path) / filename | ||
save_path.parent.mkdir(parents=True, exist_ok=True) | ||
|
||
async with httpx.AsyncClient(follow_redirects=True, cookies=cookies) as client: | ||
try: | ||
response = await client.get(self.url) | ||
response.raise_for_status() | ||
save_path.write_bytes(response.content) | ||
return save_path | ||
except httpx.HTTPStatusError as e: | ||
logger.error( | ||
f"Error downloading image: {e.response.status_code} {e.response.reason_phrase}" | ||
) | ||
return None | ||
|
||
|
||
class GeminiCandidate(BaseModel): | ||
rcid: str | ||
text: str | ||
web_images: List[GeminiImage] = [] | ||
generated_images: List[GeminiImage] = [] | ||
raw: Dict | ||
|
||
|
||
class GeminiModelOutput(BaseModel): | ||
metadata: List[str] | ||
candidates: List[GeminiCandidate] | ||
chosen: int = 0 | ||
response_dict: Optional[dict] = None | ||
|
||
@property | ||
def rcid(self) -> str: | ||
return self.candidates[self.chosen].rcid | ||
|
||
@property | ||
def text(self) -> str: | ||
return self.candidates[self.chosen].text | ||
|
||
@property | ||
def web_images(self) -> List[GeminiImage]: | ||
return self.candidates[self.chosen].web_images | ||
|
||
@property | ||
def generated_images(self) -> List[GeminiImage]: | ||
return self.candidates[self.chosen].generated_images | ||
|
||
@property | ||
def raw(self) -> Optional[Dict]: | ||
return self.response_dict |
Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
gemini/models/parser/custom_parser.py → gemini/src/parser/custom_parser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
gemini/models/tools/flight.py → gemini/src/tools/google/flight.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
gemini/models/tools/hotel.py → gemini/src/tools/google/hotel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
gemini/models/tools/tool_declaimer.py → gemini/src/tools/google/tool_declaimer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.