Skip to content

Commit

Permalink
feat: add default_headers to Gemini model (run-llama#15141)
Browse files Browse the repository at this point in the history
* feat: add default_headers to Gemini model

Similar to [OpenAI](https://github.com/run-llama/llama_index/blob/9900560183a2e212515e6273e63159316e056e96/llama-index-integrations/llms/llama-index-llms-openai/llama_index/llms/openai/base.py#L190-L192), allow `default_headers` for Gemini model as well

* Update llama-index-integrations/llms/llama-index-llms-gemini/llama_index/llms/gemini/base.py

Co-authored-by: Massimiliano Pippi <[email protected]>

* Update pyproject.toml

---------

Co-authored-by: Massimiliano Pippi <[email protected]>
  • Loading branch information
2 people authored and Josephrp committed Aug 6, 2024
1 parent da2f3fa commit 70456ec
Show file tree
Hide file tree
Showing 12 changed files with 531 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def __init__(
api_base: Optional[str] = None,
transport: Optional[str] = None,
model_name: Optional[str] = None,
default_headers: Optional[Dict[str, str]] = None,
**generate_kwargs: Any,
):
"""Creates a new Gemini model interface."""
Expand Down Expand Up @@ -123,6 +124,13 @@ def __init__(
config_params["client_options"] = {"api_endpoint": api_base}
if transport:
config_params["transport"] = transport
if default_headers:
default_metadata: Sequence[Dict[str, str]] = []
for key, value in default_headers.items():
default_metadata.append((key, value))
# `default_metadata` contains (key, value) pairs that will be sent with every request.
# When using `transport="rest"`, these will be sent as HTTP headers.
config_params["default_metadata"] = default_metadata
# transport: A string, one of: [`rest`, `grpc`, `grpc_asyncio`].
genai.configure(**config_params)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-llms-gemini"
readme = "README.md"
version = "0.1.12"
version = "0.2.0"

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Expand Down
153 changes: 153 additions & 0 deletions llama-index-integrations/llms/llama-index-llms-githubllm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
llama_index/_static
.DS_Store
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
bin/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
etc/
include/
lib/
lib64/
parts/
sdist/
share/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
.ruff_cache

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints
notebooks/

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
pyvenv.cfg

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Jetbrains
.idea
modules/
*.swp

# VsCode
.vscode

# pipenv
Pipfile
Pipfile.lock

# pyright
pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_sources()
17 changes: 17 additions & 0 deletions llama-index-integrations/llms/llama-index-llms-githubllm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
GIT_ROOT ?= $(shell git rev-parse --show-toplevel)

help: ## Show all Makefile targets.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'

format: ## Run code autoformatters (black).
pre-commit install
git ls-files | xargs pre-commit run black --files

lint: ## Run linters: pre-commit (black, ruff, codespell) and mypy
pre-commit install && git ls-files | xargs pre-commit run --show-diff-on-failure --files

test: ## Run tests via pytest.
pytest tests

watch-docs: ## Build and watch documentation.
sphinx-autobuild docs/ docs/_build/html --open-browser --watch $(GIT_ROOT)/llama_index/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# LlamaIndex Llms Integration: Githubllm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_sources()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from llama_index.llms.githubllm.base import GithubLLM


__all__ = ["GithubLLM"]
Loading

0 comments on commit 70456ec

Please sign in to comment.