langfun 0.1.2.dev202501150804__tar.gz → 0.1.2.dev202501170804__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/PKG-INFO +1 -1
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/__init__.py +0 -1
- langfun-0.1.2.dev202501170804/langfun/core/component.py +90 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/component_test.py +2 -29
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/concurrent.py +3 -17
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/concurrent_test.py +0 -16
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/__init__.py +14 -6
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/anthropic.py +1 -123
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/anthropic_test.py +0 -48
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/vertexai.py +108 -17
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/vertexai_test.py +52 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun.egg-info/PKG-INFO +1 -1
- langfun-0.1.2.dev202501150804/langfun/core/component.py +0 -352
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/LICENSE +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/README.md +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/__init__.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/agentic/__init__.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/agentic/action.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/agentic/action_eval.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/agentic/action_eval_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/agentic/action_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/coding/__init__.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/coding/python/__init__.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/coding/python/correction.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/coding/python/correction_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/coding/python/execution.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/coding/python/execution_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/coding/python/generation.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/coding/python/generation_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/coding/python/parsing.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/coding/python/parsing_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/console.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/console_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/__init__.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/base.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/base_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/matching.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/matching_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/patching.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/patching_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/scoring.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/scoring_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/__init__.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/checkpointing.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/checkpointing_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/eval_test_helper.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/evaluation.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/evaluation_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/example.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/example_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/experiment.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/experiment_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/metric_values.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/metric_values_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/metrics.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/metrics_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/progress.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/progress_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/progress_tracking.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/progress_tracking_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/reporting.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/reporting_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/runners.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/eval/v2/runners_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/langfunc.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/langfunc_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/language_model.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/language_model_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/cache/__init__.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/cache/base.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/cache/in_memory.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/cache/in_memory_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/compositional.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/compositional_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/deepseek.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/deepseek_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/fake.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/fake_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/gemini.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/gemini_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/google_genai.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/google_genai_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/groq.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/groq_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/llama_cpp.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/llama_cpp_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/openai.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/openai_compatible.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/openai_compatible_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/openai_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/rest.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/rest_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/logging.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/logging_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/memories/__init__.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/memories/conversation_history.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/memories/conversation_history_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/memory.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/message.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/message_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/__init__.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/audio.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/audio_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/image.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/image_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/mime.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/mime_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/ms_office.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/ms_office_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/pdf.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/pdf_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/video.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modalities/video_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modality.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/modality_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/natural_language.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/natural_language_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/sampling.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/sampling_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/__init__.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/completion.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/completion_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/description.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/description_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/function_generation.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/function_generation_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/mapping.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/mapping_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/parsing.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/parsing_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/querying.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/querying_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/schema.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/schema_generation.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/schema_generation_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/schema_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/scoring.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/scoring_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/tokenization.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/structured/tokenization_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/subscription.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/subscription_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/template.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/template_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/templates/__init__.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/templates/completion.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/templates/completion_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/templates/conversation.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/templates/conversation_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/templates/demonstration.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/templates/demonstration_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/templates/selfplay.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/templates/selfplay_test.py +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun.egg-info/SOURCES.txt +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun.egg-info/dependency_links.txt +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun.egg-info/requires.txt +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun.egg-info/top_level.txt +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/setup.cfg +0 -0
- {langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/setup.py +0 -0
@@ -75,7 +75,6 @@ from langfun.core.sampling import random_sample
|
|
75
75
|
from langfun.core.concurrent import RetryEntry
|
76
76
|
from langfun.core.concurrent import concurrent_execute
|
77
77
|
from langfun.core.concurrent import concurrent_map
|
78
|
-
from langfun.core.concurrent import with_context_access
|
79
78
|
from langfun.core.concurrent import with_retry
|
80
79
|
|
81
80
|
# Interface for natural language formattable.
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Copyright 2023 The Langfun Authors
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
"""langfun Component."""
|
15
|
+
|
16
|
+
from typing import ContextManager
|
17
|
+
import pyglove as pg
|
18
|
+
|
19
|
+
|
20
|
+
# Default value marker that indicates to raise error.
|
21
|
+
RAISE_IF_HAS_ERROR = (pg.MISSING_VALUE,)
|
22
|
+
|
23
|
+
|
24
|
+
class Component(pg.ContextualObject):
|
25
|
+
"""Base class for langfun components."""
|
26
|
+
|
27
|
+
# Allow symbolic assignment, which invalidates the object and recomputes
|
28
|
+
# states upon update.
|
29
|
+
allow_symbolic_assignment = True
|
30
|
+
|
31
|
+
# Class property that indicates whether to use `sym_eq` for `__eq__`,
|
32
|
+
# `sym_ne` for `__ne__`, and `sym_hash` for `__hash__`.
|
33
|
+
use_symbolic_comparison = False
|
34
|
+
|
35
|
+
def __init_subclass__(cls):
|
36
|
+
super().__init_subclass__()
|
37
|
+
|
38
|
+
# Find class attributes that do not have annotations but are `Component`,
|
39
|
+
# and treat them as symbolic fields.
|
40
|
+
additional_fields = []
|
41
|
+
for attr_name in dir(cls):
|
42
|
+
if (
|
43
|
+
attr_name.startswith('_')
|
44
|
+
or attr_name.isupper()
|
45
|
+
or attr_name in cls.__schema__.fields
|
46
|
+
):
|
47
|
+
continue
|
48
|
+
attr_value = getattr(cls, attr_name)
|
49
|
+
if isinstance(attr_value, pg.Inferentiable):
|
50
|
+
value_spec = pg.typing.Any()
|
51
|
+
elif isinstance(attr_value, Component):
|
52
|
+
value_spec = pg.typing.Object(Component)
|
53
|
+
else:
|
54
|
+
value_spec = None
|
55
|
+
if value_spec:
|
56
|
+
field = pg.typing.create_field((attr_name, value_spec))
|
57
|
+
field.value.set_default(attr_value)
|
58
|
+
additional_fields.append(field)
|
59
|
+
if additional_fields:
|
60
|
+
cls.update_schema(additional_fields)
|
61
|
+
|
62
|
+
|
63
|
+
# Aliases from PyGlove for ease of access.
|
64
|
+
context = pg.contextual_override
|
65
|
+
get_contextual_override = pg.utils.get_contextual_override
|
66
|
+
context_value = pg.utils.contextual_value
|
67
|
+
all_contextual_values = pg.utils.all_contextual_values
|
68
|
+
contextual = pg.contextual_attribute
|
69
|
+
|
70
|
+
# Decorator for setting the positional arguments for Component.
|
71
|
+
use_init_args = pg.use_init_args
|
72
|
+
|
73
|
+
|
74
|
+
def use_settings(
|
75
|
+
*,
|
76
|
+
cascade: bool = False,
|
77
|
+
**settings,
|
78
|
+
) -> ContextManager[dict[str, pg.utils.ContextualOverride]]:
|
79
|
+
"""Shortcut method for overriding component attributes.
|
80
|
+
|
81
|
+
Args:
|
82
|
+
cascade: If True, this override will apply to both current scope and nested
|
83
|
+
scope, meaning that this `lf.context` will take precedence over all
|
84
|
+
nested `lf.context` on the overriden variables.
|
85
|
+
**settings: Key/values as override for component attributes.
|
86
|
+
|
87
|
+
Returns:
|
88
|
+
A dict of attribute names to their contextual overrides.
|
89
|
+
"""
|
90
|
+
return context(cascade=cascade, override_attrs=True, **settings)
|
{langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/component_test.py
RENAMED
@@ -73,26 +73,7 @@ class ComponentContextTest(unittest.TestCase):
|
|
73
73
|
self.assertEqual(a1.y, 2)
|
74
74
|
self.assertEqual(a1.z, -1)
|
75
75
|
|
76
|
-
with lf.context(x=3, y=3, z=3)
|
77
|
-
self.assertEqual(
|
78
|
-
parent_override,
|
79
|
-
dict(
|
80
|
-
x=lf.ContextualOverride(3, cascade=False, override_attrs=False),
|
81
|
-
y=lf.ContextualOverride(3, cascade=False, override_attrs=False),
|
82
|
-
z=lf.ContextualOverride(3, cascade=False, override_attrs=False),
|
83
|
-
),
|
84
|
-
)
|
85
|
-
self.assertEqual(
|
86
|
-
lf.get_contextual_override('y'),
|
87
|
-
lf.ContextualOverride(3, cascade=False, override_attrs=False),
|
88
|
-
)
|
89
|
-
self.assertEqual(lf.context_value('x'), 3)
|
90
|
-
self.assertIsNone(lf.context_value('f', None))
|
91
|
-
with self.assertRaisesRegex(KeyError, '.* does not exist'):
|
92
|
-
lf.context_value('f')
|
93
|
-
|
94
|
-
self.assertEqual(lf.all_contextual_values(), dict(x=3, y=3, z=3))
|
95
|
-
|
76
|
+
with lf.context(x=3, y=3, z=3):
|
96
77
|
# Member attributes take precedence over `lf.context`.
|
97
78
|
self.assertEqual(a1.x, 1)
|
98
79
|
self.assertEqual(a1.y, 2)
|
@@ -109,15 +90,7 @@ class ComponentContextTest(unittest.TestCase):
|
|
109
90
|
self.assertEqual(a1.z, 3)
|
110
91
|
|
111
92
|
# Test nested contextual override with override_attrs=True (default).
|
112
|
-
with lf.context(y=4, z=4, override_attrs=True)
|
113
|
-
self.assertEqual(
|
114
|
-
nested_override,
|
115
|
-
dict(
|
116
|
-
x=lf.ContextualOverride(3, cascade=False, override_attrs=False),
|
117
|
-
y=lf.ContextualOverride(4, cascade=False, override_attrs=True),
|
118
|
-
z=lf.ContextualOverride(4, cascade=False, override_attrs=True),
|
119
|
-
),
|
120
|
-
)
|
93
|
+
with lf.context(y=4, z=4, override_attrs=True):
|
121
94
|
|
122
95
|
# Member attribute is not overriden as current scope does not override
|
123
96
|
# `x``.
|
@@ -25,7 +25,6 @@ import threading
|
|
25
25
|
import time
|
26
26
|
from typing import Annotated, Any, Callable, Iterable, Iterator, Literal, Sequence, Tuple, Type, Union
|
27
27
|
|
28
|
-
from langfun.core import component
|
29
28
|
import pyglove as pg
|
30
29
|
|
31
30
|
|
@@ -39,18 +38,6 @@ except ImportError:
|
|
39
38
|
tqdm = None
|
40
39
|
|
41
40
|
|
42
|
-
def with_context_access(func: Callable[..., Any]) -> Callable[..., Any]:
|
43
|
-
"""Derives a user function with the access to the current context."""
|
44
|
-
with component.context() as current_context:
|
45
|
-
pass
|
46
|
-
|
47
|
-
def _func(*args, **kwargs) -> Any:
|
48
|
-
with component.context(**current_context):
|
49
|
-
return func(*args, **kwargs)
|
50
|
-
|
51
|
-
return _func
|
52
|
-
|
53
|
-
|
54
41
|
class RetryError(RuntimeError):
|
55
42
|
"""Retry error."""
|
56
43
|
|
@@ -249,7 +236,8 @@ def concurrent_execute(
|
|
249
236
|
try:
|
250
237
|
executed_jobs = list(
|
251
238
|
executor.map(
|
252
|
-
lambda job: job(),
|
239
|
+
lambda job: job(),
|
240
|
+
[pg.with_contextual_override(job) for job in jobs]
|
253
241
|
)
|
254
242
|
)
|
255
243
|
for job in executed_jobs:
|
@@ -736,9 +724,7 @@ def concurrent_map(
|
|
736
724
|
retry_interval=retry_interval,
|
737
725
|
exponential_backoff=exponential_backoff,
|
738
726
|
)
|
739
|
-
future = executor.submit(
|
740
|
-
with_context_access(job),
|
741
|
-
)
|
727
|
+
future = executor.submit(pg.with_contextual_override(job))
|
742
728
|
pending_futures.append(future)
|
743
729
|
future_to_job[future] = job
|
744
730
|
total += 1
|
{langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/concurrent_test.py
RENAMED
@@ -29,22 +29,6 @@ class A(component.Component):
|
|
29
29
|
y: int = component.contextual()
|
30
30
|
|
31
31
|
|
32
|
-
class WithContextAccessTest(unittest.TestCase):
|
33
|
-
|
34
|
-
def test_context_access(self):
|
35
|
-
inputs = [A(1), A(2)]
|
36
|
-
with futures.ThreadPoolExecutor() as executor:
|
37
|
-
with component.context(y=3):
|
38
|
-
self.assertEqual(
|
39
|
-
list(
|
40
|
-
executor.map(
|
41
|
-
concurrent.with_context_access(lambda x: x.y), inputs
|
42
|
-
)
|
43
|
-
),
|
44
|
-
[3, 3],
|
45
|
-
)
|
46
|
-
|
47
|
-
|
48
32
|
class RetryErrorTest(unittest.TestCase):
|
49
33
|
|
50
34
|
def test_basics(self):
|
{langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/__init__.py
RENAMED
@@ -30,6 +30,9 @@ from langfun.core.llms.compositional import RandomChoice
|
|
30
30
|
# REST-based models.
|
31
31
|
from langfun.core.llms.rest import REST
|
32
32
|
|
33
|
+
# VertexAI-based models.
|
34
|
+
from langfun.core.llms.vertexai import VertexAI
|
35
|
+
|
33
36
|
# Gemini models.
|
34
37
|
from langfun.core.llms.google_genai import GenAI
|
35
38
|
from langfun.core.llms.google_genai import GeminiFlash2_0ThinkingExp_20241219
|
@@ -44,7 +47,7 @@ from langfun.core.llms.google_genai import GeminiFlash1_5_002
|
|
44
47
|
from langfun.core.llms.google_genai import GeminiFlash1_5_001
|
45
48
|
from langfun.core.llms.google_genai import GeminiPro1
|
46
49
|
|
47
|
-
from langfun.core.llms.vertexai import
|
50
|
+
from langfun.core.llms.vertexai import VertexAIGemini
|
48
51
|
from langfun.core.llms.vertexai import VertexAIGeminiFlash2_0ThinkingExp_20241219
|
49
52
|
from langfun.core.llms.vertexai import VertexAIGeminiFlash2_0Exp
|
50
53
|
from langfun.core.llms.vertexai import VertexAIGeminiExp_20241206
|
@@ -114,6 +117,8 @@ from langfun.core.llms.openai import Gpt3Curie
|
|
114
117
|
from langfun.core.llms.openai import Gpt3Babbage
|
115
118
|
from langfun.core.llms.openai import Gpt3Ada
|
116
119
|
|
120
|
+
# Anthropic models.
|
121
|
+
|
117
122
|
from langfun.core.llms.anthropic import Anthropic
|
118
123
|
from langfun.core.llms.anthropic import Claude35Sonnet
|
119
124
|
from langfun.core.llms.anthropic import Claude35Sonnet20241022
|
@@ -121,11 +126,14 @@ from langfun.core.llms.anthropic import Claude35Sonnet20240620
|
|
121
126
|
from langfun.core.llms.anthropic import Claude3Opus
|
122
127
|
from langfun.core.llms.anthropic import Claude3Sonnet
|
123
128
|
from langfun.core.llms.anthropic import Claude3Haiku
|
124
|
-
|
125
|
-
from langfun.core.llms.
|
126
|
-
from langfun.core.llms.
|
127
|
-
from langfun.core.llms.
|
128
|
-
from langfun.core.llms.
|
129
|
+
|
130
|
+
from langfun.core.llms.vertexai import VertexAIAnthropic
|
131
|
+
from langfun.core.llms.vertexai import VertexAIClaude3_5_Sonnet_20241022
|
132
|
+
from langfun.core.llms.vertexai import VertexAIClaude3_5_Sonnet_20240620
|
133
|
+
from langfun.core.llms.vertexai import VertexAIClaude3_5_Haiku_20241022
|
134
|
+
from langfun.core.llms.vertexai import VertexAIClaude3_Opus_20240229
|
135
|
+
|
136
|
+
# Misc open source models.
|
129
137
|
|
130
138
|
from langfun.core.llms.groq import Groq
|
131
139
|
from langfun.core.llms.groq import GroqLlama3_2_3B
|
{langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/anthropic.py
RENAMED
@@ -14,9 +14,8 @@
|
|
14
14
|
"""Language models from Anthropic."""
|
15
15
|
|
16
16
|
import base64
|
17
|
-
import functools
|
18
17
|
import os
|
19
|
-
from typing import Annotated, Any
|
18
|
+
from typing import Annotated, Any
|
20
19
|
|
21
20
|
import langfun.core as lf
|
22
21
|
from langfun.core import modalities as lf_modalities
|
@@ -24,20 +23,6 @@ from langfun.core.llms import rest
|
|
24
23
|
import pyglove as pg
|
25
24
|
|
26
25
|
|
27
|
-
try:
|
28
|
-
# pylint: disable=g-import-not-at-top
|
29
|
-
from google import auth as google_auth
|
30
|
-
from google.auth import credentials as credentials_lib
|
31
|
-
from google.auth.transport import requests as auth_requests
|
32
|
-
Credentials = credentials_lib.Credentials
|
33
|
-
# pylint: enable=g-import-not-at-top
|
34
|
-
except ImportError:
|
35
|
-
google_auth = None
|
36
|
-
auth_requests = None
|
37
|
-
credentials_lib = None
|
38
|
-
Credentials = Any # pylint: disable=invalid-name
|
39
|
-
|
40
|
-
|
41
26
|
SUPPORTED_MODELS_AND_SETTINGS = {
|
42
27
|
# See https://docs.anthropic.com/claude/docs/models-overview
|
43
28
|
# Rate limits from https://docs.anthropic.com/claude/reference/rate-limits
|
@@ -379,110 +364,3 @@ class Claude21(Anthropic):
|
|
379
364
|
class ClaudeInstant(Anthropic):
|
380
365
|
"""Cheapest small and fast model, 100K context window."""
|
381
366
|
model = 'claude-instant-1.2'
|
382
|
-
|
383
|
-
|
384
|
-
#
|
385
|
-
# Authropic models on VertexAI.
|
386
|
-
#
|
387
|
-
|
388
|
-
|
389
|
-
class VertexAIAnthropic(Anthropic):
|
390
|
-
"""Anthropic models on VertexAI."""
|
391
|
-
|
392
|
-
project: Annotated[
|
393
|
-
str | None,
|
394
|
-
'Google Cloud project ID.',
|
395
|
-
] = None
|
396
|
-
|
397
|
-
location: Annotated[
|
398
|
-
Literal['us-east5', 'europe-west1'],
|
399
|
-
'GCP location with Anthropic models hosted.'
|
400
|
-
] = 'us-east5'
|
401
|
-
|
402
|
-
credentials: Annotated[
|
403
|
-
Credentials | None, # pytype: disable=invalid-annotation
|
404
|
-
(
|
405
|
-
'Credentials to use. If None, the default credentials '
|
406
|
-
'to the environment will be used.'
|
407
|
-
),
|
408
|
-
] = None
|
409
|
-
|
410
|
-
api_version = 'vertex-2023-10-16'
|
411
|
-
|
412
|
-
def _on_bound(self):
|
413
|
-
super()._on_bound()
|
414
|
-
if google_auth is None:
|
415
|
-
raise ValueError(
|
416
|
-
'Please install "langfun[llm-google-vertex]" to use Vertex AI models.'
|
417
|
-
)
|
418
|
-
self._project = None
|
419
|
-
self._credentials = None
|
420
|
-
|
421
|
-
def _initialize(self):
|
422
|
-
project = self.project or os.environ.get('VERTEXAI_PROJECT', None)
|
423
|
-
if not project:
|
424
|
-
raise ValueError(
|
425
|
-
'Please specify `project` during `__init__` or set environment '
|
426
|
-
'variable `VERTEXAI_PROJECT` with your Vertex AI project ID.'
|
427
|
-
)
|
428
|
-
self._project = project
|
429
|
-
credentials = self.credentials
|
430
|
-
if credentials is None:
|
431
|
-
# Use default credentials.
|
432
|
-
credentials = google_auth.default(
|
433
|
-
scopes=['https://www.googleapis.com/auth/cloud-platform']
|
434
|
-
)
|
435
|
-
self._credentials = credentials
|
436
|
-
|
437
|
-
@functools.cached_property
|
438
|
-
def _session(self):
|
439
|
-
assert self._api_initialized
|
440
|
-
assert self._credentials is not None
|
441
|
-
assert auth_requests is not None
|
442
|
-
s = auth_requests.AuthorizedSession(self._credentials)
|
443
|
-
s.headers.update(self.headers or {})
|
444
|
-
return s
|
445
|
-
|
446
|
-
@property
|
447
|
-
def headers(self):
|
448
|
-
return {
|
449
|
-
'Content-Type': 'application/json; charset=utf-8',
|
450
|
-
}
|
451
|
-
|
452
|
-
@property
|
453
|
-
def api_endpoint(self) -> str:
|
454
|
-
return (
|
455
|
-
f'https://{self.location}-aiplatform.googleapis.com/v1/projects/'
|
456
|
-
f'{self._project}/locations/{self.location}/publishers/anthropic/'
|
457
|
-
f'models/{self.model}:streamRawPredict'
|
458
|
-
)
|
459
|
-
|
460
|
-
def request(
|
461
|
-
self,
|
462
|
-
prompt: lf.Message,
|
463
|
-
sampling_options: lf.LMSamplingOptions
|
464
|
-
):
|
465
|
-
request = super().request(prompt, sampling_options)
|
466
|
-
request['anthropic_version'] = self.api_version
|
467
|
-
del request['model']
|
468
|
-
return request
|
469
|
-
|
470
|
-
|
471
|
-
class VertexAIClaude3_Opus_20240229(VertexAIAnthropic): # pylint: disable=invalid-name
|
472
|
-
"""Anthropic's Claude 3 Opus model on VertexAI."""
|
473
|
-
model = 'claude-3-opus@20240229'
|
474
|
-
|
475
|
-
|
476
|
-
class VertexAIClaude3_5_Sonnet_20241022(VertexAIAnthropic): # pylint: disable=invalid-name
|
477
|
-
"""Anthropic's Claude 3.5 Sonnet model on VertexAI."""
|
478
|
-
model = 'claude-3-5-sonnet-v2@20241022'
|
479
|
-
|
480
|
-
|
481
|
-
class VertexAIClaude3_5_Sonnet_20240620(VertexAIAnthropic): # pylint: disable=invalid-name
|
482
|
-
"""Anthropic's Claude 3.5 Sonnet model on VertexAI."""
|
483
|
-
model = 'claude-3-5-sonnet@20240620'
|
484
|
-
|
485
|
-
|
486
|
-
class VertexAIClaude3_5_Haiku_20241022(VertexAIAnthropic): # pylint: disable=invalid-name
|
487
|
-
"""Anthropic's Claude 3.5 Haiku model on VertexAI."""
|
488
|
-
model = 'claude-3-5-haiku@20241022'
|
{langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/anthropic_test.py
RENAMED
@@ -19,9 +19,6 @@ from typing import Any
|
|
19
19
|
import unittest
|
20
20
|
from unittest import mock
|
21
21
|
|
22
|
-
from google.auth import exceptions
|
23
|
-
from langfun.core import language_model
|
24
|
-
from langfun.core import message as lf_message
|
25
22
|
from langfun.core import modalities as lf_modalities
|
26
23
|
from langfun.core.llms import anthropic
|
27
24
|
import pyglove as pg
|
@@ -186,50 +183,5 @@ class AnthropicTest(unittest.TestCase):
|
|
186
183
|
lm('hello', max_attempts=1)
|
187
184
|
|
188
185
|
|
189
|
-
class VertexAIAnthropicTest(unittest.TestCase):
|
190
|
-
"""Tests for VertexAI Anthropic models."""
|
191
|
-
|
192
|
-
def test_basics(self):
|
193
|
-
with self.assertRaisesRegex(ValueError, 'Please specify `project`'):
|
194
|
-
lm = anthropic.VertexAIClaude3_5_Sonnet_20241022()
|
195
|
-
lm('hi')
|
196
|
-
|
197
|
-
model = anthropic.VertexAIClaude3_5_Sonnet_20241022(project='langfun')
|
198
|
-
|
199
|
-
# NOTE(daiyip): For OSS users, default credentials are not available unless
|
200
|
-
# users have already set up their GCP project. Therefore we ignore the
|
201
|
-
# exception here.
|
202
|
-
try:
|
203
|
-
model._initialize()
|
204
|
-
except exceptions.DefaultCredentialsError:
|
205
|
-
pass
|
206
|
-
|
207
|
-
self.assertEqual(
|
208
|
-
model.api_endpoint,
|
209
|
-
(
|
210
|
-
'https://us-east5-aiplatform.googleapis.com/v1/projects/'
|
211
|
-
'langfun/locations/us-east5/publishers/anthropic/'
|
212
|
-
'models/claude-3-5-sonnet-v2@20241022:streamRawPredict'
|
213
|
-
)
|
214
|
-
)
|
215
|
-
request = model.request(
|
216
|
-
lf_message.UserMessage('hi'),
|
217
|
-
language_model.LMSamplingOptions(temperature=0.0),
|
218
|
-
)
|
219
|
-
self.assertEqual(
|
220
|
-
request,
|
221
|
-
{
|
222
|
-
'anthropic_version': 'vertex-2023-10-16',
|
223
|
-
'max_tokens': 8192,
|
224
|
-
'messages': [
|
225
|
-
{'content': [{'text': 'hi', 'type': 'text'}], 'role': 'user'}
|
226
|
-
],
|
227
|
-
'stream': False,
|
228
|
-
'temperature': 0.0,
|
229
|
-
'top_k': 40,
|
230
|
-
},
|
231
|
-
)
|
232
|
-
|
233
|
-
|
234
186
|
if __name__ == '__main__':
|
235
187
|
unittest.main()
|
{langfun-0.1.2.dev202501150804 → langfun-0.1.2.dev202501170804}/langfun/core/llms/vertexai.py
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2025 The Langfun Authors
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -15,10 +15,12 @@
|
|
15
15
|
|
16
16
|
import functools
|
17
17
|
import os
|
18
|
-
from typing import Annotated, Any
|
18
|
+
from typing import Annotated, Any, Literal
|
19
19
|
|
20
20
|
import langfun.core as lf
|
21
|
+
from langfun.core.llms import anthropic
|
21
22
|
from langfun.core.llms import gemini
|
23
|
+
from langfun.core.llms import rest
|
22
24
|
import pyglove as pg
|
23
25
|
|
24
26
|
try:
|
@@ -36,10 +38,21 @@ except ImportError:
|
|
36
38
|
Credentials = Any
|
37
39
|
|
38
40
|
|
39
|
-
@
|
40
|
-
|
41
|
-
class VertexAI
|
42
|
-
|
41
|
+
@pg.use_init_args(['api_endpoint'])
|
42
|
+
class VertexAI(rest.REST):
|
43
|
+
"""Base class for VertexAI models.
|
44
|
+
|
45
|
+
This class handles the authentication of vertex AI models. Subclasses
|
46
|
+
should implement `request` and `result` methods, as well as the `api_endpoint`
|
47
|
+
property. Or let users to provide them as __init__ arguments.
|
48
|
+
|
49
|
+
Please check out VertexAIGemini in `gemini.py` as an example.
|
50
|
+
"""
|
51
|
+
|
52
|
+
model: Annotated[
|
53
|
+
str | None,
|
54
|
+
'Model ID.'
|
55
|
+
] = None
|
43
56
|
|
44
57
|
project: Annotated[
|
45
58
|
str | None,
|
@@ -114,6 +127,17 @@ class VertexAI(gemini.Gemini):
|
|
114
127
|
s.headers.update(self.headers or {})
|
115
128
|
return s
|
116
129
|
|
130
|
+
|
131
|
+
#
|
132
|
+
# Gemini models served by Vertex AI.
|
133
|
+
#
|
134
|
+
|
135
|
+
|
136
|
+
@pg.use_init_args(['model'])
|
137
|
+
@pg.members([('api_endpoint', pg.typing.Str().freeze(''))])
|
138
|
+
class VertexAIGemini(VertexAI, gemini.Gemini):
|
139
|
+
"""Gemini models served by Vertex AI.."""
|
140
|
+
|
117
141
|
@property
|
118
142
|
def api_endpoint(self) -> str:
|
119
143
|
assert self._api_initialized
|
@@ -124,7 +148,7 @@ class VertexAI(gemini.Gemini):
|
|
124
148
|
)
|
125
149
|
|
126
150
|
|
127
|
-
class VertexAIGeminiFlash2_0ThinkingExp_20241219(
|
151
|
+
class VertexAIGeminiFlash2_0ThinkingExp_20241219(VertexAIGemini): # pylint: disable=invalid-name
|
128
152
|
"""Vertex AI Gemini Flash 2.0 Thinking model launched on 12/19/2024."""
|
129
153
|
|
130
154
|
api_version = 'v1alpha'
|
@@ -132,61 +156,128 @@ class VertexAIGeminiFlash2_0ThinkingExp_20241219(VertexAI): # pylint: disable=i
|
|
132
156
|
timeout = None
|
133
157
|
|
134
158
|
|
135
|
-
class VertexAIGeminiFlash2_0Exp(
|
159
|
+
class VertexAIGeminiFlash2_0Exp(VertexAIGemini): # pylint: disable=invalid-name
|
136
160
|
"""Vertex AI Gemini 2.0 Flash model."""
|
137
161
|
|
138
162
|
model = 'gemini-2.0-flash-exp'
|
139
163
|
|
140
164
|
|
141
|
-
class VertexAIGeminiExp_20241206(
|
165
|
+
class VertexAIGeminiExp_20241206(VertexAIGemini): # pylint: disable=invalid-name
|
142
166
|
"""Vertex AI Gemini Experimental model launched on 12/06/2024."""
|
143
167
|
|
144
168
|
model = 'gemini-exp-1206'
|
145
169
|
|
146
170
|
|
147
|
-
class VertexAIGeminiExp_20241114(
|
171
|
+
class VertexAIGeminiExp_20241114(VertexAIGemini): # pylint: disable=invalid-name
|
148
172
|
"""Vertex AI Gemini Experimental model launched on 11/14/2024."""
|
149
173
|
|
150
174
|
model = 'gemini-exp-1114'
|
151
175
|
|
152
176
|
|
153
|
-
class VertexAIGeminiPro1_5(
|
177
|
+
class VertexAIGeminiPro1_5(VertexAIGemini): # pylint: disable=invalid-name
|
154
178
|
"""Vertex AI Gemini 1.5 Pro model."""
|
155
179
|
|
156
180
|
model = 'gemini-1.5-pro-latest'
|
157
181
|
|
158
182
|
|
159
|
-
class VertexAIGeminiPro1_5_002(
|
183
|
+
class VertexAIGeminiPro1_5_002(VertexAIGemini): # pylint: disable=invalid-name
|
160
184
|
"""Vertex AI Gemini 1.5 Pro model."""
|
161
185
|
|
162
186
|
model = 'gemini-1.5-pro-002'
|
163
187
|
|
164
188
|
|
165
|
-
class VertexAIGeminiPro1_5_001(
|
189
|
+
class VertexAIGeminiPro1_5_001(VertexAIGemini): # pylint: disable=invalid-name
|
166
190
|
"""Vertex AI Gemini 1.5 Pro model."""
|
167
191
|
|
168
192
|
model = 'gemini-1.5-pro-001'
|
169
193
|
|
170
194
|
|
171
|
-
class VertexAIGeminiFlash1_5(
|
195
|
+
class VertexAIGeminiFlash1_5(VertexAIGemini): # pylint: disable=invalid-name
|
172
196
|
"""Vertex AI Gemini 1.5 Flash model."""
|
173
197
|
|
174
198
|
model = 'gemini-1.5-flash'
|
175
199
|
|
176
200
|
|
177
|
-
class VertexAIGeminiFlash1_5_002(
|
201
|
+
class VertexAIGeminiFlash1_5_002(VertexAIGemini): # pylint: disable=invalid-name
|
178
202
|
"""Vertex AI Gemini 1.5 Flash model."""
|
179
203
|
|
180
204
|
model = 'gemini-1.5-flash-002'
|
181
205
|
|
182
206
|
|
183
|
-
class VertexAIGeminiFlash1_5_001(
|
207
|
+
class VertexAIGeminiFlash1_5_001(VertexAIGemini): # pylint: disable=invalid-name
|
184
208
|
"""Vertex AI Gemini 1.5 Flash model."""
|
185
209
|
|
186
210
|
model = 'gemini-1.5-flash-001'
|
187
211
|
|
188
212
|
|
189
|
-
class VertexAIGeminiPro1(
|
213
|
+
class VertexAIGeminiPro1(VertexAIGemini): # pylint: disable=invalid-name
|
190
214
|
"""Vertex AI Gemini 1.0 Pro model."""
|
191
215
|
|
192
216
|
model = 'gemini-1.0-pro'
|
217
|
+
|
218
|
+
|
219
|
+
#
|
220
|
+
# Anthropic models on Vertex AI.
|
221
|
+
#
|
222
|
+
|
223
|
+
|
224
|
+
@pg.use_init_args(['model'])
|
225
|
+
@pg.members([('api_endpoint', pg.typing.Str().freeze(''))])
|
226
|
+
class VertexAIAnthropic(VertexAI, anthropic.Anthropic):
|
227
|
+
"""Anthropic models on VertexAI."""
|
228
|
+
|
229
|
+
location: Annotated[
|
230
|
+
Literal['us-east5', 'europe-west1'],
|
231
|
+
'GCP location with Anthropic models hosted.'
|
232
|
+
] = 'us-east5'
|
233
|
+
|
234
|
+
api_version = 'vertex-2023-10-16'
|
235
|
+
|
236
|
+
@property
|
237
|
+
def headers(self):
|
238
|
+
return {
|
239
|
+
'Content-Type': 'application/json; charset=utf-8',
|
240
|
+
}
|
241
|
+
|
242
|
+
@property
|
243
|
+
def api_endpoint(self) -> str:
|
244
|
+
return (
|
245
|
+
f'https://{self.location}-aiplatform.googleapis.com/v1/projects/'
|
246
|
+
f'{self._project}/locations/{self.location}/publishers/anthropic/'
|
247
|
+
f'models/{self.model}:streamRawPredict'
|
248
|
+
)
|
249
|
+
|
250
|
+
def request(
|
251
|
+
self,
|
252
|
+
prompt: lf.Message,
|
253
|
+
sampling_options: lf.LMSamplingOptions
|
254
|
+
):
|
255
|
+
request = super().request(prompt, sampling_options)
|
256
|
+
request['anthropic_version'] = self.api_version
|
257
|
+
del request['model']
|
258
|
+
return request
|
259
|
+
|
260
|
+
|
261
|
+
# pylint: disable=invalid-name
|
262
|
+
|
263
|
+
|
264
|
+
class VertexAIClaude3_Opus_20240229(VertexAIAnthropic):
|
265
|
+
"""Anthropic's Claude 3 Opus model on VertexAI."""
|
266
|
+
model = 'claude-3-opus@20240229'
|
267
|
+
|
268
|
+
|
269
|
+
class VertexAIClaude3_5_Sonnet_20241022(VertexAIAnthropic):
|
270
|
+
"""Anthropic's Claude 3.5 Sonnet model on VertexAI."""
|
271
|
+
model = 'claude-3-5-sonnet-v2@20241022'
|
272
|
+
|
273
|
+
|
274
|
+
class VertexAIClaude3_5_Sonnet_20240620(VertexAIAnthropic):
|
275
|
+
"""Anthropic's Claude 3.5 Sonnet model on VertexAI."""
|
276
|
+
model = 'claude-3-5-sonnet@20240620'
|
277
|
+
|
278
|
+
|
279
|
+
class VertexAIClaude3_5_Haiku_20241022(VertexAIAnthropic):
|
280
|
+
"""Anthropic's Claude 3.5 Haiku model on VertexAI."""
|
281
|
+
model = 'claude-3-5-haiku@20241022'
|
282
|
+
|
283
|
+
# pylint: enable=invalid-name
|