-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Vertex AI Gemini Pro (#185)
* update to LiteLLM 1.14.1 with Gemini support * add third-party service credential handling pattern - add GCP credential handling for Vertex AI * add Gemini Pro model settings * docs: Vertex AI credentials creation.
- Loading branch information
Showing
13 changed files
with
614 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Configuration | ||
|
||
- [LLM Service Configuration](./llm-config.md) | ||
- [Configure Spaces](./config-spaces.md) | ||
- [Configure File Storage Services](./file-storage-services.md) |
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,33 @@ | ||
# LLM Configuration | ||
|
||
Currently all supported LLM services are configured when Docq is deployed/started via environment variables. | ||
|
||
These are documented in [/misc/docker.env.template](https://github.com/docqai/docq/blob/main/misc/docker.env.template). | ||
|
||
Find a little bit more information on how to get these credentials from each respective service. | ||
|
||
???+ warning | ||
In production, set secrets values in the shell. e.g. `set SOME_API_KEY=<your secret api key value>`. | ||
|
||
A tool like Infisical helps manage this process while keeping your secret values safe. | ||
|
||
## OpenAI | ||
|
||
- Sign up for an OpenAI account. Generate an API key | ||
|
||
## Azure OpenAI | ||
|
||
Assumes you have an Azure subscription | ||
|
||
- If using the all in one ARM template to deploy Docq these env vars are set securely for you. | ||
- If using and existing deployment or click-ops deployment. Login to your Azure console. Navigate to your Azure OpenAI deployment to find the required values. | ||
|
||
## Vertex AI (PaLm2 and Gemini Pro) | ||
|
||
Assumes you have a GCP account. | ||
|
||
- Login to your GCP console. | ||
- You can either select an existing GCP project or create a new one. | ||
- Navigate to 'IAM and Admin' > 'Service Accounts'. Create a new service account. You may also use an existing one. | ||
- Assign the SA account the 'Vertex AI User' role. | ||
- switch to the 'Keys' tab > 'Add key' > 'Create new key'. This will generate a credentials.json file. Copy the entire content of this file and set the env var. |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "docq" | ||
version = "0.7.1" | ||
version = "0.7.2" | ||
description = "Docq.AI - private and secure knowledge insight on your data." | ||
authors = ["Docq.AI Team <[email protected]>"] | ||
maintainers = ["Docq.AI Team <[email protected]>"] | ||
|
@@ -47,9 +47,12 @@ google-api-python-client = "^2.104.0" | |
google-auth-httplib2 = "^0.1.1" | ||
microsoftgraph-python = "^1.1.6" | ||
llama-index = "^0.9.8.post1" | ||
litellm = "^1.7.7" | ||
pydantic = "^2.5.2" | ||
mkdocs-material = "^9.4.14" | ||
google-cloud-aiplatform = "^1.38.0" | ||
litellm = "^1.14.1" | ||
opentelemetry-instrumentation-httpx = "0.41b0" | ||
opentelemetry-instrumentation-system-metrics = "0.41b0" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
pre-commit = "^2.18.1" | ||
|
@@ -179,6 +182,11 @@ cmd = "opentelemetry-instrument --logs_exporter none streamlit run web/index.py | |
args = [{ name = "port", default = 8501, type = "integer" }] | ||
env = { WATCHDOG_LOG_LEVEL = "ERROR", PYTHONPATH = "${PWD}/web/:${PWD}/source/:${PWD}/../docq-extensions/source/" } | ||
|
||
[tool.poe.tasks.run-otel-infisical] | ||
cmd = "infisical run --env=dev -- opentelemetry-instrument --logs_exporter none streamlit run web/index.py --server.port $port --browser.gatherUsageStats false --server.runOnSave true --server.fileWatcherType auto" | ||
args = [{ name = "port", default = 8501, type = "integer" }] | ||
env = { WATCHDOG_LOG_LEVEL = "ERROR", PYTHONPATH = "${PWD}/web/:${PWD}/source/:${PWD}/../docq-extensions/source/" } | ||
|
||
[tool.poe.tasks.docker-build] | ||
cmd = """ | ||
docker build | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Utils to help handle credentials for various third-party services. | ||
If you there are credentials that needs to be written to a file or set to a different environment variable, this is the place to do it. | ||
If a credentials object/json needs to be constructed from values in env vars or other sources, this is the place to do it. | ||
""" | ||
import os | ||
from typing import Optional | ||
|
||
from opentelemetry import trace | ||
|
||
from .google_drive import CREDENTIALS_KEY | ||
|
||
tracer = trace.get_tracer(__name__) | ||
|
||
|
||
def load_gcp_credentials_from_env_var(save_path: Optional[str] = None) -> bool: | ||
"""Saves credentials json from an env var to a file for services that only accept a file path. | ||
Args: | ||
save_path (str): Path inc filename to save the credentials JSON to. Default `./.streamlit/gcp_credentials.json` | ||
""" | ||
span = trace.get_current_span() | ||
|
||
DOCQ_GOOGLE_APPLICATION_CREDENTIALS_JSON = "DOCQ_GOOGLE_APPLICATION_CREDENTIALS_JSON" # noqa: N806 | ||
|
||
success = False | ||
credentials_json = f"<env var {DOCQ_GOOGLE_APPLICATION_CREDENTIALS_JSON} not set>" | ||
try: | ||
credentials_json = os.environ[DOCQ_GOOGLE_APPLICATION_CREDENTIALS_JSON] | ||
except KeyError as e: | ||
success = False | ||
span.add_event(f"Failed to access env var {DOCQ_GOOGLE_APPLICATION_CREDENTIALS_JSON}", attributes={"error": str(e)}) | ||
span.record_exception(e) | ||
|
||
path = save_path or "./.streamlit/gcp_credentials.json" | ||
|
||
try: | ||
with open(path, "w") as f: | ||
f.write(credentials_json) | ||
success = True | ||
span.add_event("Wrote GCP credentials to file successfully", attributes={"file_path": path}) | ||
except IOError as e: | ||
success = False | ||
span.add_event("Failed to write GCP credentials to file", attributes={"error": str(e), "file_path": path}) | ||
span.record_exception(e) | ||
|
||
# note: this will only be available to the current process thread. coroutine code will not have access. | ||
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = path # default GCP env var | ||
os.environ[CREDENTIALS_KEY] = path # used by the google_drive.py module. | ||
|
||
return success | ||
|
||
def setup_all_service_credentials() -> None: | ||
"""Setup all service credentials.""" | ||
with tracer.start_as_current_span("docq.services.credential_utils.setup_all_service_credentials") as span: | ||
load_gcp_credentials_from_env_var() | ||
span.add_event("GCP credentials loaded") |
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