forked from open-telemetry/opentelemetry-python-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working sanitized VCR for tests, but missing some assertions
- Loading branch information
Showing
4 changed files
with
169 additions
and
53 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...telemetry-instrumentation-vertexai-v2/tests/cassettes/test_vertexai_generate_content.yaml
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 @@ | ||
interactions: | ||
- request: | ||
body: "{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": | ||
[\n {\n \"fileData\": {\n \"mimeType\": \"image/jpeg\",\n | ||
\ \"fileUri\": \"gs://generativeai-downloads/images/scones.jpg\"\n | ||
\ }\n },\n {\n \"text\": \"what is shown in this | ||
image?\"\n }\n ]\n }\n ]\n}" | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '317' | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- python-requests/2.32.3 | ||
method: POST | ||
uri: https://us-central1-aiplatform.googleapis.com/v1beta1/projects/fake-project/locations/us-central1/publishers/google/models/gemini-pro-vision:generateContent?%24alt=json%3Benum-encoding%3Dint | ||
response: | ||
body: | ||
string: "{\n \"candidates\": [\n {\n \"content\": {\n \"role\": | ||
\"model\",\n \"parts\": [\n {\n \"text\": \" The | ||
image shows a table with a cup of coffee, a bowl of blueberries, and several | ||
blueberry scones. There are also pink flowers on the table.\"\n }\n | ||
\ ]\n },\n \"finishReason\": 1,\n \"safetyRatings\": | ||
[\n {\n \"category\": 1,\n \"probability\": 1,\n | ||
\ \"probabilityScore\": 0.024780273,\n \"severity\": 1,\n | ||
\ \"severityScore\": 0.072753906\n },\n {\n \"category\": | ||
2,\n \"probability\": 1,\n \"probabilityScore\": 0.025512695,\n | ||
\ \"severity\": 1,\n \"severityScore\": 0.06738281\n },\n | ||
\ {\n \"category\": 3,\n \"probability\": 1,\n \"probabilityScore\": | ||
0.040283203,\n \"severity\": 1,\n \"severityScore\": 0.03515625\n | ||
\ },\n {\n \"category\": 4,\n \"probability\": | ||
1,\n \"probabilityScore\": 0.07910156,\n \"severity\": 1,\n | ||
\ \"severityScore\": 0.083984375\n }\n ],\n \"avgLogprobs\": | ||
-0.068832365671793613\n }\n ],\n \"usageMetadata\": {\n \"promptTokenCount\": | ||
265,\n \"candidatesTokenCount\": 30,\n \"totalTokenCount\": 295\n },\n | ||
\ \"modelVersion\": \"gemini-pro-vision\"\n}\n" | ||
headers: | ||
Cache-Control: | ||
- private | ||
Content-Encoding: | ||
- gzip | ||
Content-Type: | ||
- application/json; charset=UTF-8 | ||
Transfer-Encoding: | ||
- chunked | ||
Vary: | ||
- Origin | ||
- X-Origin | ||
- Referer | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
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
52 changes: 0 additions & 52 deletions
52
...rumentation-genai/opentelemetry-instrumentation-vertexai-v2/tests/disabled_test_gemini.py
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
instrumentation-genai/opentelemetry-instrumentation-vertexai-v2/tests/test_gemini.py
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,50 @@ | ||
import pytest | ||
from vertexai.preview.generative_models import GenerativeModel, Part | ||
|
||
# from opentelemetry.semconv_ai import SpanAttributes | ||
|
||
|
||
@pytest.mark.vcr | ||
def test_vertexai_generate_content(exporter): | ||
multimodal_model = GenerativeModel("gemini-pro-vision") | ||
response = multimodal_model.generate_content( | ||
[ | ||
Part.from_uri( | ||
"gs://generativeai-downloads/images/scones.jpg", | ||
mime_type="image/jpeg", | ||
), | ||
"what is shown in this image?", | ||
] | ||
) | ||
|
||
spans = exporter.get_finished_spans() | ||
assert [span.name for span in spans] == [ | ||
"text_completion gemini-pro-vision" | ||
] | ||
|
||
vertexai_span = spans[0] | ||
assert len(spans) == 1 | ||
# assert ( | ||
# "what is shown in this image?" | ||
# in vertexai_span.attributes[f"{SpanAttributes.LLM_PROMPTS}.0.user"] | ||
# ) | ||
# assert ( | ||
# vertexai_span.attributes[SpanAttributes.LLM_REQUEST_MODEL] | ||
# == "gemini-pro-vision" | ||
# ) | ||
# assert ( | ||
# vertexai_span.attributes[SpanAttributes.LLM_USAGE_TOTAL_TOKENS] | ||
# == response._raw_response.usage_metadata.total_token_count | ||
# ) | ||
# assert ( | ||
# vertexai_span.attributes[SpanAttributes.LLM_USAGE_PROMPT_TOKENS] | ||
# == response._raw_response.usage_metadata.prompt_token_count | ||
# ) | ||
# assert ( | ||
# vertexai_span.attributes[SpanAttributes.LLM_USAGE_COMPLETION_TOKENS] | ||
# == response._raw_response.usage_metadata.candidates_token_count | ||
# ) | ||
# assert ( | ||
# vertexai_span.attributes[f"{SpanAttributes.LLM_COMPLETIONS}.0.content"] | ||
# == response.text | ||
# ) |