SimplerLLM 0.3.1.22__tar.gz → 0.3.2__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.
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/PKG-INFO +24 -1
- simplerllm-0.3.2/README.md +522 -0
- simplerllm-0.3.2/SimplerLLM/__init__.py +255 -0
- simplerllm-0.3.2/SimplerLLM/image/__init__.py +24 -0
- simplerllm-0.3.2/SimplerLLM/image/generation/__init__.py +21 -0
- simplerllm-0.3.2/SimplerLLM/image/generation/base.py +191 -0
- simplerllm-0.3.2/SimplerLLM/image/generation/providers/__init__.py +16 -0
- simplerllm-0.3.2/SimplerLLM/image/generation/providers/google_image.py +234 -0
- simplerllm-0.3.2/SimplerLLM/image/generation/providers/image_response_models.py +59 -0
- simplerllm-0.3.2/SimplerLLM/image/generation/providers/openai_image.py +287 -0
- simplerllm-0.3.2/SimplerLLM/image/generation/providers/stability_image.py +263 -0
- simplerllm-0.3.2/SimplerLLM/image/generation/wrappers/__init__.py +14 -0
- simplerllm-0.3.2/SimplerLLM/image/generation/wrappers/google_wrapper.py +270 -0
- simplerllm-0.3.2/SimplerLLM/image/generation/wrappers/openai_wrapper.py +239 -0
- simplerllm-0.3.2/SimplerLLM/image/generation/wrappers/stability_wrapper.py +310 -0
- simplerllm-0.3.2/SimplerLLM/language/__init__.py +126 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/__init__.py +103 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/base.py +244 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/exceptions.py +102 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/input_guardrails/__init__.py +20 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/input_guardrails/pii_detection.py +236 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/input_guardrails/prompt_injection.py +136 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/input_guardrails/topic_filter.py +215 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/output_guardrails/__init__.py +23 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/output_guardrails/content_safety.py +299 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/output_guardrails/format_validator.py +246 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/output_guardrails/length_validator.py +260 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/output_guardrails/pii_detection.py +273 -0
- simplerllm-0.3.2/SimplerLLM/language/guardrails/wrapper.py +558 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm/wrappers/anthropic_wrapper.py +36 -7
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm/wrappers/openai_wrapper.py +37 -4
- simplerllm-0.3.2/SimplerLLM/language/llm_clustering/__init__.py +118 -0
- simplerllm-0.3.2/SimplerLLM/language/llm_clustering/chunk_store.py +380 -0
- simplerllm-0.3.2/SimplerLLM/language/llm_clustering/clusterer.py +248 -0
- simplerllm-0.3.2/SimplerLLM/language/llm_clustering/flat_clusterer.py +361 -0
- simplerllm-0.3.2/SimplerLLM/language/llm_clustering/models.py +291 -0
- simplerllm-0.3.2/SimplerLLM/language/llm_clustering/persistence.py +484 -0
- simplerllm-0.3.2/SimplerLLM/language/llm_clustering/tree_builder.py +360 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_providers/llm_response_models.py +2 -1
- simplerllm-0.3.2/SimplerLLM/language/llm_retrieval/__init__.py +79 -0
- simplerllm-0.3.2/SimplerLLM/language/llm_retrieval/models.py +164 -0
- simplerllm-0.3.2/SimplerLLM/language/llm_retrieval/retriever.py +386 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_router/router.py +4 -0
- simplerllm-0.3.2/SimplerLLM/tools/image_helpers.py +266 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/vectors/local_vector_db.py +2 -2
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/vectors/qdrant_vector_db.py +142 -102
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/vectors/simpler_vector.py +88 -63
- simplerllm-0.3.2/SimplerLLM/vectors/vector_db.py +405 -0
- simplerllm-0.3.2/SimplerLLM/voice/__init__.py +110 -0
- simplerllm-0.3.2/SimplerLLM/voice/dialogue_generator/__init__.py +19 -0
- simplerllm-0.3.2/SimplerLLM/voice/dialogue_generator/audio_merger.py +362 -0
- simplerllm-0.3.2/SimplerLLM/voice/dialogue_generator/dialogue_generator.py +640 -0
- simplerllm-0.3.2/SimplerLLM/voice/dialogue_generator/models.py +183 -0
- simplerllm-0.3.2/SimplerLLM/voice/live_voice_chat/__init__.py +11 -0
- simplerllm-0.3.2/SimplerLLM/voice/live_voice_chat/audio_player.py +335 -0
- simplerllm-0.3.2/SimplerLLM/voice/live_voice_chat/audio_recorder.py +374 -0
- simplerllm-0.3.2/SimplerLLM/voice/live_voice_chat/live_voice_chat.py +373 -0
- simplerllm-0.3.2/SimplerLLM/voice/live_voice_chat/models.py +59 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/__init__.py +105 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/audio_utils.py +205 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/base.py +286 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/models.py +308 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/providers/__init__.py +19 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/providers/elevenlabs_convai.py +643 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/providers/openai_realtime.py +511 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/providers/realtime_response_models.py +172 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/realtime_voice_chat.py +303 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/wrappers/__init__.py +11 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/wrappers/elevenlabs_wrapper.py +306 -0
- simplerllm-0.3.2/SimplerLLM/voice/realtime_voice/wrappers/openai_wrapper.py +444 -0
- simplerllm-0.3.2/SimplerLLM/voice/stt/__init__.py +10 -0
- simplerllm-0.3.2/SimplerLLM/voice/stt/base.py +110 -0
- simplerllm-0.3.2/SimplerLLM/voice/stt/providers/__init__.py +7 -0
- simplerllm-0.3.2/SimplerLLM/voice/stt/providers/openai_stt.py +234 -0
- simplerllm-0.3.2/SimplerLLM/voice/stt/providers/stt_response_models.py +47 -0
- simplerllm-0.3.2/SimplerLLM/voice/stt/wrappers/__init__.py +5 -0
- simplerllm-0.3.2/SimplerLLM/voice/stt/wrappers/openai_wrapper.py +172 -0
- simplerllm-0.3.2/SimplerLLM/voice/tts/__init__.py +11 -0
- simplerllm-0.3.2/SimplerLLM/voice/tts/base.py +125 -0
- simplerllm-0.3.2/SimplerLLM/voice/tts/providers/__init__.py +18 -0
- simplerllm-0.3.2/SimplerLLM/voice/tts/providers/elevenlabs_tts.py +227 -0
- simplerllm-0.3.2/SimplerLLM/voice/tts/providers/openai_tts.py +190 -0
- simplerllm-0.3.2/SimplerLLM/voice/tts/providers/tts_response_models.py +51 -0
- simplerllm-0.3.2/SimplerLLM/voice/tts/wrappers/__init__.py +16 -0
- simplerllm-0.3.2/SimplerLLM/voice/tts/wrappers/elevenlabs_wrapper.py +216 -0
- simplerllm-0.3.2/SimplerLLM/voice/tts/wrappers/openai_wrapper.py +172 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_dubbing/__init__.py +37 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_dubbing/audio_sync.py +326 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_dubbing/base.py +370 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_dubbing/models.py +61 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_dubbing/video_processor.py +280 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_transcription/__init__.py +26 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_transcription/base.py +329 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_transcription/caption_generator.py +357 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_transcription/models.py +112 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_transcription/utils/__init__.py +26 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_transcription/utils/subtitle_formatter.py +58 -0
- simplerllm-0.3.2/SimplerLLM/voice/video_transcription/utils/video_utils.py +225 -0
- simplerllm-0.3.2/SimplerLLM/voice/voice_chat/__init__.py +19 -0
- simplerllm-0.3.2/SimplerLLM/voice/voice_chat/conversation.py +115 -0
- simplerllm-0.3.2/SimplerLLM/voice/voice_chat/models.py +125 -0
- simplerllm-0.3.2/SimplerLLM/voice/voice_chat/voice_chat.py +548 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM.egg-info/PKG-INFO +24 -1
- simplerllm-0.3.2/SimplerLLM.egg-info/SOURCES.txt +204 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM.egg-info/requires.txt +15 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/setup.py +13 -3
- simplerllm-0.3.2/tests/test_llm_clustering_retrieval.py +355 -0
- simplerllm-0.3.2/tests/test_production_vector_db.py +765 -0
- simplerllm-0.3.2/tests/test_qdrant_comprehensive.py +793 -0
- simplerllm-0.3.2/tests/test_qdrant_integration_live.py +653 -0
- simplerllm-0.3.2/tests/test_unified_vector_interface.py +222 -0
- simplerllm-0.3.2/tests/test_vision_anthropic.py +250 -0
- simplerllm-0.3.2/tests/test_vision_openai.py +254 -0
- simplerllm-0.3.2/tests/test_vision_quick.py +179 -0
- simplerllm-0.3.1.22/SimplerLLM/language/__init__.py +0 -35
- simplerllm-0.3.1.22/SimplerLLM/utils/__init__.py +0 -0
- simplerllm-0.3.1.22/SimplerLLM/vectors/vector_db.py +0 -23
- simplerllm-0.3.1.22/SimplerLLM.egg-info/SOURCES.txt +0 -105
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/LICENSE +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/embeddings.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/flow/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/flow/flow.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/flow/models.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/flow/tool_registry.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm/base.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm/reliable.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm/wrappers/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm/wrappers/cohere_wrapper.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm/wrappers/deepseek_wrapper.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm/wrappers/gemini_wrapper.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm/wrappers/ollama_wrapper.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm/wrappers/openrouter_wrapper.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_addons.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_brainstorm/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_brainstorm/models.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_brainstorm/recursive_brainstorm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_feedback/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_feedback/feedback_loop.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_feedback/models.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_judge/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_judge/judge.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_judge/models.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_provider_router/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_provider_router/models.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_provider_router/provider_router.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_provider_router/query_classifier.py +0 -0
- {simplerllm-0.3.1.22/SimplerLLM → simplerllm-0.3.2/SimplerLLM/language/llm_providers}/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_providers/anthropic_llm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_providers/cohere_llm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_providers/deepseek_llm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_providers/gemini_llm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_providers/ollama_llm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_providers/openai_llm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_providers/openrouter_llm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_providers/voyage_llm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_router/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/language/llm_router/models.py +0 -0
- {simplerllm-0.3.1.22/SimplerLLM/language/llm_providers → simplerllm-0.3.2/SimplerLLM/prompts}/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/prompts/hub/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/prompts/hub/agentic_prompts.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/prompts/hub/prompt_manager.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/prompts/messages_template.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/prompts/prompt_builder.py +0 -0
- {simplerllm-0.3.1.22/SimplerLLM/prompts → simplerllm-0.3.2/SimplerLLM/tools}/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/apify_api.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/brainstorm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/email_functions.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/file_functions.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/file_loader.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/generic_loader.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/json_helpers.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/pandas_func.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/pattern_helpers.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/python_func.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/rapid_api.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/serp.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/text_chunker.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/tools/youtube.py +0 -0
- {simplerllm-0.3.1.22/SimplerLLM/tools → simplerllm-0.3.2/SimplerLLM/utils}/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/utils/custom_verbose.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/vectors/__init__.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM/vectors/vector_providers.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM.egg-info/dependency_links.txt +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/SimplerLLM.egg-info/top_level.txt +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/setup.cfg +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_agent.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_agent_full.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_cohere.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_cohere_embeddings.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_comprehensive_llm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_embeddings_comprehensive.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_flow_comprehensive.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_llm_brainstorm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_llm_feedback.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_llm_judge.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_llm_provider_router.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_nested_models.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_openrouter.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_openrouter_full_response.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_pattern_extraction.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_pattern_helpers.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_pydantic_edge_cases.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_pydantic_edge_cases_llm.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_pydantic_structures.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_qdrant_connection.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_real_llm_generation.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_router_simple.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_router_youtube_titles.py +0 -0
- {simplerllm-0.3.1.22 → simplerllm-0.3.2}/tests/test_voyage_embeddings.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: SimplerLLM
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: An easy-to-use Library for interacting with language models.
|
|
5
5
|
Home-page: https://github.com/hassancs91/SimplerLLM
|
|
6
6
|
Author: Hasan Aboul Hasan
|
|
@@ -25,10 +25,13 @@ License-File: LICENSE
|
|
|
25
25
|
Requires-Dist: aiohttp>=3.9
|
|
26
26
|
Requires-Dist: cohere>=5.0
|
|
27
27
|
Requires-Dist: duckduckgo_search>=5.3
|
|
28
|
+
Requires-Dist: elevenlabs>=1.0
|
|
28
29
|
Requires-Dist: lxml_html_clean>=0.1
|
|
29
30
|
Requires-Dist: newspaper3k>=0.2
|
|
30
31
|
Requires-Dist: numpy>=1.26
|
|
31
32
|
Requires-Dist: openai>=1.59
|
|
33
|
+
Requires-Dist: google-genai>=1.52.0
|
|
34
|
+
Requires-Dist: Pillow>=10.0
|
|
32
35
|
Requires-Dist: pydantic>=2.10
|
|
33
36
|
Requires-Dist: PyPDF2>=3.0
|
|
34
37
|
Requires-Dist: python-dotenv>=1.0
|
|
@@ -40,6 +43,16 @@ Requires-Dist: scipy>=1.15
|
|
|
40
43
|
Requires-Dist: tiktoken>=0.9
|
|
41
44
|
Requires-Dist: qdrant-client==1.14.3
|
|
42
45
|
Requires-Dist: voyageai==0.3.3
|
|
46
|
+
Requires-Dist: pydub>=0.25.1
|
|
47
|
+
Requires-Dist: elevenlabs>=2.22.0
|
|
48
|
+
Requires-Dist: sounddevice>=0.4.6
|
|
49
|
+
Requires-Dist: pynput>=1.7.6
|
|
50
|
+
Requires-Dist: moviepy>=1.0.3
|
|
51
|
+
Requires-Dist: yt-dlp>=2023.3.4
|
|
52
|
+
Provides-Extra: voice
|
|
53
|
+
Requires-Dist: pygame>=2.5.0; extra == "voice"
|
|
54
|
+
Provides-Extra: all
|
|
55
|
+
Requires-Dist: pygame>=2.5.0; extra == "all"
|
|
43
56
|
Dynamic: author
|
|
44
57
|
Dynamic: author-email
|
|
45
58
|
Dynamic: classifier
|
|
@@ -49,6 +62,7 @@ Dynamic: home-page
|
|
|
49
62
|
Dynamic: keywords
|
|
50
63
|
Dynamic: license
|
|
51
64
|
Dynamic: license-file
|
|
65
|
+
Dynamic: provides-extra
|
|
52
66
|
Dynamic: requires-dist
|
|
53
67
|
Dynamic: requires-python
|
|
54
68
|
Dynamic: summary
|
|
@@ -72,6 +86,15 @@ SimplerLLM is an open-source Python library designed to simplify interactions wi
|
|
|
72
86
|
pip install simplerllm
|
|
73
87
|
```
|
|
74
88
|
|
|
89
|
+
### Optional Dependencies
|
|
90
|
+
|
|
91
|
+
For voice/audio features (AudioPlayer file playback):
|
|
92
|
+
```bash
|
|
93
|
+
pip install simplerllm[voice]
|
|
94
|
+
# Or install pygame directly:
|
|
95
|
+
pip install pygame>=2.5.0
|
|
96
|
+
```
|
|
97
|
+
|
|
75
98
|
## Key Features
|
|
76
99
|
|
|
77
100
|
### 🔗 Unified LLM Interface
|
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
# SimplerLLM
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://discord.gg/HUrtZXyp3j)
|
|
5
|
+
|
|
6
|
+
**Your Easy Pass to Advanced AI** - A comprehensive Python library for simplified Large Language Model interactions.
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
SimplerLLM is an open-source Python library designed to simplify interactions with Large Language Models (LLMs) for researchers, developers, and AI enthusiasts. It provides a unified interface for multiple LLM providers, robust tools for content processing, and advanced features like reliable failover systems and intelligent routing.
|
|
11
|
+
|
|
12
|
+
[📚 Full Documentation](https://docs.simplerllm.com/)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install simplerllm
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Optional Dependencies
|
|
21
|
+
|
|
22
|
+
For voice/audio features (AudioPlayer file playback):
|
|
23
|
+
```bash
|
|
24
|
+
pip install simplerllm[voice]
|
|
25
|
+
# Or install pygame directly:
|
|
26
|
+
pip install pygame>=2.5.0
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Key Features
|
|
30
|
+
|
|
31
|
+
### 🔗 Unified LLM Interface
|
|
32
|
+
- **8 LLM Providers**: OpenAI, Anthropic, Google Gemini, Cohere, OpenRouter, DeepSeek, and Ollama
|
|
33
|
+
- **Consistent API**: Same interface across all providers
|
|
34
|
+
- **100+ Models**: Access to diverse models through OpenRouter integration
|
|
35
|
+
- **Async Support**: Full asynchronous capabilities
|
|
36
|
+
|
|
37
|
+
### 🛡️ Reliability & Failover
|
|
38
|
+
- **Reliable LLM**: Automatic failover between primary and secondary providers
|
|
39
|
+
- **Retry Logic**: Built-in exponential backoff for failed requests
|
|
40
|
+
- **Validation**: Automatic provider validation during initialization
|
|
41
|
+
|
|
42
|
+
### 🎯 Structured Output
|
|
43
|
+
- **Pydantic Integration**: Generate validated JSON responses
|
|
44
|
+
- **Type Safety**: Automatic validation and parsing
|
|
45
|
+
- **Retry Logic**: Automatic retry on validation failures
|
|
46
|
+
|
|
47
|
+
### 🔍 Vector Operations
|
|
48
|
+
- **Multiple Providers**: OpenAI, Voyage AI, and Cohere embeddings
|
|
49
|
+
- **Local & Cloud Storage**: Local vector database and Qdrant integration
|
|
50
|
+
- **Semantic Search**: Advanced similarity search capabilities
|
|
51
|
+
|
|
52
|
+
### 🧠 Intelligent Routing
|
|
53
|
+
- **LLM Router**: AI-powered content routing and selection
|
|
54
|
+
- **Metadata Filtering**: Route based on content metadata
|
|
55
|
+
- **Confidence Scoring**: Intelligent selection with confidence metrics
|
|
56
|
+
|
|
57
|
+
### 🛠️ Advanced Tools
|
|
58
|
+
- **Content Loading**: PDF, DOCX, web pages, and more
|
|
59
|
+
- **Text Chunking**: Semantic, sentence, and paragraph-based chunking
|
|
60
|
+
- **Search Integration**: Serper and Value Serp APIs
|
|
61
|
+
- **Prompt Templates**: Dynamic prompt generation and management
|
|
62
|
+
|
|
63
|
+
## Quick Start
|
|
64
|
+
|
|
65
|
+
### Basic LLM Usage
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from SimplerLLM.language.llm import LLM, LLMProvider
|
|
69
|
+
|
|
70
|
+
# Create LLM instance
|
|
71
|
+
llm = LLM.create(provider=LLMProvider.OPENAI, model_name="gpt-4o")
|
|
72
|
+
|
|
73
|
+
# Generate response
|
|
74
|
+
response = llm.generate_response(prompt="Explain quantum computing in simple terms")
|
|
75
|
+
print(response)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### All Supported Providers
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from SimplerLLM.language.llm import LLM, LLMProvider
|
|
82
|
+
|
|
83
|
+
# OpenAI
|
|
84
|
+
openai_llm = LLM.create(provider=LLMProvider.OPENAI, model_name="gpt-4o")
|
|
85
|
+
|
|
86
|
+
# Anthropic Claude
|
|
87
|
+
anthropic_llm = LLM.create(provider=LLMProvider.ANTHROPIC, model_name="claude-3-5-sonnet-20241022")
|
|
88
|
+
|
|
89
|
+
# Google Gemini
|
|
90
|
+
gemini_llm = LLM.create(provider=LLMProvider.GEMINI, model_name="gemini-1.5-pro")
|
|
91
|
+
|
|
92
|
+
# Cohere
|
|
93
|
+
cohere_llm = LLM.create(provider=LLMProvider.COHERE, model_name="command-r-plus")
|
|
94
|
+
|
|
95
|
+
# OpenRouter (Access to 100+ models)
|
|
96
|
+
openrouter_llm = LLM.create(provider=LLMProvider.OPENROUTER, model_name="openai/gpt-4o")
|
|
97
|
+
|
|
98
|
+
# DeepSeek
|
|
99
|
+
deepseek_llm = LLM.create(provider=LLMProvider.DEEPSEEK, model_name="deepseek-chat")
|
|
100
|
+
|
|
101
|
+
# Ollama (Local models)
|
|
102
|
+
ollama_llm = LLM.create(provider=LLMProvider.OLLAMA, model_name="llama2")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Reliable LLM with Failover
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from SimplerLLM.language.llm import LLM, LLMProvider
|
|
109
|
+
from SimplerLLM.language.llm.reliable import ReliableLLM
|
|
110
|
+
|
|
111
|
+
# Create primary and secondary LLMs
|
|
112
|
+
primary_llm = LLM.create(provider=LLMProvider.OPENAI, model_name="gpt-4o")
|
|
113
|
+
secondary_llm = LLM.create(provider=LLMProvider.ANTHROPIC, model_name="claude-3-5-sonnet-20241022")
|
|
114
|
+
|
|
115
|
+
# Create reliable LLM with automatic failover
|
|
116
|
+
reliable_llm = ReliableLLM(primary_llm, secondary_llm)
|
|
117
|
+
|
|
118
|
+
# If primary fails, automatically uses secondary
|
|
119
|
+
response = reliable_llm.generate_response(prompt="Explain machine learning")
|
|
120
|
+
print(response)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Structured JSON Output with Pydantic
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from pydantic import BaseModel, Field
|
|
127
|
+
from SimplerLLM.language.llm import LLM, LLMProvider
|
|
128
|
+
from SimplerLLM.language.llm_addons import generate_pydantic_json_model
|
|
129
|
+
|
|
130
|
+
class MovieRecommendation(BaseModel):
|
|
131
|
+
title: str = Field(description="Movie title")
|
|
132
|
+
genre: str = Field(description="Movie genre")
|
|
133
|
+
year: int = Field(description="Release year")
|
|
134
|
+
rating: float = Field(description="IMDb rating")
|
|
135
|
+
reason: str = Field(description="Why this movie is recommended")
|
|
136
|
+
|
|
137
|
+
llm = LLM.create(provider=LLMProvider.OPENAI, model_name="gpt-4o")
|
|
138
|
+
prompt = "Recommend a great science fiction movie from the 2020s"
|
|
139
|
+
|
|
140
|
+
recommendation = generate_pydantic_json_model(
|
|
141
|
+
llm_instance=llm,
|
|
142
|
+
prompt=prompt,
|
|
143
|
+
model_class=MovieRecommendation
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
print(f"Title: {recommendation.title}")
|
|
147
|
+
print(f"Genre: {recommendation.genre}")
|
|
148
|
+
print(f"Year: {recommendation.year}")
|
|
149
|
+
print(f"Rating: {recommendation.rating}")
|
|
150
|
+
print(f"Reason: {recommendation.reason}")
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Reliable JSON Generation
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from SimplerLLM.language.llm.reliable import ReliableLLM
|
|
157
|
+
from SimplerLLM.language.llm_addons import generate_pydantic_json_model_reliable
|
|
158
|
+
|
|
159
|
+
# Use reliable LLM with JSON generation
|
|
160
|
+
reliable_llm = ReliableLLM(primary_llm, secondary_llm)
|
|
161
|
+
|
|
162
|
+
recommendation, provider, model_name = generate_pydantic_json_model_reliable(
|
|
163
|
+
reliable_llm=reliable_llm,
|
|
164
|
+
prompt=prompt,
|
|
165
|
+
model_class=MovieRecommendation
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
print(f"Generated by: {provider.name} using {model_name}")
|
|
169
|
+
print(f"Title: {recommendation.title}")
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Embeddings
|
|
173
|
+
|
|
174
|
+
### All Embedding Providers
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from SimplerLLM.language.embeddings import EmbeddingsLLM, EmbeddingsProvider
|
|
178
|
+
|
|
179
|
+
# OpenAI Embeddings
|
|
180
|
+
openai_embeddings = EmbeddingsLLM.create(
|
|
181
|
+
provider=EmbeddingsProvider.OPENAI,
|
|
182
|
+
model_name="text-embedding-3-large"
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# Voyage AI Embeddings
|
|
186
|
+
voyage_embeddings = EmbeddingsLLM.create(
|
|
187
|
+
provider=EmbeddingsProvider.VOYAGE,
|
|
188
|
+
model_name="voyage-3-large"
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
# Cohere Embeddings
|
|
192
|
+
cohere_embeddings = EmbeddingsLLM.create(
|
|
193
|
+
provider=EmbeddingsProvider.COHERE,
|
|
194
|
+
model_name="embed-english-v3.0"
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
# Generate embeddings
|
|
198
|
+
text = "SimplerLLM makes AI development easier"
|
|
199
|
+
embeddings = openai_embeddings.generate_embeddings(text)
|
|
200
|
+
print(f"Embedding dimensions: {len(embeddings)}")
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Advanced Embedding Features
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
# Voyage AI with advanced options
|
|
207
|
+
voyage_embeddings = EmbeddingsLLM.create(
|
|
208
|
+
provider=EmbeddingsProvider.VOYAGE,
|
|
209
|
+
model_name="voyage-3-large"
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
# Optimize for search queries vs documents
|
|
213
|
+
query_embeddings = voyage_embeddings.generate_embeddings(
|
|
214
|
+
user_input="What is machine learning?",
|
|
215
|
+
input_type="query",
|
|
216
|
+
output_dimension=1024
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
document_embeddings = voyage_embeddings.generate_embeddings(
|
|
220
|
+
user_input="Machine learning is a subset of artificial intelligence...",
|
|
221
|
+
input_type="document",
|
|
222
|
+
output_dimension=1024
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
# Cohere with different input types
|
|
226
|
+
cohere_embeddings = EmbeddingsLLM.create(
|
|
227
|
+
provider=EmbeddingsProvider.COHERE,
|
|
228
|
+
model_name="embed-english-v3.0"
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
classification_embeddings = cohere_embeddings.generate_embeddings(
|
|
232
|
+
user_input="This is a positive review",
|
|
233
|
+
input_type="classification"
|
|
234
|
+
)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Vector Databases
|
|
238
|
+
|
|
239
|
+
### Local Vector Database
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
from SimplerLLM.vectors.vector_db import VectorDB, VectorProvider
|
|
243
|
+
from SimplerLLM.language.embeddings import EmbeddingsLLM, EmbeddingsProvider
|
|
244
|
+
|
|
245
|
+
# Create embeddings model
|
|
246
|
+
embeddings_model = EmbeddingsLLM.create(
|
|
247
|
+
provider=EmbeddingsProvider.OPENAI,
|
|
248
|
+
model_name="text-embedding-3-small"
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
# Create local vector database
|
|
252
|
+
vector_db = VectorDB.create(provider=VectorProvider.LOCAL)
|
|
253
|
+
|
|
254
|
+
# Add documents
|
|
255
|
+
documents = [
|
|
256
|
+
"SimplerLLM is a Python library for LLM interactions",
|
|
257
|
+
"Vector databases store high-dimensional embeddings",
|
|
258
|
+
"Semantic search finds similar content based on meaning"
|
|
259
|
+
]
|
|
260
|
+
|
|
261
|
+
for i, doc in enumerate(documents):
|
|
262
|
+
embedding = embeddings_model.generate_embeddings(doc)
|
|
263
|
+
vector_db.add_vector(id=f"doc_{i}", vector=embedding, metadata={"text": doc})
|
|
264
|
+
|
|
265
|
+
# Search for similar documents
|
|
266
|
+
query = "Python library for AI"
|
|
267
|
+
query_embedding = embeddings_model.generate_embeddings(query)
|
|
268
|
+
results = vector_db.search(query_embedding, top_k=2)
|
|
269
|
+
|
|
270
|
+
for result in results:
|
|
271
|
+
print(f"Score: {result['score']:.4f}")
|
|
272
|
+
print(f"Text: {result['metadata']['text']}")
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Qdrant Vector Database
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
from SimplerLLM.vectors.vector_db import VectorDB, VectorProvider
|
|
279
|
+
|
|
280
|
+
# Create Qdrant vector database
|
|
281
|
+
qdrant_db = VectorDB.create(
|
|
282
|
+
provider=VectorProvider.QDRANT,
|
|
283
|
+
url="http://localhost:6333",
|
|
284
|
+
collection_name="my_collection"
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
# Same interface as local vector database
|
|
288
|
+
embedding = embeddings_model.generate_embeddings("Sample document")
|
|
289
|
+
qdrant_db.add_vector(id="doc_1", vector=embedding, metadata={"text": "Sample document"})
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Intelligent Routing
|
|
293
|
+
|
|
294
|
+
```python
|
|
295
|
+
from SimplerLLM.language.llm_router.router import LLMRouter
|
|
296
|
+
from SimplerLLM.language.llm import LLM, LLMProvider
|
|
297
|
+
|
|
298
|
+
# Create router with LLM
|
|
299
|
+
llm = LLM.create(provider=LLMProvider.OPENAI, model_name="gpt-4o")
|
|
300
|
+
router = LLMRouter(llm)
|
|
301
|
+
|
|
302
|
+
# Add choices
|
|
303
|
+
choices = [
|
|
304
|
+
("Machine Learning Tutorial", {"category": "education", "difficulty": "beginner"}),
|
|
305
|
+
("Advanced Deep Learning", {"category": "education", "difficulty": "advanced"}),
|
|
306
|
+
("Python Programming Guide", {"category": "programming", "difficulty": "intermediate"})
|
|
307
|
+
]
|
|
308
|
+
|
|
309
|
+
router.add_choices(choices)
|
|
310
|
+
|
|
311
|
+
# Route based on input
|
|
312
|
+
result = router.route("I want to learn the basics of AI")
|
|
313
|
+
if result:
|
|
314
|
+
print(f"Selected: {result.selected_index}")
|
|
315
|
+
print(f"Confidence: {result.confidence_score}")
|
|
316
|
+
print(f"Reasoning: {result.reasoning}")
|
|
317
|
+
|
|
318
|
+
# Get top 3 matches
|
|
319
|
+
top_results = router.route_top_k("programming tutorial", k=3)
|
|
320
|
+
for result in top_results:
|
|
321
|
+
choice_content, metadata = router.get_choice(result.selected_index)
|
|
322
|
+
print(f"Choice: {choice_content}")
|
|
323
|
+
print(f"Confidence: {result.confidence_score}")
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Advanced Tools
|
|
327
|
+
|
|
328
|
+
### Content Loading
|
|
329
|
+
|
|
330
|
+
```python
|
|
331
|
+
from SimplerLLM.tools.generic_loader import load_content
|
|
332
|
+
|
|
333
|
+
# Load from various sources
|
|
334
|
+
pdf_content = load_content("document.pdf")
|
|
335
|
+
web_content = load_content("https://example.com/article")
|
|
336
|
+
docx_content = load_content("document.docx")
|
|
337
|
+
|
|
338
|
+
print(f"PDF content: {pdf_content.content[:100]}...")
|
|
339
|
+
print(f"Web content: {web_content.content[:100]}...")
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Text Chunking
|
|
343
|
+
|
|
344
|
+
```python
|
|
345
|
+
from SimplerLLM.tools.text_chunker import (
|
|
346
|
+
chunk_by_sentences,
|
|
347
|
+
chunk_by_paragraphs,
|
|
348
|
+
chunk_by_semantics,
|
|
349
|
+
chunk_by_max_chunk_size
|
|
350
|
+
)
|
|
351
|
+
from SimplerLLM.language.embeddings import EmbeddingsLLM, EmbeddingsProvider
|
|
352
|
+
|
|
353
|
+
text = "Your long document text here..."
|
|
354
|
+
|
|
355
|
+
# Sentence-based chunking
|
|
356
|
+
sentence_chunks = chunk_by_sentences(text, max_sentences=3)
|
|
357
|
+
|
|
358
|
+
# Paragraph-based chunking
|
|
359
|
+
paragraph_chunks = chunk_by_paragraphs(text, max_paragraphs=2)
|
|
360
|
+
|
|
361
|
+
# Semantic chunking
|
|
362
|
+
embeddings_model = EmbeddingsLLM.create(
|
|
363
|
+
provider=EmbeddingsProvider.OPENAI,
|
|
364
|
+
model_name="text-embedding-3-small"
|
|
365
|
+
)
|
|
366
|
+
semantic_chunks = chunk_by_semantics(text, embeddings_model, threshold_percentage=80)
|
|
367
|
+
|
|
368
|
+
# Size-based chunking
|
|
369
|
+
size_chunks = chunk_by_max_chunk_size(text, max_chunk_size=1000)
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Search Integration
|
|
373
|
+
|
|
374
|
+
```python
|
|
375
|
+
from SimplerLLM.tools.serp import search_with_serper_api
|
|
376
|
+
|
|
377
|
+
# Search the web
|
|
378
|
+
results = search_with_serper_api("latest AI developments", num_results=5)
|
|
379
|
+
for result in results:
|
|
380
|
+
print(f"Title: {result['title']}")
|
|
381
|
+
print(f"URL: {result['link']}")
|
|
382
|
+
print(f"Snippet: {result['snippet']}")
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Prompt Templates
|
|
386
|
+
|
|
387
|
+
```python
|
|
388
|
+
from SimplerLLM.prompts.prompt_builder import create_prompt_template, create_multi_value_prompts
|
|
389
|
+
|
|
390
|
+
# Single prompt template
|
|
391
|
+
template = create_prompt_template("Write a {style} article about {topic}")
|
|
392
|
+
template.assign_params(style="technical", topic="machine learning")
|
|
393
|
+
print(template.content)
|
|
394
|
+
|
|
395
|
+
# Multi-value prompts
|
|
396
|
+
multi_template = create_multi_value_prompts(
|
|
397
|
+
"Hello {name}, your meeting is on {date} about {topic}"
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
params_list = [
|
|
401
|
+
{"name": "Alice", "date": "Monday", "topic": "AI"},
|
|
402
|
+
{"name": "Bob", "date": "Tuesday", "topic": "ML"},
|
|
403
|
+
]
|
|
404
|
+
|
|
405
|
+
prompts = multi_template.generate_prompts(params_list)
|
|
406
|
+
for prompt in prompts:
|
|
407
|
+
print(prompt)
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## Configuration
|
|
411
|
+
|
|
412
|
+
### Environment Variables
|
|
413
|
+
|
|
414
|
+
Create a `.env` file in your project root:
|
|
415
|
+
|
|
416
|
+
```env
|
|
417
|
+
# LLM Providers
|
|
418
|
+
OPENAI_API_KEY=your_openai_api_key
|
|
419
|
+
ANTHROPIC_API_KEY=your_anthropic_api_key
|
|
420
|
+
GEMINI_API_KEY=your_gemini_api_key
|
|
421
|
+
COHERE_API_KEY=your_cohere_api_key
|
|
422
|
+
OPENROUTER_API_KEY=your_openrouter_api_key
|
|
423
|
+
OPENROUTER_SITE_URL=your_site_url # Optional
|
|
424
|
+
OPENROUTER_SITE_NAME=your_site_name # Optional
|
|
425
|
+
|
|
426
|
+
# Embeddings
|
|
427
|
+
VOYAGE_API_KEY=your_voyage_api_key
|
|
428
|
+
|
|
429
|
+
# Tools
|
|
430
|
+
RAPIDAPI_API_KEY=your_rapidapi_key
|
|
431
|
+
SERPER_API_KEY=your_serper_api_key
|
|
432
|
+
VALUE_SERP_API_KEY=your_value_serp_api_key
|
|
433
|
+
STABILITY_API_KEY=your_stability_api_key
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Async Support
|
|
437
|
+
|
|
438
|
+
Most functions support async operations:
|
|
439
|
+
|
|
440
|
+
```python
|
|
441
|
+
import asyncio
|
|
442
|
+
from SimplerLLM.language.llm import LLM, LLMProvider
|
|
443
|
+
from SimplerLLM.language.llm_addons import generate_pydantic_json_model_async
|
|
444
|
+
|
|
445
|
+
async def main():
|
|
446
|
+
llm = LLM.create(provider=LLMProvider.OPENAI, model_name="gpt-4o")
|
|
447
|
+
|
|
448
|
+
# Async response generation
|
|
449
|
+
response = await llm.generate_response_async(prompt="What is async programming?")
|
|
450
|
+
print(response)
|
|
451
|
+
|
|
452
|
+
# Async JSON generation
|
|
453
|
+
result = await generate_pydantic_json_model_async(
|
|
454
|
+
llm_instance=llm,
|
|
455
|
+
prompt="Generate a product review",
|
|
456
|
+
model_class=MovieRecommendation
|
|
457
|
+
)
|
|
458
|
+
print(result)
|
|
459
|
+
|
|
460
|
+
asyncio.run(main())
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
## Error Handling and Best Practices
|
|
464
|
+
|
|
465
|
+
### Robust Error Handling
|
|
466
|
+
|
|
467
|
+
```python
|
|
468
|
+
from SimplerLLM.language.llm import LLM, LLMProvider
|
|
469
|
+
from SimplerLLM.language.llm_addons import generate_pydantic_json_model
|
|
470
|
+
|
|
471
|
+
try:
|
|
472
|
+
llm = LLM.create(provider=LLMProvider.OPENAI, model_name="gpt-4o")
|
|
473
|
+
|
|
474
|
+
result = generate_pydantic_json_model(
|
|
475
|
+
llm_instance=llm,
|
|
476
|
+
prompt="Generate a summary",
|
|
477
|
+
model_class=MovieRecommendation,
|
|
478
|
+
max_retries=3
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
if isinstance(result, str): # Error case
|
|
482
|
+
print(f"Error: {result}")
|
|
483
|
+
else:
|
|
484
|
+
print(f"Success: {result}")
|
|
485
|
+
|
|
486
|
+
except Exception as e:
|
|
487
|
+
print(f"Exception: {e}")
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### Cost Calculation
|
|
491
|
+
|
|
492
|
+
```python
|
|
493
|
+
from SimplerLLM.language.llm_addons import calculate_text_generation_costs
|
|
494
|
+
|
|
495
|
+
input_text = "Your input prompt here"
|
|
496
|
+
output_text = "Generated response here"
|
|
497
|
+
|
|
498
|
+
cost_info = calculate_text_generation_costs(
|
|
499
|
+
input=input_text,
|
|
500
|
+
response=output_text,
|
|
501
|
+
cost_per_million_input_tokens=2.50, # Example: GPT-4 pricing
|
|
502
|
+
cost_per_million_output_tokens=10.00,
|
|
503
|
+
approximate=True # Use approximate token counting
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
print(f"Input tokens: {cost_info['input_tokens']}")
|
|
507
|
+
print(f"Output tokens: {cost_info['output_tokens']}")
|
|
508
|
+
print(f"Total cost: ${cost_info['total_cost']:.6f}")
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
## License
|
|
512
|
+
|
|
513
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
514
|
+
|
|
515
|
+
## Support
|
|
516
|
+
|
|
517
|
+
- [📖 Documentation](https://docs.simplerllm.com/)
|
|
518
|
+
- [💬 Discord Community](https://discord.gg/HUrtZXyp3j)
|
|
519
|
+
|
|
520
|
+
---
|
|
521
|
+
|
|
522
|
+
**SimplerLLM** - Making AI development simpler, one line of code at a time.
|