lukestanley commited on
Commit
fbb0bdf
1 Parent(s): a96b492

Make reusable via CLI, and modue, moved core logic to improvement_loop.

Browse files
Files changed (1) hide show
  1. chill.py +40 -22
chill.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import json
2
  import time
3
  from utils import calculate_overall_score, query_ai_prompt
@@ -17,7 +18,9 @@ from promptObjects import (
17
  # python3 -m llama_cpp.server --model mixtral-8x7b-instruct-v0.1.Q4_K_M.gguf --port 5834 --n_ctx 4096 --use_mlock false
18
  # Run this script:
19
  # python3 chill.py
20
- # This should then try and improve the original text below:
 
 
21
 
22
  original_text = """Stop chasing dreams instead. Life is not a Hollywood movie. Not everyone is going to get a famous billionaire. Adjust your expectations to reality, and stop thinking so highly of yourself, stop judging others. Assume the responsibility for the things that happen in your life. It is kind of annoying to read your text, it is always some external thing that "happened" to you, and it is always other people who are not up to your standards. At some moment you even declare with despair. And guess what? This is true and false at the same time, in a fundamental level most people are not remarkable, and you probably aren't too. But at the same time, nobody is the same, you have worth just by being, and other people have too. The impression I get is that you must be someone incredibly annoying to work with, and that your performance is not even nearly close to what you think it is, and that you really need to come down to earth. Stop looking outside, work on yourself instead. You'll never be satisfied just by changing jobs. Do therapy if you wish, become acquainted with stoicism, be a volunteer in some poor country, whatever, but do something to regain control of your life, to get some perspective, and to adjust your expectations to reality."""
23
  # From elzbardico on https://news.ycombinator.com/item?id=36119858
@@ -40,7 +43,7 @@ start_time = time.time()
40
  max_iterations = 20
41
 
42
 
43
- def improve_text():
44
  global suggestions
45
  replacements = {
46
  "original_text": json.dumps(original_text),
@@ -108,26 +111,41 @@ def print_iteration_result(iteration, overall_score, time_used):
108
  print(json.dumps(suggestions, indent=2))
109
 
110
 
111
- for iteration in range(1, max_iterations + 1):
112
- try:
113
- if iteration % 2 == 1:
114
- last_edit = improve_text()
115
- else:
116
- critique_dict = critique_text(last_edit)
117
- update_suggestions(critique_dict)
118
- overall_score = critique_dict["overall_score"]
119
- time_used = time.time() - start_time
120
-
121
- print_iteration_result(iteration, overall_score, time_used)
122
-
123
- if should_stop(iteration, overall_score, time_used):
124
- print(
125
- "Stopping\nTop suggestion:\n", json.dumps(suggestions[0], indent=4)
126
- )
127
- break
128
- except ValueError as e:
129
- print("ValueError:", e)
130
- continue
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
  # TODO: Segment the text into sentences for parallel processing, and isolate the most problematic parts for improvement
133
  """
 
1
+ import argparse
2
  import json
3
  import time
4
  from utils import calculate_overall_score, query_ai_prompt
 
18
  # python3 -m llama_cpp.server --model mixtral-8x7b-instruct-v0.1.Q4_K_M.gguf --port 5834 --n_ctx 4096 --use_mlock false
19
  # Run this script:
20
  # python3 chill.py
21
+ # This should then try and improve the original text below.
22
+ # Or you could import the improvement_loop function with a string as an argument to improve a specific text,
23
+ # or use it as a command line tool with the -t flag to improve a specific text.
24
 
25
  original_text = """Stop chasing dreams instead. Life is not a Hollywood movie. Not everyone is going to get a famous billionaire. Adjust your expectations to reality, and stop thinking so highly of yourself, stop judging others. Assume the responsibility for the things that happen in your life. It is kind of annoying to read your text, it is always some external thing that "happened" to you, and it is always other people who are not up to your standards. At some moment you even declare with despair. And guess what? This is true and false at the same time, in a fundamental level most people are not remarkable, and you probably aren't too. But at the same time, nobody is the same, you have worth just by being, and other people have too. The impression I get is that you must be someone incredibly annoying to work with, and that your performance is not even nearly close to what you think it is, and that you really need to come down to earth. Stop looking outside, work on yourself instead. You'll never be satisfied just by changing jobs. Do therapy if you wish, become acquainted with stoicism, be a volunteer in some poor country, whatever, but do something to regain control of your life, to get some perspective, and to adjust your expectations to reality."""
26
  # From elzbardico on https://news.ycombinator.com/item?id=36119858
 
43
  max_iterations = 20
44
 
45
 
46
+ def improve_text_attempt():
47
  global suggestions
48
  replacements = {
49
  "original_text": json.dumps(original_text),
 
111
  print(json.dumps(suggestions, indent=2))
112
 
113
 
114
+ def improvement_loop(input_text):
115
+ global original_text
116
+ original_text = input_text
117
+ for iteration in range(1, max_iterations + 1):
118
+ try:
119
+ if iteration % 2 == 1:
120
+ last_edit = improve_text_attempt()
121
+ else:
122
+ critique_dict = critique_text(last_edit)
123
+ update_suggestions(critique_dict)
124
+ overall_score = critique_dict["overall_score"]
125
+ time_used = time.time() - start_time
126
+
127
+ print_iteration_result(iteration, overall_score, time_used)
128
+
129
+ if should_stop(iteration, overall_score, time_used):
130
+ print(
131
+ "Stopping\nTop suggestion:\n",
132
+ json.dumps(suggestions[0], indent=4),
133
+ )
134
+ break
135
+ except ValueError as e:
136
+ print("ValueError:", e)
137
+ continue
138
+
139
+ return suggestions[0]
140
+
141
+
142
+ if __name__ == "__main__":
143
+ parser = argparse.ArgumentParser(description="Process and improve text.")
144
+ parser.add_argument("-t", "--text", type=str, help="Text to be improved", default=original_text)
145
+ args = parser.parse_args()
146
+
147
+ improvement_loop(args.text)
148
+
149
 
150
  # TODO: Segment the text into sentences for parallel processing, and isolate the most problematic parts for improvement
151
  """