|
6 | 6 |
|
7 | 7 | [ -z "$1" ] && echo "Usage: ,ask [s] <your question>"
|
8 | 8 |
|
| 9 | +questionsPrompt="You are a document search who helps people find the right search statements. |
| 10 | +They will provide you with a query and you'll provide them with possible search statements to find the relevant docs. |
| 11 | +Give only the statements. Each question should be a single line. |
| 12 | +
|
| 13 | +Additional instructions: |
| 14 | +- Keep statements simple and broad |
| 15 | +- Try to cover all aspects of the query |
| 16 | +- Split the different aspects of the question into different statements |
| 17 | +- Only give 15 |
| 18 | +- No additional formatting like numbering |
| 19 | +
|
| 20 | +Example output for the query 'How can I create a user-role and bind that to a custom role? Show me curl commands': |
| 21 | +
|
| 22 | +creating roles |
| 23 | +creating user-roles |
| 24 | +api routes for roles |
| 25 | +api routes for user-roles |
| 26 | +binding user-roles to custom roles" |
| 27 | + |
| 28 | +short="" |
9 | 29 | if [ "$1" = "s" ]; then
|
10 | 30 | shift
|
11 |
| - refer search --format llm "$*" | |
12 |
| - aichat --prompt "Using the provided context, answer my follow-up question concisely. Do not make up answers if not available in the provided context." "$*" |
13 |
| -else |
14 |
| - refer search --format llm "$*" | |
15 |
| - aichat --prompt "Using the provided context, answer my follow-up question. Do not make up answers if not available in the provided context." "$*" |
| 31 | + short="true" |
16 | 32 | fi
|
| 33 | +query="$*" |
| 34 | + |
| 35 | +printf "Finding the right questions to ask...\r" >&2 |
| 36 | +questions="$(aichat --prompt "$questionsPrompt" "$query" | grep -v '^$')" |
| 37 | + |
| 38 | +printf "\033[2K" |
| 39 | +printf "\033[90m%s\033[0m\n" "# Refined questions" >&2 |
| 40 | +echo "$questions" | while read -r question; do |
| 41 | + printf "\033[90m%s\033[0m\n" "$question" >&2 |
| 42 | +done |
| 43 | + |
| 44 | +printf "\nFinding the right documents to refer...\r" >&2 |
| 45 | +allDocuments="$( { echo "$questions"; echo "$query"; } | xargs -I{} refer search '{}')" |
| 46 | +uniqueDocuments="$(echo "$allDocuments" | cut -d: -f1 | sort | uniq)" |
| 47 | + |
| 48 | +# TODO(meain): Introduce a reranker and limit to maybe 5 |
| 49 | +context="$(echo "$uniqueDocuments" | while read -r doc; do |
| 50 | + echo "--------------------------------------------------------------" |
| 51 | + echo |
| 52 | + printf "Filename: " |
| 53 | + refer show "$doc" |
| 54 | + echo |
| 55 | +done)" |
| 56 | +
|
| 57 | +printf "\033[2K" |
| 58 | +printf "\033[90m%s\033[0m\n" "# Files referred" >&2 |
| 59 | +echo "$uniqueDocuments" | while read -r doc; do |
| 60 | + printf "\033[90m%s\033[0m\n" "$(refer show "$doc" | head -n1)" >&2 |
| 61 | +done |
| 62 | +echo >&2 |
| 63 | +
|
| 64 | +responseQuery="You will be given a context and a follow-up question. Your task is to answer the question concisely using only the information provided in the context. Here's how to approach this task: |
| 65 | +
|
| 66 | +To answer the question: |
| 67 | +
|
| 68 | +1. Carefully analyze the context to find relevant information. |
| 69 | +2. If the answer is explicitly stated in the context, provide that answer. |
| 70 | +3. If the answer can be inferred from the information given, explain your reasoning briefly. |
| 71 | +4. If the question cannot be answered based on the context provided, state that the information is not available. |
| 72 | +
|
| 73 | +Important guidelines: |
| 74 | +- Only use information from the given context. Do not include any external knowledge or assumptions. |
| 75 | +- Be concise in your response. Aim for clarity and brevity. |
| 76 | +- If the context doesn't provide enough information to answer the question fully, it's okay to say so. |
| 77 | +- Do not make up or speculate on information that is not present in the context. |
| 78 | +- If you quote directly from the context, use quotation marks. |
| 79 | +
|
| 80 | +Remember, it's better to admit when information is not available than to provide an incorrect or speculative answer." |
| 81 | +
|
| 82 | +echo "$context" | |
| 83 | + if [ -n "$short" ]; then |
| 84 | + aichat --prompt "$responseQuery Keep your answers super short and concise." "$query" |
| 85 | + else |
| 86 | + aichat --prompt "$responseQuery" "$query" |
| 87 | + fi |
0 commit comments