-
Notifications
You must be signed in to change notification settings - Fork 3
llm request from scratch <3 #2
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
base: master
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR introduces a simple LLM interaction tool that provides a command-line interface for querying Mistral AI models. The implementation creates a bash function that maintains conversation history and provides a terminal-based chat experience.
Key Changes
- Adds a new
.askllmfile containing environment variable exports and a bash function for LLM interaction - Implements conversation history management with automatic truncation to keep the last 6 exchanges
- Provides interactive terminal interface with colored output and word wrapping
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| @@ -0,0 +1,81 @@ | |||
| # command: askllm | |||
|
|
|||
| export ASKLLM_MISTRAL_API_KEY="mistral-api-key" | |||
Copilot
AI
Aug 27, 2025
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.
The API key is hardcoded as a placeholder value. This should be documented as needing user configuration, or the export should be removed entirely to require users to set their own key securely.
| export ASKLLM_MISTRAL_API_KEY="mistral-api-key" | |
| # NOTE: You must set ASKLLM_MISTRAL_API_KEY in your environment before using askllm. |
| fi | ||
|
|
||
| echo -e "\033[36mEnter query (empty to exit, 'clear' to reset history):\033[0m" | ||
| USER_INPUT=$(cat) |
Copilot
AI
Aug 27, 2025
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.
Using cat without any input source will hang indefinitely waiting for stdin. This should be read -r USER_INPUT or read -p 'prompt: ' USER_INPUT to properly capture user input.
| USER_INPUT=$(cat) | |
| read -r USER_INPUT |
| if ((${#ROLES[@]} > 7)); then | ||
| ROLES=("system" "${ROLES[@]: -6}") | ||
| CONTENTS=("${CONTENTS[0]}" "${CONTENTS[@]: -6}") |
Copilot
AI
Aug 27, 2025
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.
The history truncation logic is incorrect. When truncating to keep the last 6 exchanges plus the system prompt, the CONTENTS array should preserve the system prompt at index 0, but line 42 assumes CONTENTS[0] is always the system content which may not be true after multiple truncations.
| if ((${#ROLES[@]} > 7)); then | |
| ROLES=("system" "${ROLES[@]: -6}") | |
| CONTENTS=("${CONTENTS[0]}" "${CONTENTS[@]: -6}") | |
| CONTENTS=("$ASKLLM_SYSTEM_PROMPT" "${CONTENTS[@]: -6}") |
| max_tokens: 512, | ||
| stream: false | ||
| }')") | ||
|
|
Copilot
AI
Aug 27, 2025
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.
The error handling doesn't distinguish between API errors and missing response content. Consider checking for API error responses first (e.g., .error.message) before attempting to extract the content.
| ERROR_MSG=$(echo "$RESPONSE" | jq -r '.error.message // empty') | |
| if [[ -n "$ERROR_MSG" ]]; then | |
| echo -e "\033[31mAPI Error: $ERROR_MSG\033[0m" | |
| echo -e "\033[33mAPI response:\n$RESPONSE\033[0m" | |
| return 1 | |
| fi |
A simple implementation for fun even in someone elses cloud.