Skip to content

Commit

Permalink
now it is letting the llm control the output
Browse files Browse the repository at this point in the history
  • Loading branch information
mike dupont committed Dec 6, 2023
1 parent 7972929 commit 7eb27b3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# llama.cpp python hack

`./bin/main -m ~/.ollama/models/mistral --interactive -r STOP -p 'WHat is a tensor?'`

Will call embedding.py and then if the plugin ends in stop the results will start a new prompt for the llm.


# llama.cpp

![llama](https://user-images.githubusercontent.com/1991296/230134379-7181e485-c521-4d23-a0d6-f7b3b61ba524.png)
Expand Down
8 changes: 6 additions & 2 deletions embedding.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
print("hello llama.cpp" + llm_input)
llm_output = "Is it because of your mother that " + llm_input + "?";
print("hello llama.cpp, got input:\n" + llm_input + "\n")

if len(llm_input) > 20:
llm_output = "Reinterpret with emojis " + llm_input + "?\nSTOP";
else:
llm_output = llm_input
16 changes: 8 additions & 8 deletions examples/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ int main(int argc, char ** argv) {

struct llama_sampling_context * ctx_sampling = llama_sampling_init(sparams);
//print_fields(*ctx_sampling);

std::string last_output; // the output from python at any time
while ((n_remain != 0 && !is_antiprompt) || params.interactive) {
// predict
if (!embd.empty()) {
Expand Down Expand Up @@ -706,7 +706,7 @@ int main(int argc, char ** argv) {
// just print the whole thing
const std::string last_output1 = output_ss.str();
printf("%s",last_output1.c_str());
const std::string last_output = process_output_plugin(last_output1);
last_output = process_output_plugin(last_output1);
printf("%s",last_output.c_str());

// if not currently processing queued inputs;
Expand All @@ -716,7 +716,7 @@ int main(int argc, char ** argv) {
const int n_prev = 32;
const std::string last_output1 = llama_sampling_prev_str(ctx_sampling, ctx, n_prev);
// now plugin the python :
const std::string last_output = process_output_plugin(last_output1);
const std::string partial_output = process_output_plugin(last_output1);

is_antiprompt = false;
// Check if each of the reverse prompts appears at the end of the output.
Expand Down Expand Up @@ -783,11 +783,11 @@ int main(int argc, char ** argv) {
console::set_display(console::user_input);

std::string line;
bool another_line = true;
do {
another_line = console::readline(line, params.multiline_input);
buffer += line;
} while (another_line);
//bool another_line = true;
//do {
// another_line = console::readline(line, params.multiline_input);
buffer += last_output;
//} while (another_line);

// done taking input, reset color
console::set_display(console::reset);
Expand Down

0 comments on commit 7eb27b3

Please sign in to comment.