Skip to content

word ботяра removed from the LLM prompt #97

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

Merged
merged 3 commits into from
Apr 20, 2025
Merged

word ботяра removed from the LLM prompt #97

merged 3 commits into from
Apr 20, 2025

Conversation

ovchynnikov
Copy link
Owner

@ovchynnikov ovchynnikov commented Apr 20, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved message preprocessing by removing the bot mention and trailing punctuation before generating responses, resulting in more accurate replies.

@ovchynnikov ovchynnikov self-assigned this Apr 20, 2025
Copy link
Contributor

coderabbitai bot commented Apr 20, 2025

"""

Walkthrough

The update introduces preprocessing of incoming message text in the respond_with_llm_message function by removing the specific bot mention "ботяра" and any trailing punctuation before sending the prompt to the LLM API. This is achieved by importing and utilizing the re module. Additional changes include formatting adjustments for improved readability, such as breaking up long statements, reformatting environment variable assignments, and updating logging and list comprehensions. No changes were made to function signatures or the core logic of message handling, media processing, or error handling.

Changes

File(s) Summary of Changes
src/main.py Imported re module; updated respond_with_llm_message to strip bot mention and punctuation from prompts; reformatted environment variable assignment, logging, and list comprehensions for readability; no changes to function signatures or core logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Bot
    participant LLM_API

    User->>Bot: Send message (may include "ботяра")
    Bot->>Bot: Preprocess message (remove "ботяра" and punctuation)
    Bot->>LLM_API: Send cleaned prompt
    LLM_API-->>Bot: Return response
    Bot-->>User: Send LLM response
Loading

Possibly related PRs

  • Dev > main; LLM response added #90: Refines the preprocessing of prompt text in the same respond_with_llm_message function, directly building upon and modifying its internal logic.
  • Dev #91: Modifies message text preprocessing for bot mentions in src/main.py, focusing on detection and cleaning of bot mentions.
  • LLM Identify the language #93: Also modifies respond_with_llm_message to preprocess or transform the prompt before sending it to the LLM API, related to input message preparation.
    """

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f23d178 and b303526.

📒 Files selected for processing (1)
  • src/main.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main.py

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main.py (1)

456-465: Consider using a single with statement for better readability

The nested with statements can be combined into a single statement with multiple contexts.

- async with aiohttp.ClientSession() as session:
-     async with session.post(
-         f"{LLM_API_ADDR}/api/generate",
-         json={
-             "model": LLM_MODEL,
-             "prompt": prompt,
-             "stream": False,
-             "num_predict": 200
-         },
-     ) as response:
+ async with aiohttp.ClientSession() as session, session.post(
+     f"{LLM_API_ADDR}/api/generate",
+     json={
+         "model": LLM_MODEL,
+         "prompt": prompt,
+         "stream": False,
+         "num_predict": 200
+     },
+ ) as response:
🧰 Tools
🪛 Ruff (0.8.2)

456-465: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c759b07 and fa5e8a5.

📒 Files selected for processing (1)
  • src/main.py (8 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
src/main.py

456-465: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)

🪛 GitHub Actions: 📝 Linters
src/main.py

[error] 1-1: Black formatting check failed. The file would be reformatted. Run 'black --write' to fix code style issues.

🔇 Additional comments (12)
src/main.py (12)

24-24: Addition of regex module for text preprocessing

This addition of the re module is necessary for the implementation of the bot mention removal functionality in the respond_with_llm_message function.


35-36: Improved readability with proper line breaks

The environment variable assignment has been properly formatted with line breaks for better readability.


107-108: Improved formatting for list comprehension

The list comprehension has been properly formatted with line breaks for better readability.


236-237: Improved formatting for debug statement

The debug statement has been properly formatted with line breaks for better readability.


267-268: Improved formatting for video grouping logic

The list comprehension for grouping videos has been properly formatted with line breaks for better readability.


274-275: Improved formatting for picture grouping logic

The list comprehension for grouping pictures has been properly formatted with line breaks for better readability.


314-317: Improved formatting for info logging

The random choice selection and info logging have been properly formatted with line breaks for better readability.


452-453: Effectively removes "ботяра" from LLM prompts

This is the core change that implements the PR objective. The regex pattern r'ботяра[^\w\s]*' effectively removes the bot mention "ботяра" and any trailing punctuation from the message before sending it to the LLM API. This results in cleaner, more focused prompts.


459-464: Improved JSON formatting in API request

The JSON payload for the LLM API request has been properly formatted with line breaks for better readability.


468-469: Improved formatting for response data extraction

The response data extraction has been properly formatted with line breaks for better readability.


513-514: Improved formatting for message handler registration

The message handler registration has been properly formatted with line breaks for better readability.


1-523:

❓ Verification inconclusive

Fix Black formatting issues

The pipeline is reporting that Black formatting check failed. Consider running Black to automatically fix code style issues.


🏁 Script executed:

#!/bin/bash
# Check what changes Black would make
black --diff src/main.py

Length of output: 122


Ensure Black is available and format the code

The CI check failed because black is not installed in the environment. Please:

  • Add Black to your development dependencies (e.g., pip install --dev black)
  • Run black src/main.py locally to apply the formatter
  • Commit and push the changes so the pipeline passes
🧰 Tools
🪛 Ruff (0.8.2)

368-368: Use a context manager for opening files

(SIM115)


425-425: Use a context manager for opening files

(SIM115)


456-465: Use a single with statement with multiple contexts instead of nested with statements

(SIM117)

🪛 GitHub Actions: 📝 Linters

[error] 1-1: Black formatting check failed. The file would be reformatted. Run 'black --write' to fix code style issues.

@ovchynnikov ovchynnikov merged commit 9055c33 into main Apr 20, 2025
7 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.

1 participant