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

Simplify message creation and rename files #10

Merged
merged 5 commits into from
Jan 22, 2025

Conversation

mentatai[bot]
Copy link
Contributor

@mentatai mentatai bot commented Jan 22, 2025

This PR implements the following changes:

  1. Created a Messages class that provides a simpler interface for creating messages:

    messages = Messages()
    messages.add_system("You are a helpful assistant")
    messages.add_user("What's the capital of France?")
  2. Renamed files for clarity:

    • openai_client.py -> llm_utils.py
    • test_openai.py -> test_llm_utils.py
  3. Removed direct dependencies on OpenAI types in the public interface

Closes #9

🤖 See my steps and track the cost of the PR here

This PR implements the following changes:
1. Created a Messages class that provides a simpler interface for creating messages:
   ```python
   messages = Messages()
   messages.add_system("You are a helpful assistant")
   messages.add_user("What's the capital of France?")
   ```

2. Renamed files for clarity:
   - openai_client.py -> llm_utils.py
   - test_openai.py -> test_llm_utils.py

3. Removed direct dependencies on OpenAI types in the public interface

Closes # 9
@mentatai mentatai bot requested a review from biobootloader January 22, 2025 22:38
Copy link
Contributor Author

@mentatai mentatai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an example of how the new interface simplifies message creation compared to the old approach:

Before:

messages = [
    cast(ChatCompletionSystemMessageParam, {
        "role": "system",
        "content": "You are a helpful assistant."
    }),
    cast(ChatCompletionUserMessageParam, {
        "role": "user",
        "content": "What's the best way to learn Python?"
    })
]

After:

messages = Messages()
messages.add_system("You are a helpful assistant.")
messages.add_user("What's the best way to learn Python?")

The new interface:

  • Eliminates the need to import OpenAI types
  • Removes type casting boilerplate
  • Makes the code more readable and maintainable
  • Still maintains type safety internally

Let me know if you'd like any adjustments to the implementation!

Thanks for using MentatBot. Give comments a 👍 or 👎 to help me improve!
You can change my review settings on my settings page.

mentatai bot added 4 commits January 22, 2025 22:38
- Remove unused OpenAI type imports
- Sort imports alphabetically
- Add proper type annotations for OpenAI message types
- Use type casting to ensure message compatibility
- Update return type of get_messages()
Fix the last linting issue by removing the unused Any import from typing.
- Make Messages class iterable for OpenAI client compatibility
- Use Sequence instead of List for better type compatibility
- Fix TypedDict access warnings
- Improve type hints in get_completion function
@biobootloader biobootloader merged commit 812b9d3 into main Jan 22, 2025
1 check 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.

simplify message creation
1 participant