(system_prompt: str, initial_query: str, client, model: str)
| 91 | return margins, response.usage.completion_tokens |
| 92 | |
| 93 | def run(system_prompt: str, initial_query: str, client, model: str) -> Tuple[str, int]: |
| 94 | memory = Memory() |
| 95 | query, context = extract_query(initial_query) |
| 96 | completion_tokens = 0 |
| 97 | |
| 98 | # Process context and add to memory |
| 99 | chunk_size = 100000 |
| 100 | for i in range(0, len(context), chunk_size): |
| 101 | chunk = context[i:i+chunk_size] |
| 102 | # print(f"chunk: {chunk}") |
| 103 | key_info, tokens = extract_key_information(system_prompt, chunk, query, client, model) |
| 104 | #print(f"key info: {key_info}") |
| 105 | completion_tokens += tokens |
| 106 | for info in key_info: |
| 107 | memory.add(info) |
| 108 | # print(f"query : {query}") |
| 109 | # Retrieve relevant information from memory |
| 110 | relevant_info = memory.get_relevant(query) |
| 111 | # print(f"relevant_info : {relevant_info}") |
| 112 | # Generate response using relevant information |
| 113 | messages = [ |
| 114 | {"role": "system", "content": system_prompt}, |
| 115 | {"role": "user", "content": f""" |
| 116 | |
| 117 | I asked my assistant to read and analyse the above content page by page to help you complete this task. These are margin notes left on each page: |
| 118 | '''text |
| 119 | {relevant_info} |
| 120 | ''' |
| 121 | Read again the note(s), take a deep breath and answer the query. |
| 122 | {query} |
| 123 | """} |
| 124 | ] |
| 125 | |
| 126 | response = client.chat.completions.create( |
| 127 | model=model, |
| 128 | messages=messages, |
| 129 | ) |
| 130 | # print(f"response : {response}") |
| 131 | final_response = response.choices[0].message.content.strip() |
| 132 | completion_tokens += response.usage.completion_tokens |
| 133 | # print(f"final_response: {final_response}") |
| 134 | return final_response, completion_tokens |
nothing calls this directly
no test coverage detected