-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,81 @@ | ||||||||||||||||||
| # command: askllm | ||||||||||||||||||
|
|
||||||||||||||||||
| export ASKLLM_MISTRAL_API_KEY="mistral-api-key" | ||||||||||||||||||
| export ASKLLM_MODEL="codestral-latest" | ||||||||||||||||||
| export ASKLLM_SYSTEM_PROMPT="You are an assistant created to help manage the Linux system in the terminal. Your task is to provide short and appropriate solutions to the problems described in the user's message without unnecessary testing. If you do not understand the task or have insufficient information, ask the user to provide more. Reply briefly and accurately, without using markdown or other text formatting - only plaintext." | ||||||||||||||||||
|
|
||||||||||||||||||
| askllm() { | ||||||||||||||||||
| local -a ROLES=() | ||||||||||||||||||
| local -a CONTENTS=() | ||||||||||||||||||
| ROLES+=("system") | ||||||||||||||||||
| CONTENTS+=("$ASKLLM_SYSTEM_PROMPT") | ||||||||||||||||||
|
|
||||||||||||||||||
| while true; do | ||||||||||||||||||
| if [[ -z "$ASKLLM_MISTRAL_API_KEY" ]]; then | ||||||||||||||||||
| echo -e "\033[31mERROR: ASKLLM_MISTRAL_API_KEY not set.\033[0m" | ||||||||||||||||||
| return 1 | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| echo -e "\033[36mEnter query (empty to exit, 'clear' to reset history):\033[0m" | ||||||||||||||||||
| USER_INPUT=$(cat) | ||||||||||||||||||
|
||||||||||||||||||
| USER_INPUT=$(cat) | |
| read -r USER_INPUT |
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}") |
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 |
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.