Comments (11)
Hi @IamJasonBoy,
You can use -p flag along with cat command to provide the context. So from your example above, it will look like as follows:
cat bito.txt | bito -p prompt.txt
where prompt.txt will contain your prompt.
You can check for more such options and examples in the Readme under "Bito CLI commands" section here: https://github.com/gitbito/CLI#bito-cli-commands
from cli.
I don't quite understand, if I ask a question once. When asked the second time. The text for the second question is stored in bito.txt. How to store the first question
cat bito.txt | bito -p prompt.txt
bito.txt -> Save this text
prompt.txt -> What format are historical questions and answers stored in?
from cli.
@IamJasonBoy if I understood correctly you want to save multiple questions or have multiple prompts?
from cli.
It's contextual communication, and my second question relies on the first one.
For example,
when asking a question for the first time, write a fifty word article,
the second question to 100 words.
How to convey the content of the previous text
from cli.
Hi @IamJasonBoy ,
Currently Bito CLI does not support context out of the box, except for in chat mode. When used in non chat mode with -p option, each call uses the prompt plus the input provided for evaluating instructions in the prompt file.
We are working on supporting context, but it's not available today. We will update you once the functionality is available.
from cli.
Hi @IamJasonBoy ,
Till we have the context support implemented natively for non chat mode and make it available, one can write a shell script which maintains context and uses Bito CLI with it.
Given below is an example shell script rwc.sh
(run with context) showing how one can maintain and use context with Bito CLI (its an example provided without any warranty or guarantee, may have bugs :), one can make it better by adding validations, better way of handling input and parameter processing. Please feel free to use it, modify it based on your needs).
It takes prompt file and context file as inputs. The context is created and maintained in the context file eg:testmac ~ % echo "55" | ./rwc.sh pmultiplication.txt myctx1.txt
where pmultiplication.txt
is prompt file and myctx1.txt
is the context file. Hope this example helps with your automation in the interim.
#!/bin/bash
# If you want to debug or print each command use -x
# else set it to +x
set +x
# Number of lines to use as context from the context file
# Here we are limiting the context from the context file to max
# of 512 lines for its use as context while executing prompt
CONTEXT_LINES_TO_USE=512
# Bito CLI
BITO_CLI=`which bito`
# Temporary file to create prompt with context
# based on the prompt provided plus the existing context
PROMP_WITH_CONTEXT=ctxprompt.$$
# Temporary output file
OUTPUT_FILE=.op.$$
# from command line get first parameter to use as prompt file
PROMPT_FILE=$1
# Variable for file to maintain context
CONTEXT_FILE=$2
# create an input file based on the data provided in input which is piped
INPUT_FILE_DATA=$(cat)
# Create temporary files
touch $CONTEXT_FILE
touch $OUTPUT_FILE
# Create prompt to execute using prompt and context using
# fixed lines from previous context
echo "#context-start#" >> $PROMP_WITH_CONTEXT
tail -$CONTEXT_LINES_TO_USE $CONTEXT_FILE >> $PROMP_WITH_CONTEXT
echo "#context-end#" >> $PROMP_WITH_CONTEXT
echo "previous context is provided within '#context-start#' and '#context-end#' where User: means input provided by the user and Bito CLI: means the response. Please answer:" >> $PROMP_WITH_CONTEXT
cat $PROMPT_FILE >> $PROMP_WITH_CONTEXT
# execute the create prompt
echo $INPUT_FILE_DATA |$BITO_CLI -p $PROMP_WITH_CONTEXT > $OUTPUT_FILE
# print the output
cat $OUTPUT_FILE
# Update the context in the context file.
# The context is maintained as
# User:
# content of the prompt with input
# Bito CLI:
# output from Bito CLI
echo "User:" >> $CONTEXT_FILE
# Check if {{%input%}} is used in prompt file
# if yes replace it with the input provided
# if not append the input after the prompt
if grep -q "{{%input%}}" "$PROMPT_FILE"; then
sed "s/{{%input%}}/$(echo $INPUT_FILE_DATA| sed 's/$/\\n/' | tr -d '\n')/g" $PROMPT_FILE >> $CONTEXT_FILE
else
cat $PROMPT_FILE >> $CONTEXT_FILE
echo $INPUT_FILE_DATA >> $CONTEXT_FILE
fi
# Add the output to the context file
echo "Bito CLI:" >> $CONTEXT_FILE
# remove all the temporary files
cat $OUTPUT_FILE >> $CONTEXT_FILE
# Remove temporary files
rm $OUTPUT_FILE $PROMP_WITH_CONTEXT $INPUT_FILE
Given below is an example run:
testmac ~ % echo "55" | ./rwc.sh pmultiplication.txt myctx1.txt
Sure, here's the multiplication table for 55:
55 x 1 = 55
55 x 2 = 110
55 x 3 = 165
55 x 4 = 220
55 x 5 = 275
55 x 6 = 330
55 x 7 = 385
55 x 8 = 440
55 x 9 = 495
55 x 10 = 550
testmac ~ % echo "awk" | ./rwc.sh pwhatis.txt myctx1.txt
awk is a command-line tool used for text processing and searching. It is typically used for manipulating text files and data streams, and is designed to be highly flexible and customizable.
testmac ~ % echo "what are the questions i have asked till now" | ./rwc.sh emptyprompt.txt myctx1.txt
From the provided context, you have asked for:
1. "print multiplication table for the following number: 55"
2. "Please answer what is following: awk"
testmac ~ %
Given below are the prompt files use in the above example run:
pmultiplication.txt
print multiplication table for the following number:
pwhatis.txt
Please answer what is following:
{{%input%}}
emptyprompt.txt
is an empty file
Given below is the content of the context file myctx1.txt
created based on the example run mentioned above:
testmac ~ % cat myctx1.txt
User:
print multiplication table for the following number:
55
Bito CLI:
Sure, here's the multiplication table for 55:
55 x 1 = 55
55 x 2 = 110
55 x 3 = 165
55 x 4 = 220
55 x 5 = 275
55 x 6 = 330
55 x 7 = 385
55 x 8 = 440
55 x 9 = 495
55 x 10 = 550
User:
Please answer what is following:
awk
Bito CLI:
awk is a command-line tool used for text processing and searching. It is typically used for manipulating text files and data streams, and is designed to be highly flexible and customizable.
User:
what are the questions i have asked till now
Bito CLI:
From the provided context, you have asked for:
1. "print multiplication table for the following number: 55"
2. "Please answer what is following: awk"
With a multiline file as input:
cmdlist.txt
contains list of commands
testmac ~ % cat cmdlist.txt
awk
lex
grep
sed
pexplaincommand.txt
contains following prompt
testmac ~ % cat pexplaincommand.txt
Please explain each of the following:
{{%input%}}
Here's the output of the shell script
testmac ~ % cat t.txt | ./rwc.sh pwhatis.txt myctx1.txt
Sure, here's an explanation of each of the following terms:
1. awk - A command-line tool used for text processing and searching in Unix/Linux systems. It is designed to be highly flexible and customizable, and is typically used for manipulating text files and data streams.
2. lex - A program generator used to generate lexical analyzers (tokenizers) for text processing. It takes a set of regular expressions as input and generates code in C, which can then be compiled and run.
3. grep - A command-line tool used to search for patterns in text files. It is typically used to search for specific words or phrases within a file or directory, and can also be used to search recursively.
4. sed - A command-line tool used for text processing and editing in Unix/Linux systems. It is typically used to perform simple text transformations on an input file (or stream of data), such as search-and-replace operations or line deletions.
Hope this helps
from cli.
Thank you for your answer, although I didn't understand
from cli.
Thank you for your answer, although I didn't understand
他的意思应该是将每次的回答前面加上"Bito CLI:",添加到context文件的末尾,作为下一次询问的context.
from cli.
@IamJasonBoy ,
With the latest version 3.1 launched today, context in non-interactive mode is now supported. @macky3099 will provide some examples in comments later with some examples
from cli.
Hello @IamJasonBoy
You can now use -c flag along with cat, -p and -f flags to provide context in the non-interactive mode.
You just need to provide some filename to -c flag as an argument and keep using that same filename for -c for all your further requests to Bito.
Here is how you can do it:
- cat prompt.txt | bito -c context.txt
- bito -p prompt.txt -f file.txt -c context.txt
- echo "your query" | bito -c context.txt
I am also attaching a screenshot that shows the above examples in action:
Let us know if you face any issues.
Thanks!
from cli.
@IamJasonBoy also, do let us know if this solves your problem and if we can close this issue.
from cli.
Related Issues (20)
- Sorry, Bito is not reachable due to a network or server issue. Please try again HOT 1
- curl: (60) SSL certificate problem: HOT 2
- Bito CLI in interactive mode hangs forever HOT 5
- BitoCLI would not work on a brand new installation HOT 3
- BitoCLI: Ctrl-D is mapped to provide a date. Can you allow me to remap to Alt-X? HOT 1
- No hint indicating installation was successful in BitoCLI.msi HOT 3
- Feedback on Bito and CLI HOT 1
- Mushahid lehri HOT 2
- Left and right arrow keys support in cmd HOT 1
- getting only the code back from a local bito commandline API request HOT 4
- How to call bito in PHP to perform content interaction HOT 1
- Can pass prompt in text HOT 3
- The last code fragment not end in ``` HOT 10
- error HOT 3
- How to "Continue"? HOT 2
- Where is the source code? HOT 1
- WIN MSI - Trojan HOT 2
- cli HOT 1
- The specified executable is not a valid application for this OS platform HOT 5
- Error: Slash commands are not available for this session due to an configuration issue. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cli.