-
Notifications
You must be signed in to change notification settings - Fork 6
LLM parameters added to json #107
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
Conversation
WalkthroughThe update modifies the JSON payload in the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API Handler (respond_with_llm_message)
participant LLM API
Client->>API Handler (respond_with_llm_message): Send message/request
API Handler->>LLM API: POST request with updated parameters (temperature=0.8, top_k, top_p, etc.)
LLM API-->>API Handler: Return response
API Handler-->>Client: Return processed LLM response
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main.py (1)
492-500
: Add logging for LLM errors.The error handling is good, but the errors are only printed to stdout. Consider using the same logging approach as elsewhere in the file.
await update.message.reply_text(bot_response) except (aiohttp.ClientResponseError, aiohttp.ContentTypeError) as e: - print(f"Response error in LLM request: {e}") + error(f"Response error in LLM request: %s", e) await update.message.reply_text("Sorry, I received an invalid response from the AI service.") except aiohttp.ClientError as e: - print(f"Network error in LLM request: {e}") + error(f"Network error in LLM request: %s", e) await update.message.reply_text("Sorry, I couldn't connect to the AI service.") except ValueError as e: - print(f"Data processing error in LLM request: {e}") + error(f"Data processing error in LLM request: %s", e) await update.message.reply_text("Sorry, I had trouble processing the AI service response.")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (1)
src/main.py
(1 hunks)
"temperature": 0.8, | ||
"top_k": 40, | ||
"top_p": 0.95, | ||
"min_p": 0.05, | ||
"dynatemp_range": 0, | ||
"dynatemp_exponent": 1, | ||
"typical_p": 1, | ||
"xtc_probability": 0, | ||
"xtc_threshold": 0.1, | ||
"repeat_last_n": 64, | ||
"repeat_penalty": 1, | ||
"presence_penalty": 0, | ||
"frequency_penalty": 0, | ||
"dry_multiplier": 0, | ||
"dry_base": 1.75, | ||
"dry_allowed_length": 2, | ||
"dry_penalty_last_n": -1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider adding documentation and making LLM parameters configurable.
The addition of these LLM parameters provides more fine-grained control over text generation, which is good. However, these values are hardcoded with no explanation of their purpose or why these specific values were chosen. This could make maintenance challenging for future developers.
Consider the following improvements:
- Add comments explaining what each parameter does and why these values were selected
- Make critical parameters configurable through environment variables (similar to how you handle
LLM_API_ADDR
)
async def respond_with_llm_message(update):
"""Handle LLM responses when bot is mentioned."""
message_text = update.message.text
# Remove bot mention and any punctuation after it
prompt = re.sub(r'ботяра[^\w\s]*', '', message_text.lower()).strip()
+ # Load LLM parameters from environment variables or use defaults
+ temperature = float(os.getenv("LLM_TEMPERATURE", "0.8"))
+ top_k = int(os.getenv("LLM_TOP_K", "40"))
+ top_p = float(os.getenv("LLM_TOP_P", "0.95"))
try:
async with aiohttp.ClientSession() as session:
async with session.post(
f"{LLM_API_ADDR}/completion",
json={
"prompt": prompt,
"n_predict": 1024,
- "temperature": 0.8,
- "top_k": 40,
- "top_p": 0.95,
+ "temperature": temperature, # Controls randomness in text generation
+ "top_k": top_k, # Limits token selection to the k most likely tokens
+ "top_p": top_p, # Nucleus sampling threshold
"min_p": 0.05,
"dynatemp_range": 0,
"dynatemp_exponent": 1,
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"temperature": 0.8, | |
"top_k": 40, | |
"top_p": 0.95, | |
"min_p": 0.05, | |
"dynatemp_range": 0, | |
"dynatemp_exponent": 1, | |
"typical_p": 1, | |
"xtc_probability": 0, | |
"xtc_threshold": 0.1, | |
"repeat_last_n": 64, | |
"repeat_penalty": 1, | |
"presence_penalty": 0, | |
"frequency_penalty": 0, | |
"dry_multiplier": 0, | |
"dry_base": 1.75, | |
"dry_allowed_length": 2, | |
"dry_penalty_last_n": -1, | |
async def respond_with_llm_message(update): | |
"""Handle LLM responses when bot is mentioned.""" | |
message_text = update.message.text | |
# Remove bot mention and any punctuation after it | |
prompt = re.sub(r'ботяра[^\w\s]*', '', message_text.lower()).strip() | |
# Load LLM parameters from environment variables or use defaults | |
temperature = float(os.getenv("LLM_TEMPERATURE", "0.8")) | |
top_k = int(os.getenv("LLM_TOP_K", "40")) | |
top_p = float(os.getenv("LLM_TOP_P", "0.95")) | |
try: | |
async with aiohttp.ClientSession() as session: | |
async with session.post( | |
f"{LLM_API_ADDR}/completion", | |
json={ | |
"prompt": prompt, | |
"n_predict": 1024, | |
"temperature": temperature, # Controls randomness in text generation | |
"top_k": top_k, # Limits token selection to the k most likely tokens | |
"top_p": top_p, # Nucleus sampling threshold | |
"min_p": 0.05, | |
"dynatemp_range": 0, | |
"dynatemp_exponent": 1, | |
"typical_p": 1, | |
"xtc_probability": 0, | |
"xtc_threshold": 0.1, | |
"repeat_last_n": 64, | |
"repeat_penalty": 1, | |
"presence_penalty": 0, | |
"frequency_penalty": 0, | |
"dry_multiplier": 0, | |
"dry_base": 1.75, | |
"dry_allowed_length": 2, | |
"dry_penalty_last_n": -1, | |
}, | |
) as resp: | |
# … |
🤖 Prompt for AI Agents
In src/main.py around lines 465 to 481, the LLM parameters are hardcoded without
any comments explaining their purpose or rationale for chosen values, which
hinders maintainability. Add inline comments for each parameter describing its
function and why the specific value was selected. Additionally, refactor the
code to load critical parameters from environment variables with sensible
defaults, similar to the existing LLM_API_ADDR handling, to make them
configurable without code changes.
Summary by CodeRabbit
New Features
Style