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

Feature/prompt blueprint #48

Merged
merged 11 commits into from
Jul 5, 2024
Merged

Feature/prompt blueprint #48

merged 11 commits into from
Jul 5, 2024

Conversation

dockhardman
Copy link
Owner

Summary of Changes

This PR introduces several modifications to the languru package, primarily focusing on restructuring and enhancing the prompt template functionality. The changes can be categorized as follows:

Prompt Template Enhancements

  1. Renamed base.py to prompt_template.py and updated related imports.
  2. Extended the PromptTemplate class with new methods and properties:
    • Added from_description class method for creating instances from prompt descriptions.
    • Implemented md5 and md5_formatted properties for generating hash representations.
  3. Introduced new utility functions in chat.py for handling chat completions.

Code Organization

  1. Moved ensure_openai_chat_completion_content and ensure_openai_chat_completion_message_params from common.py to openai_utils.py.
  2. Created new files assistant.py and user.py in the prompts/repositories/ directory to store prompt-related constants.

Dependency Updates

  1. Updated several package versions in poetry.lock, including anthropic, google-ai-generativelanguage, google-api-python-client, google-auth, google-generativeai, mkdocs-material, openai, orjson, and pillow.

Minor Adjustments

  1. Removed unused imports and adjusted import statements in various files.
  2. Updated type hints and docstrings for better code clarity.

- Create explanations.py with detailed CO-STAR framework explanation
- Add questions.py with CO-STAR framework question
- Implement string variables using Final[Text] typing
- Use dedent for multiline strings in both files
- Move assistant explanations to new `assistant.py` file
- Rename `questions.py` to `user.py` for user-related prompts
- Add `request_to_rewrite_as_costar` function in `user.py`
- Remove redundant `explanations.py` file

This refactoring improves code organization by separating
assistant and user-related prompt functions, enhancing
maintainability and readability of the CO-STAR framework
implementation.
- Introduce `from_description` class method in PromptTemplate
- Implement OpenAI-based prompt generation with example handling
- Add support for verbose output and error handling
- Enhance type hinting and import necessary utilities
…ocumentation

- Rename languru/prompts/base.py to languru/prompts/prompt_template.py
- Update import statements in __init__.py files to reflect the new module name
- Add comprehensive docstring to PromptTemplate class method in prompt_template.py
- Refine instructions for CO-STAR framework in user.py

This change improves code organization and enhances documentation for better
maintainability and user understanding.
- Create new test file tests/prompts/test_prompt_template.py
- Implement test_prompt_template_from_description function
- Verify PromptTemplate creation with PerplexityOpenAI client
- Use "llama-3-sonar-small-32k-chat" model for testing
- Assert the existence of the prompt attribute in the template

This test ensures the correct functionality of the PromptTemplate
class when creating instances from descriptions, improving the
overall test coverage of the prompts module.
- Move OpenAI-specific utilities to dedicated module
- Add MD5 hash properties to PromptTemplate for message fingerprinting
- Update imports across affected modules and tests
- Remove redundant prompt utility module
- Move MD5 hash generation logic to `messages_to_md5` function in openai_utils.py
- Update PromptTemplate to use the new function for hash generation
- Add comprehensive test cases for PromptTemplate operations
- Remove unused imports and perform minor code cleanup
- Implement `chat_completion_once` function in new file `languru/utils/chat.py`
- Support multiple input types: message list, query, and system message
- Handle prompt variable replacement and message conversion
- Integrate with OpenAI's latest Python client
- Add verbose logging option for debugging
- Import `chat_completion_once` and remove unused OpenAI utility functions
- Update PromptTemplate initialization:
  - Increase default temperature from 0.3 to 0.7
  - Simplify chat completion process using `chat_completion_once`
- Improve example generation:
  - Streamline message creation and formatting
  - Enhance prompt construction with examples
- Adjust prompt formatting in user repository
- Optimize multiple_replace function usage in chat completion
Copy link

codecov bot commented Jul 5, 2024

Codecov Report

Attention: Patch coverage is 76.99115% with 26 lines in your changes missing coverage. Please review.

Project coverage is 81.12%. Comparing base (24d0656) to head (fa0eb43).

Files Patch % Lines
languru/utils/openai_utils.py 48.48% 17 Missing ⚠️
languru/utils/chat.py 82.14% 5 Missing ⚠️
languru/prompts/prompt_template.py 92.50% 3 Missing ⚠️
languru/utils/common.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #48      +/-   ##
==========================================
+ Coverage   79.98%   81.12%   +1.14%     
==========================================
  Files          62       64       +2     
  Lines        2143     2215      +72     
==========================================
+ Hits         1714     1797      +83     
+ Misses        429      418      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dockhardman dockhardman merged commit 8e143a5 into master Jul 5, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant