Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(weave): Implement VertexAI integration #2743

Merged
merged 35 commits into from
Nov 26, 2024
Merged

feat(weave): Implement VertexAI integration #2743

merged 35 commits into from
Nov 26, 2024

Conversation

soumik12345
Copy link
Contributor

@soumik12345 soumik12345 commented Oct 21, 2024

Description

This PR adds the autopatch integration with VertexAI Generative Models API.

Supported cases

Sync generation

Without Streaming

import vertexai
import weave
from vertexai.generative_models import GenerativeModel

weave.init(project_name="google_ai_studio-test")
vertexai.init(project="wandb-growth", location="us-central1")
model = GenerativeModel("gemini-1.5-flash-002")
response = model.generate_content(
    "What's a good name for a flower shop specialising in selling dried flower bouquets?"
)

Sample trace

With Streaming

import vertexai
import weave
from vertexai.generative_models import GenerativeModel

weave.init(project_name="google_ai_studio-test")
vertexai.init(project="wandb-growth", location="us-central1")
model = GenerativeModel("gemini-1.5-flash-002")
response = model.generate_content(
    "What's a good name for a flower shop specialising in selling dried flower bouquets?",
    stream=True,
)

Sample trace

Async Generation

Without Streaming

import vertexai
import weave
from vertexai.generative_models import GenerativeModel

weave.init(project_name="google_ai_studio-test")
vertexai.init(project="wandb-growth", location="us-central1")
model = GenerativeModel("gemini-1.5-flash-002")

async def async_generate():
    response = await model.generate_content_async(
        "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?"
    )
    return response

response = asyncio.run(async_generate())

Sample trace

With Streaming

import vertexai
import weave
from vertexai.generative_models import GenerativeModel

weave.init(project_name="google_ai_studio-test")
vertexai.init(project="wandb-growth", location="us-central1")
model = GenerativeModel("gemini-1.5-flash-002")

async def get_response():
    chunks = []
    async for chunk in await model.generate_content_async(
        "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?",
        stream=True,
    ):
        if chunk.text:
            chunks.append(chunk.text)
    return chunks

response = asyncio.run(get_response())

Sample trace

@soumik12345 soumik12345 self-assigned this Oct 21, 2024
@soumik12345 soumik12345 requested a review from a team as a code owner October 21, 2024 18:58
@soumik12345 soumik12345 marked this pull request as draft October 21, 2024 19:16
Copy link

socket-security bot commented Oct 21, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
pypi/[email protected] eval, filesystem 0 45.7 kB vertex_ai

View full report↗︎

@soumik12345 soumik12345 changed the title feat(weave): Implement VertexAI implementation feat(weave): Implement VertexAI integration Oct 21, 2024

trace_name = op_name_from_ref(call.op_name)
assert trace_name == "vertexai.GenerativeModel.generate_content"
assert call.output is not None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make a more relevant assert using a mock? This is just checking if anything populated at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added cassettes for test_content_generation and test_content_generation_stream. However, I'm unable to generate them for test_content_generation_async and test_content_generation_async_stream.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do cassettes work here? I thought this used the google grpc stuff under the hood?

In the case where they don't work, you (or gpt!) will need to mock out the request/response manually

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewtruong Do you mean that we need to write the cassettes manually for those specific functions? Or is there another way?

@soumik12345 soumik12345 marked this pull request as ready for review October 28, 2024 21:29
@andrewtruong
Copy link
Collaborator

It's unfortunate we can't use VCRpy here. Instead of mocking, you can put a 5x retry on the test. It's not great, but given how fast these things move it might be the best option

@andrewtruong
Copy link
Collaborator

Your pytest markers should be called flaky -- see example: https://github.com/wandb/weave/blame/master/tests/integrations/google_ai_studio/google_ai_studio_test.py#L50

Copy link
Collaborator

@andrewtruong andrewtruong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with the understanding that you have thoroughly checked the integration since these tests are skipped

@soumik12345 soumik12345 merged commit b89825e into master Nov 26, 2024
120 checks passed
@soumik12345 soumik12345 deleted the feat/vertexai branch November 26, 2024 02:47
@github-actions github-actions bot locked and limited conversation to collaborators Nov 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants