Views
No views yet







| Enteli-49B (EnteliMind) | GPT 3.5 (OpenAI) | LLaMa 70B (Meta AI) | |
|---|---|---|---|
| MMLU | 73.6% | 70% | 69.9% |
| HelloSwag (10-shot) | 90.6% | 85.5% | 87.1% |
| ARC Challenge (25-shot) | 87.9% | 85.2% | 85.1% |
| WinoGrande (5-shot) | 83.2% | 81.6% | 83.2% |
| GSM-8K (5-shot) | 61.1% | 57.1% | 53.6% |
\<s\> [INST] There goes the prompt [/INST] There goes the answer\</s\> [INST] Follow-up prompt [/INST]1#pip install transformers accelerate bitsandbytes
2import torch
3from transformers import AutoTokenizer, AutoModelForCausalLM
4
5model_name = "arhanovich/Enteli-49B"
6auth_token = "There goes the auth token" #Since this a private model, you must use that auth token to access the model and the tokenizer
7
8tokenizer = AutoTokenizer.from_pretrained(model_name, use_default_system_prompt=False, use_auth_token=auth_token)
9model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float32, device_map='auto',local_files_only=False, load_in_4bit=True, use_auth_token=auth_token)
10
11prompt = input("Query: ")
12full_prompt = f"<s>[INST] You are a helpful AI called Enteli trained by the AI company EnteliMind.[/INST]\nUser: {prompt}\nAssistant:"
13input_ids = tokenizer(full_prompt, return_tensors="pt").input_ids.to("cuda")
14generation_output = model.generate(
15input_ids=input_ids, max_new_tokens=500)
16answer = str(tokenizer.decode(generation_output[0], skip_special_tokens=True)).replace(full_prompt, "")
17print(f"Answer: {answer}")1pip install transformers accelerate bitsandbytes duckduckgo_search
2
3import torch
4import transformers
5
6model_name = "arhanovich/Enteli-49B"
7
8auth_token = "There goes the auth token" #Since this a private model, you must use that auth token to access the model and the tokenizer
9
10tokenizer = transformers.AutoTokenizer.from_pretrained(model_name, use_default_system_prompt=False, use_auth_token=auth_token)
11model = transformers.AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float32, device_map='auto',local_files_only=False, load_in_4bit=True, use_auth_token=auth_token)
12
13generate_text = transformers.pipeline(
14 model=model, tokenizer=tokenizer,
15 return_full_text=False,
16 task="text-generation",
17 temperature=0.1, # 'randomness' of outputs, 0.0 is the min and 1.0 the max
18 top_p=0.15, # select from top tokens whose probability add up to 15%
19 top_k=0, # select from top 0 tokens (because zero, relies on top_p)
20 max_new_tokens=512, # max number of tokens to generate in the output
21 repetition_penalty=1.1
22)
23
24
25def instruction_format(sys_message: str, query: str):
26 return f'<s> [INST] {sys_message} [/INST]\nUser: {query}\nAssistant: ```json\n{{\n"tool_name": '
27
28system_message= """You are a helpful AI assistant, you are an agent capable of using a variety of tools to answer a question. Here are a few of the tools available to you:
29
30- Calculator: the calculator should be used whenever you need to perform a calculation, no matter how simple. It uses Python so make sure to write complete Python code required to perform the calculation required and make sure the Python returns your answer to the `output` variable.
31- Search: the search tool should be used whenever you need to find information. It can be used to find information about everything
32- Final Answer: the final answer tool must be used to respond to the user. You must use this when you have decided on an answer.
33
34TOOL USAGE
35
36Let's get started. The users query is as follows.
37"""
38
39import json
40
41def format_output(text: str):
42 full_json_str = '{\n"tool_name": '+text
43 full_json_str = full_json_str.strip()
44 if full_json_str.endswith("```"):
45 full_json_str = full_json_str[:-3]
46 return json.loads(full_json_str)
47
48from duckduckgo_search import DDGS
49
50def use_tool(action: dict):
51 tool_name = action["tool_name"]
52 if tool_name == "Final Answer":
53 return "Assistant: "+action["input"]
54 elif tool_name == "Calculator":
55 exec(action["input"])
56 return f"Tool Output: {output}"
57 elif tool_name == "Search":
58 contexts = []
59 with DDGS() as ddgs:
60 results = ddgs.text(
61 action["input"],
62 region="wt-wt", safesearch="on",
63 max_results=3
64 )
65 for r in results:
66 contexts.append(r['body'])
67 info = "\n---\n".join(contexts)
68 return f"Tool Output: {info}"
69 else:
70 # otherwise just assume final answer
71 return "Assistant: "+action["input"]
72
73
74def run_agent(query: str):
75 res = generate_text(query)
76 action_dict = format_output(res[0]["generated_text"])
77 response = use_tool(action_dict)
78 full_text = f"{query}{res[0]['generated_text']}\n{response}"
79 return response, full_text
80
81
82query = input(">: ")
83
84input_prompt = instruction_format(system_message, query)
85
86out = run_agent(input_prompt)
87print(out)
88
89second_step = out[1]+"""
90Assistant: ```json
91{
92 "tool_name": """
93
94out = run_agent(second_step)
95
96print(out[0])To use these tools you must always respond in JSON format containing `"tool_name"` and `"input"` key-value pairs. For example, to answer the question, "what is the square root of 51?" you must use the calculator tool like so:
```json
{
"tool_name": "Calculator",
"input": "from math import sqrt; output = sqrt(51)"
}
```
Or to answer the question "who is the current president of the USA?" you must respond:
```json
{
"tool_name": "Search",
"input": "current president of USA"
}
```
Remember, even when answering to the user, you must still use this JSON format! If you'd like to ask how the user is doing you must write:
```json
{
"tool_name": "Final Answer",
"input": "How are you today?"
}
```1#pip install transformers accelerate bitsandbytes
2import torch
3import transformers
4auth_token = "There goes the auth token" #Since this a private model, you must use that auth token to access the model and the tokenizer
5model_name = "arhanovich/Enteli-49B"
6
7tokenizer = transformers.AutoTokenizer.from_pretrained(model_name, use_default_system_prompt=False, use_auth_token=auth_token)
8model = transformers.AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float32, device_map='auto',local_files_only=False, load_in_4bit=True, use_auth_token=auth_token)
9
10
11def generate_text(query):
12 system_message = """
13 <s>[INST]You are a helpful AI assistant, you are an agent capable of using a variety of tools to answer a question. Here are a few of the tools available to you:
14
15 - Compund Interest: Calculate the future value of an investment with compound interest. :param principal: Initial amount of money invested (principal) :param rate: Annual interest rate (as a decimal) :param periods: Number of periods the money is invested for :return: Future value of the investment.
16 - Present Value Annuity: Calculate the present value of an annuity :param payment: The fixed payment amount per period :param rate: Discount rate per period (as a decimal).:param periods: Total number of periods :return: Present value of the annuity.
17 - Capital Asset Pricing: Calculate the expected return of an asset using the Capital Asset Pricing Model (CAPM) :param expected_market_return: Expected return of the market :param risk_free_rate: Risk-free rate of return :param beta: Beta of the asset :return: Expected return of the asset.
18 - Final Answer: the final answer tool must be used to respond to the user. You must use this when you have decided on an answer. :param answer:Your final answer
19
20 To use these tools you must always respond in JSON format containing `"tool_name"` and `"parameters"` key-value pairs.
21
22 For example, to answer the question, "Suppose you invest $5,000 in a savings account offering an annual interest rate of 4%. How much money will be in the account after 10 years if the interest is compounded annually?" you must use the tool like so:
23
24 ```json
25 {
26 "tool_name": "Compund Interest",
27 "input": "principal=5000, rate=0.04, periods=10"
28 }
29 ```
30
31 Or to answer the question "You are considering an investment that will pay you $1,000 per year for the next 5 years. If your discount rate is 3%, what is the present value of these future payments?" you must respond:
32
33 ```json
34 {
35 "tool_name": "Present Value Annuity",
36 "input": "payment=1000, rate=0.03, periods=5"
37 }
38 ```
39
40 To answer the question "An asset has a beta of 1.2. The risk-free rate is 2%, and the expected market return is 8%. What is the expected return on this asset according to the CAPM?" use the tool like that
41 ```json
42 {
43 "tool_name": "Capital Asset Pricing",
44 "input": "expected_market_return=0.08, risk_free_rate=0.02, beta=1.2"
45 }
46 ```
47
48 Remember, even when answering to the user, you must still use this JSON format! Example, if the Present Value of the Annuity tool gave an ouput like that: 4987.76
49
50 ```json
51 {
52 "tool_name": "Final Answer",
53 "input": "answer: The Present Value of the Annuity is 4987.76"
54 }
55 ```
56
57 Let's get started. The users query is as follows. You must always give your answer in JSON fomat!!!
58 User: """
59
60 full_prompt = system_message + query + "[/INST]"
61
62 input_ids = tokenizer(full_prompt, return_tensors="pt").input_ids.to("cuda")
63
64 generation_output = model.generate(input_ids=input_ids, max_new_tokens=1024, temperature=0.6, top_p=0.9, top_k=50)
65 answer = str(tokenizer.decode(generation_output[0], skip_special_tokens=True))
66 answer = answer.split("[/INST]")[-1].strip()
67 return answer
68
69import json
70import re
71def format_output(text: str):
72 # Find the JSON part in the text
73 start = text.find("{")
74 end = text.rfind("}") + 1
75 if start == -1 or end == -1:
76 raise ValueError("JSON string not found in the text")
77
78 # Extract the JSON string
79 json_str = text[start:end]
80
81 # Parse the JSON string
82 try:
83 json_obj = json.loads(json_str)
84 except json.JSONDecodeError:
85 match = re.search(r'"answer":\s*"([^"]+)"', text)
86 if match:
87 return match.group(1)
88 else:
89 raise ValueError("Answer not found")
90
91
92
93 # Ensure the necessary keys are present
94 if "tool_name" not in json_obj or "input" not in json_obj:
95 raise ValueError("Required keys ('tool_name', 'input') are missing in the JSON")
96
97 # Extract and parse the parameters
98 try:
99 parameters_str = json_obj["input"]
100 params = dict(param.split("=") for param in parameters_str.split(", "))
101
102 # Convert parameter values to appropriate type (int, float, or leave as string)
103 def convert_value(v):
104 try:
105 return float(v) if '.' in v else int(v)
106 except ValueError:
107 return v # If conversion to int or float fails, return the string as is
108
109 params = {k: convert_value(v) for k, v in params.items()}
110 except Exception as e:
111 raise ValueError(f"Error parsing parameters: {e}")
112
113 return json_obj["tool_name"], params
114
115
116def compound_interest(principal, rate, periods):
117 """
118 Calculate the future value of an investment with compound interest.
119 :param principal: Initial amount of money invested (principal).
120 :param rate: Annual interest rate (as a decimal).
121 :param periods: Number of periods the money is invested for.
122 :return: Future value of the investment.
123 """
124 return principal * (1 + rate) ** periods
125
126def present_value_annuity(payment, rate, periods):
127 """
128 Calculate the present value of an annuity.
129 :param payment: The fixed payment amount per period.
130 :param rate: Discount rate per period (as a decimal).
131 :param periods: Total number of periods.
132 :return: Present value of the annuity.
133 """
134 return payment * ((1 - (1 + rate) ** -periods) / rate)
135
136def capm(expected_market_return, risk_free_rate, beta):
137 """
138 Calculate the expected return of an asset using the Capital Asset Pricing Model (CAPM).
139 :param expected_market_return: Expected return of the market.
140 :param risk_free_rate: Risk-free rate of return.
141 :param beta: Beta of the asset.
142 :return: Expected return of the asset.
143 """
144 return risk_free_rate + beta * (expected_market_return - risk_free_rate)
145
146
147def final_answer(answer):
148 return answer
149
150
151
152def use_tool(tool_name, params):
153 if tool_name == "Final Answer":
154 result = final_answer(**params)
155 return "Assistant:" + result
156
157 elif tool_name == "Capital Asset Pricing":
158 result = capm(**params)
159 return "Tool Output:" + str(result)
160
161 elif tool_name == "Present Value Annuity":
162 result = present_value_annuity(**params)
163 return "Tool Output:" + str(result)
164 elif tool_name == "Compound Interest":
165 result = compound_interest(**params)
166 return "Tool Output:" + str(result)
167
168 else:
169 return "Assistant: An error occured"
170
171
172def run_agent(query: str):
173 res = generate_text(query)
174 print(res)
175 tool_name, params = format_output(res)
176 response = use_tool(tool_name, params)
177 full_text = f"{query}{res}\n{response}"
178 return response, full_text
179
180
181query= input(">: ")
182out = run_agent(query)
183print(f"Result: {out[0]}")
184
185#You can run the second outputs and get the final results using the same logic as in the previous example