diff --git a/llama-index-integrations/readers/llama-index-readers-gpt-repo/llama_index/readers/gpt_repo/base.py b/llama-index-integrations/readers/llama-index-readers-gpt-repo/llama_index/readers/gpt_repo/base.py index 1c2683294cfb5eb7729f10551969aa7f3be35a07..409d2df2a15c688af4aa43a5a60dafe07274afec 100644 --- a/llama-index-integrations/readers/llama-index-readers-gpt-repo/llama_index/readers/gpt_repo/base.py +++ b/llama-index-integrations/readers/llama-index-readers-gpt-repo/llama_index/readers/gpt_repo/base.py @@ -58,6 +58,7 @@ def process_repository( ignore_list, concatenate: bool = False, extensions: Optional[List[str]] = None, + encoding: Optional[str] = "utf-8", ) -> List[str]: """Process repository.""" result_texts = [] @@ -74,7 +75,7 @@ def process_repository( not should_ignore(relative_file_path, ignore_list) and is_correct_extension ): - with open(file_path, errors="ignore") as file: + with open(file_path, errors="ignore", encoding=encoding) as file: contents = file.read() result_text += "-" * 4 + "\n" result_text += f"{relative_file_path}\n" @@ -105,6 +106,7 @@ class GPTRepoReader(BaseReader): repo_path: str, preamble_str: Optional[str] = None, extensions: Optional[List[str]] = None, + encoding: Optional[str] = "utf-8", ) -> List[Document]: """Load data from the input directory. @@ -146,7 +148,11 @@ class GPTRepoReader(BaseReader): "aforementioned file as context.\n" ) text_list = process_repository( - repo_path, ignore_list, concatenate=self.concatenate, extensions=extensions + repo_path, + ignore_list, + concatenate=self.concatenate, + extensions=extensions, + encoding=encoding, ) docs = [] for text in text_list: diff --git a/llama-index-legacy/llama_index/legacy/embeddings/gemini.py b/llama-index-legacy/llama_index/legacy/embeddings/gemini.py index 67278a3be97437f49197a219d6e1c82d70928848..838fa1447d04b029801e51779289a2f411b692ce 100644 --- a/llama-index-legacy/llama_index/legacy/embeddings/gemini.py +++ b/llama-index-legacy/llama_index/legacy/embeddings/gemini.py @@ -47,7 +47,17 @@ class GeminiEmbedding(BaseEmbedding): "google-generativeai package not found, install with" "'pip install google-generativeai'" ) - gemini.configure(api_key=api_key) + # API keys are optional. The API can be authorised via OAuth (detected + # environmentally) or by the GOOGLE_API_KEY environment variable. + config_params: Dict[str, Any] = { + "api_key": api_key or os.getenv("GOOGLE_API_KEY"), + } + if api_base: + config_params["client_options"] = {"api_endpoint": api_base} + if transport: + config_params["transport"] = transport + # transport: A string, one of: [`rest`, `grpc`, `grpc_asyncio`]. + gemini.configure(**config_params) self._model = gemini super().__init__(