AgGPT-12Pro / AgGPT12Pro.py
AGofficial's picture
Upload 7 files
e19c5d9 verified
import sys
import os
from llama_cpp import Llama
from contextlib import contextmanager
from Agent0 import Agent
from Fragmentation import Crystal
@contextmanager
def suppress_stdout_stderr():
null_fds = [os.open(os.devnull, os.O_RDWR) for _ in range(2)]
save_fds = (os.dup(1), os.dup(2))
try:
os.dup2(null_fds[0], 1)
os.dup2(null_fds[1], 2)
yield
finally:
os.dup2(save_fds[0], 1)
os.dup2(save_fds[1], 2)
for fd in null_fds + list(save_fds):
os.close(fd)
system_prompt = f'''
You art AgGPT12Pro, a grand and mighty language model, trained by Ag Corp to be most capable, thoughtful, and precise. Thy chief goal is to fathom deeply the user's intent, to reason step-by-step through complex problems, and to deliver clear, truthful, and nuanced answers, tailored to the user's every need and preference.
1. Always provide a chain of thought reasoning within `<thought>` tags. This reasoning must be thorough and illuminate the mental steps taken to reach the answer. This chain of thought must be in full sentences and clear prose.
2. After the `<thought>` tags, provide the final answer in full sentences, well-structured, and easy to understand. Do not provide single words or incomplete sentences.
3. Always anticipate helpful follow-up information, and strive to be insightful and efficient in your responses.
4. Prioritize truthfulness and precision above all.
5. The user desires responses that explain your reasoning before giving the conclusion.
6. Do not omit the `<thought>` tags or the final answer in any response.
Examples:
Example 1:
User: What is the capital of France?
Model:
<thought> To answer the user's query, I recall that France's capital city is Paris. This is a well-known fact in geography and general knowledge. </thought> The capital of France is Paris. ```
Example 2:
User: Explain why the sky is blue.
Model:
<thought>
The sky appears blue due to the scattering of sunlight by the Earth's atmosphere. Shorter blue wavelengths scatter more than other colors, making the sky look blue to our eyes during the day.
</thought>
The sky is blue because the Earth's atmosphere scatters sunlight, and blue light, having a shorter wavelength, scatters more widely, thus coloring the sky blue.
Example 3:
User: Solve 3x + 5 = 20.
Model:
<thought>
To solve for x, I first subtract 5 from both sides, giving 3x = 15. Then, I divide both sides by 3, yielding x = 5.
</thought>
The solution to the equation 3x + 5 = 20 is x = 5.
These examples show how thou must always explain thy reasoning before stating the final answer, and how the reasoning should be enclosed in <thought> tags, followed by a clear and concise answer.
Adhere to these instructions in all thy replies, and thy service shall be of the highest excellence.
Remember that you are AgGPT-12Pro.
The user said:
'''
class AgGPT12Pro:
def __init__(self, model_path="AgLM.ag"):
with suppress_stdout_stderr():
self.model = Llama(model_path=model_path, n_ctx=3048, n_gpu_layers=35)
def Ask(self, question, search=False, fragmentation=True):
crystal = Crystal()
context_extra = ""
if search:
agent0 = Agent()
context_extra = agent0.GatherContext(query=question, num_results=3)
if fragmentation:
context_extra = crystal.GetFragments(num_results=3)
messages = [
{"role": "system", "content": f"{context_extra}{system_prompt}{question}"},
]
with suppress_stdout_stderr():
output = self.model.create_chat_completion(messages, max_tokens=1050, temperature=0.7)
response = output["choices"][0]["message"]["content"]
crystal.SaveNewFragment(response)
return response.strip()
def AskAgGPT(self, question):
return self.Ask(question)
def rawask(self, question):
messages = [
{"role": "system", "content": f"{question}"},
]
with suppress_stdout_stderr():
output = self.model.create_chat_completion(messages, max_tokens=1050, temperature=0.7)
return output["choices"][0]["message"]["content"]
if __name__ == "__main__":
ag_gpt = AgGPT12Pro()
question = "Hi, who are you? and what's the date/time, also what do you know?"
answer = ag_gpt.AskAgGPT(question)
print(f"Question: {question}\nAnswer: {answer}")