WilliamGazeley commited on
Commit
b401ec2
1 Parent(s): d8a7106

Fix recursion bug

Browse files
src/config.py CHANGED
@@ -15,6 +15,6 @@ class Config(BaseSettings):
15
  chat_template: str = Field("chatml", description="Chat template for prompt formatting")
16
  num_fewshot: int | None = Field(None, description="Option to use json mode examples")
17
  load_in_4bit: str = Field("False", description="Option to load in 4bit with bitsandbytes")
18
- max_depth: int = Field(5, description="Maximum number of recursive iteration")
19
 
20
  config = Config(_env_file=".env")
 
15
  chat_template: str = Field("chatml", description="Chat template for prompt formatting")
16
  num_fewshot: int | None = Field(None, description="Option to use json mode examples")
17
  load_in_4bit: str = Field("False", description="Option to load in 4bit with bitsandbytes")
18
+ max_depth: int = Field(3, description="Maximum number of recursive iteration")
19
 
20
  config = Config(_env_file=".env")
src/functioncall.py CHANGED
@@ -92,7 +92,7 @@ class ModelInference:
92
  inputs.to(self.model.device),
93
  max_new_tokens=1500,
94
  temperature=0.8,
95
- repetition_penalty=1.1,
96
  do_sample=True,
97
  eos_token_id=self.tokenizer.eos_token_id
98
  )
@@ -135,7 +135,8 @@ class ModelInference:
135
  depth += 1
136
  if depth >= max_depth:
137
  print(f"Maximum recursion depth reached ({max_depth}). Stopping recursion.")
138
- return
 
139
 
140
  completion = self.run_inference(prompt)
141
  return recursive_loop(prompt, completion, depth)
@@ -147,7 +148,7 @@ class ModelInference:
147
  depth += 1
148
  if depth >= max_depth:
149
  print(f"Maximum recursion depth reached ({max_depth}). Stopping recursion.")
150
- return
151
 
152
  completion = self.run_inference(prompt)
153
  return recursive_loop(prompt, completion, depth)
 
92
  inputs.to(self.model.device),
93
  max_new_tokens=1500,
94
  temperature=0.8,
95
+ repetition_penalty=1.2,
96
  do_sample=True,
97
  eos_token_id=self.tokenizer.eos_token_id
98
  )
 
135
  depth += 1
136
  if depth >= max_depth:
137
  print(f"Maximum recursion depth reached ({max_depth}). Stopping recursion.")
138
+ completion = self.run_inference(prompt)
139
+ return completion
140
 
141
  completion = self.run_inference(prompt)
142
  return recursive_loop(prompt, completion, depth)
 
148
  depth += 1
149
  if depth >= max_depth:
150
  print(f"Maximum recursion depth reached ({max_depth}). Stopping recursion.")
151
+ return completion
152
 
153
  completion = self.run_inference(prompt)
154
  return recursive_loop(prompt, completion, depth)
src/functions.py CHANGED
@@ -20,7 +20,7 @@ az_creds = AzureKeyCredential(config.az_search_api_key)
20
  az_search_client = SearchClient(config.az_search_endpoint, config.az_search_idx_name, az_creds)
21
 
22
  @tool
23
- def get_company_analysis(query: str) -> dict:
24
  """
25
  Searches through your database of company and crypto analysis, retrieves top 2
26
  pieces of analysis relevant to your query. You MUST ALWAYS use this function
@@ -280,7 +280,7 @@ def get_company_profile(symbol: str) -> dict:
280
 
281
  def get_openai_tools() -> List[dict]:
282
  functions = [
283
- get_company_analysis,
284
  google_search_and_scrape,
285
  get_current_stock_price,
286
  get_company_news,
 
20
  az_search_client = SearchClient(config.az_search_endpoint, config.az_search_idx_name, az_creds)
21
 
22
  @tool
23
+ def get_analysis(query: str) -> dict:
24
  """
25
  Searches through your database of company and crypto analysis, retrieves top 2
26
  pieces of analysis relevant to your query. You MUST ALWAYS use this function
 
280
 
281
  def get_openai_tools() -> List[dict]:
282
  functions = [
283
+ get_analysis,
284
  google_search_and_scrape,
285
  get_current_stock_price,
286
  get_company_news,
src/prompt_assets/output_sys_prompt.yml CHANGED
@@ -5,7 +5,10 @@ Role: |
5
  Objective: |
6
  Answer questions accurately and truthfully given your current knowledge. Answer the question directly.
7
  Your purpose is to give financial advice and indepth analysis.
 
8
  Instructions: |
9
  The questions will be asked by top technology executives and CFO of large fintech companies and successful startups.
10
  Answer in a friendly and engaging manner representing a top female investment professional working at a leading investment bank.
11
  Give a direct answer to question, concise yet insightful.
 
 
 
5
  Objective: |
6
  Answer questions accurately and truthfully given your current knowledge. Answer the question directly.
7
  Your purpose is to give financial advice and indepth analysis.
8
+ Use points and datafrom the assistant message to form your answers.
9
  Instructions: |
10
  The questions will be asked by top technology executives and CFO of large fintech companies and successful startups.
11
  Answer in a friendly and engaging manner representing a top female investment professional working at a leading investment bank.
12
  Give a direct answer to question, concise yet insightful.
13
+ Do not tell the user to do work, e.g. do not ask them to keep up with news or watch the market
14
+ Do not tell the user to consult a financial advisor, because you already are the best financial advisor
src/prompt_assets/sys_prompt.yml CHANGED
@@ -4,6 +4,7 @@ Role: |
4
  You are provided with function signatures within <tools></tools> XML tags.
5
  The current date is: {date}.
6
  Objective: |
 
7
  You may use agentic frameworks for reasoning and planning to help with user query.
8
  Please call a function and wait for function results to be provided to you in the next iteration.
9
  Don't make assumptions about what values to plug into function arguments.
@@ -28,6 +29,7 @@ Schema: |
28
  {schema}
29
  Instructions: |
30
  If the user asks for an opinion, you must use functions to form your opinion
 
31
  At the very first turn you don't have <tool_results> so you shouldn't not make up the results.
32
  Please keep a running summary with analysis of previous function results and summaries from previous iterations.
33
  Do not stop calling functions until the task has been accomplished or you've reached max iteration of 10.
 
4
  You are provided with function signatures within <tools></tools> XML tags.
5
  The current date is: {date}.
6
  Objective: |
7
+ Your purpose is to give financial advice and analysis
8
  You may use agentic frameworks for reasoning and planning to help with user query.
9
  Please call a function and wait for function results to be provided to you in the next iteration.
10
  Don't make assumptions about what values to plug into function arguments.
 
29
  {schema}
30
  Instructions: |
31
  If the user asks for an opinion, you must use functions to form your opinion
32
+ You should almost always lean on information you have from get_analysis
33
  At the very first turn you don't have <tool_results> so you shouldn't not make up the results.
34
  Please keep a running summary with analysis of previous function results and summaries from previous iterations.
35
  Do not stop calling functions until the task has been accomplished or you've reached max iteration of 10.