Skip to content

Conversation

mrDzurb
Copy link
Member

@mrDzurb mrDzurb commented Jan 3, 2025

Description

This PR introduces a centralized and reusable client for interacting with OCI Model Deployment. The primary motivation for this development is to address redundancy and streamline integrations with third-party frameworks like LangChain, LlamaIndex, evaluation, and other frameworks. By centralizing the client functionality within the Oracle-ADS library, we establish a single source of truth for managing and modifying the client, ensuring consistency and maintainability across all integrations.

Implementation Highlights:

  • Provides both synchronous (Client) and asynchronous (AsyncClient) implementations using httpx library.
  • Implements a custom OCIAuth authentication mechanism, fully integrated with OCI Signer for secure and compliant communication.
  • Leverages the tenacity library for configurable retry behavior, enabling robust handling of transient errors.

Usage

Sync

Text Completion

from ads.aqua.client.client import Client
ads.set_auth(auth="security_token", profile="<replace-with-your-profile>")

client = Client(endpoint="https://<MD_OCID>/predict")
response = client.generate(
    prompt="Tell me a joke",
    payload={"model":"odsc-llm"},
    stream=False,
)
print(response)

Chat Completion

from ads.aqua.client.client import Client
ads.set_auth(auth="security_token", profile="<replace-with-your-profile>")

client = Client(endpoint="https://<MD_OCID>/predict")
response = client.generate(
    messages=[{"role": "user", "content": "Tell me a joke."}],
    payload={"model":"odsc-llm"},
    stream=False,
)
print(response)

Streaming

from ads.aqua.client.client import Client
ads.set_auth(auth="security_token", profile="<replace-with-your-profile>")

client = Client(endpoint="https://<MD_OCID>/predict")
response = client.generate(
    messages=[{"role": "user", "content": "Tell me a joke."}],
    payload={"model":"odsc-llm"},
    stream=True,
)

for chunk in response:
  print(chunk)

Embedding

from ads.aqua.client.client import Client
ads.set_auth(auth="security_token", profile="<replace-with-your-profile>")

client = Client(endpoint="https://<MD_OCID>/predict")
response = client.embeddings(
     input = ["one", "two"]
)

print(response)

Async

Text Completion

from ads.aqua.client.client import AsyncClient
ads.set_auth(auth="security_token", profile="<replace-with-your-profile>")

client = AsyncClient(endpoint="https://<MD_OCID>/predict")
response = await client.generate(
    prompt="Tell me a joke",
    payload={"model":"odsc-llm"},
    stream=False,
)
print(response)

Streaming

from ads.aqua.client.client import AsyncClient
ads.set_auth(auth="security_token", profile="<replace-with-your-profile>")

client = AsyncClient(endpoint="https://<MD_OCID>/predict")
async for chunk in await client.generate(
    prompt="Tell me a joke",
    payload={"model":"odsc-llm"},
    stream=True,
):
    print(chunk)

Embedding

from ads.aqua.client.client import AsyncClient
ads.set_auth(auth="security_token", profile="<replace-with-your-profile>")

client = AsyncClient(endpoint="https://<MD_OCID>/predict")
response = await client.embeddings(
     input = ["one", "two"]
)

print(response)

Tests

image

NB Example

llama_index_test_client.ipynb.zip

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jan 3, 2025
Copy link

github-actions bot commented Jan 3, 2025

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.

Copy link

github-actions bot commented Jan 3, 2025

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.

darenr
darenr previously approved these changes Jan 3, 2025
Copy link

github-actions bot commented Jan 3, 2025

📌 Cov diff with main:

Coverage-0%

📌 Overall coverage:

Coverage-20.00%

1 similar comment
Copy link

github-actions bot commented Jan 6, 2025

📌 Cov diff with main:

Coverage-0%

📌 Overall coverage:

Coverage-20.00%

qiuosier
qiuosier previously approved these changes Jan 6, 2025
@mrDzurb mrDzurb dismissed stale reviews from qiuosier and darenr via 4506995 January 7, 2025 23:15
Copy link

github-actions bot commented Jan 7, 2025

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.

Copy link

github-actions bot commented Jan 7, 2025

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.

Copy link

github-actions bot commented Jan 7, 2025

📌 Cov diff with main:

Coverage-91%

📌 Overall coverage:

Coverage-57.49%

@mrDzurb mrDzurb requested review from qiuosier and darenr January 8, 2025 01:10
@mrDzurb mrDzurb enabled auto-merge January 8, 2025 17:52
Copy link

github-actions bot commented Jan 8, 2025

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.

@mrDzurb mrDzurb disabled auto-merge January 8, 2025 17:54
Copy link

github-actions bot commented Jan 8, 2025

📌 Cov diff with main:

Coverage-91%

📌 Overall coverage:

Coverage-57.48%

Copy link

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.

Copy link

📌 Cov diff with main:

Coverage-91%

📌 Overall coverage:

Coverage-57.48%

Copy link

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.

Copy link

📌 Cov diff with main:

Coverage-91%

📌 Overall coverage:

Coverage-56.73%

@mrDzurb mrDzurb enabled auto-merge February 1, 2025 00:57
@mrDzurb mrDzurb merged commit 6a9fe42 into main Feb 1, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants