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

Adding support for vextex and gemini #788

Open
PierreColombo opened this issue Jan 8, 2025 · 1 comment
Open

Adding support for vextex and gemini #788

PierreColombo opened this issue Jan 8, 2025 · 1 comment

Comments

@PierreColombo
Copy link

PierreColombo commented Jan 8, 2025

Hello,

I see that you currently support clients like Anthropic, OpenAI, and Bedrock. We would love to see Vertex AI added as a supported client. Google has made a strong comeback in the LLM space with a leading model that excels in many use cases, including ours.

Do you think this could be made possible?

Best regards,
Pierre

@alexmojaki
Copy link
Contributor

Experimenting with this, this code:

import vertexai
from vertexai.generative_models import GenerativeModel

import logfire

logfire.configure(scrubbing=False)
vertexai.init()


original_generate_content = GenerativeModel._generate_content


def instrumented_generate_content(self: GenerativeModel, contents, *args, **kwargs):
    with logfire.span('generate_content', request=contents) as span:
        result = original_generate_content(self, contents, *args, **kwargs)
        span.set_attribute('response', result)
        return result


GenerativeModel._generate_content = instrumented_generate_content

model = GenerativeModel('gemini-1.5-flash-002')

chat = model.start_chat()
chat.send_message('What is 2+2?')
chat.send_message('really?')

on the branch of #799

produces:

{
  "request": [
    {
      "role": "user",
      "parts": [
        {
          "text": "What is 2+2?"
        }
      ]
    },
    {
      "role": "model",
      "parts": [
        {
          "text": "2 + 2 = 4\n"
        }
      ]
    },
    {
      "role": "user",
      "parts": [
        {
          "text": "really?"
        }
      ]
    }
  ],
  "response": {
    "candidates": [
      {
        "content": {
          "role": "model",
          "parts": [
            {
              "text": "Yes, really.  2 + 2 = 4 is a fundamental fact of arithmetic.\n"
            }
          ]
        },
        "finish_reason": "STOP",
        "avg_logprobs": -0.08722147345542908
      }
    ],
    "usage_metadata": {
      "prompt_token_count": 17,
      "candidates_token_count": 20,
      "total_token_count": 37
    },
    "model_version": "gemini-1.5-flash-002"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants