test_vertex.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from unittest.mock import patch
  2. from sentry.llm.usecases import LLMUseCase, complete_prompt
  3. def test_complete_prompt(set_sentry_option):
  4. with (
  5. set_sentry_option(
  6. "llm.provider.options",
  7. {"vertex": {"models": ["vertex-1.0"], "options": {"url": "fake_url"}}},
  8. ),
  9. set_sentry_option(
  10. "llm.usecases.options",
  11. {"example": {"provider": "vertex", "options": {"model": "vertex-1.0"}}},
  12. ),
  13. patch(
  14. "sentry.llm.providers.vertex.VertexProvider._get_access_token",
  15. return_value="fake_token",
  16. ),
  17. patch(
  18. "requests.post",
  19. return_value=type(
  20. "obj",
  21. (object,),
  22. {"status_code": 200, "json": lambda x: {"predictions": [{"content": ""}]}},
  23. )(),
  24. ),
  25. ):
  26. res = complete_prompt(
  27. usecase=LLMUseCase.EXAMPLE,
  28. prompt="prompt here",
  29. message="message here",
  30. temperature=0.0,
  31. max_output_tokens=1024,
  32. )
  33. assert res == ""