jpfearnworks commited on
Commit
6355201
1 Parent(s): 6814a67

Update docstrings, imports

Browse files
src/main.py CHANGED
@@ -4,7 +4,6 @@ import streamlit as st
4
  from reasoning import ReasoningRouter, default_reasoning_router_config
5
  load_dotenv(find_dotenv())
6
 
7
- openai_api_key = os.getenv("OPENAI_API_KEY")
8
 
9
  def run_app():
10
  """
 
4
  from reasoning import ReasoningRouter, default_reasoning_router_config
5
  load_dotenv(find_dotenv())
6
 
 
7
 
8
  def run_app():
9
  """
src/reasoning/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
- from .react import ReactStrategy
2
- from .tree_of_thought import TreeOfThoughtStrategy
3
- from .chain_of_thought import ChainOfThoughtStrategy
4
  from .reasoning_router import ReasoningRouter, default_reasoning_router_config
5
- from .reasoning_strategy import ReasoningStrategy, ReasoningConfig
 
1
+ from .react import ReactStrategy, default_react_config
2
+ from .tree_of_thought import TreeOfThoughtStrategy, default_tot_config
3
+ from .chain_of_thought import ChainOfThoughtStrategy, default_cot_confg
4
  from .reasoning_router import ReasoningRouter, default_reasoning_router_config
5
+ from .reasoning_strategy import ReasoningStrategy, ReasoningConfig, default_reasoning_config
src/reasoning/chain_of_thought.py CHANGED
@@ -12,10 +12,10 @@ class ChainOfThoughtStrategy(ReasoningStrategy):
12
  self.display("Using 'Chain of Thought'")
13
 
14
  template_cot = """You are asked a question and rather than simply guessing the right answer break down the solution into a series of staps
15
- The question is {question}
16
 
17
- Write out your step by step reasoning and after considering all of the facts and applying this reasoning write out your final answer
18
- """
19
  prompt = PromptTemplate(template=template_cot, input_variables=["question"])
20
  llm_chain = LLMChain(prompt=prompt, llm=self.llm)
21
  response_cot = llm_chain.run(question)
 
12
  self.display("Using 'Chain of Thought'")
13
 
14
  template_cot = """You are asked a question and rather than simply guessing the right answer break down the solution into a series of staps
15
+ The question is {question}
16
 
17
+ Write out your step by step reasoning and after considering all of the facts and applying this reasoning write out your final answer
18
+ """
19
  prompt = PromptTemplate(template=template_cot, input_variables=["question"])
20
  llm_chain = LLMChain(prompt=prompt, llm=self.llm)
21
  response_cot = llm_chain.run(question)
src/reasoning/reasoning_router.py CHANGED
@@ -3,7 +3,7 @@ from .react import ReactStrategy, default_react_config
3
  from .tree_of_thought import TreeOfThoughtStrategy, default_tot_config
4
  from .chain_of_thought import ChainOfThoughtStrategy, default_cot_confg
5
  from .reasoning_strategy import ReasoningConfig
6
- from typing import Tuple, Callable
7
  import re
8
  import os
9
 
@@ -36,17 +36,25 @@ class ReasoningRouter:
36
 
37
  """
38
  self.template = """
39
- Consider the following problem or puzzle: {question}. Based on the characteristics of the problem,
40
- identify the most suitable approach among the three techniques described below. consider each carefully
41
- in the context of the question, write out the likelihood of success of each, and then select the most
42
- appropriate approach:""" + self.usage_block + """
43
- Based on the characteristics of the given problem or puzzle, select the technique that aligns most closely with the nature of the problem. It is important to first provide the number of the technique that best solves the problem, followed by a period. Then you may provide your reason why you have chosen this technique.
44
-
45
- The number of the selected technique is...
46
- """
47
 
 
 
 
48
  @staticmethod
49
- def find_first_integer(text):
 
 
 
 
 
 
 
 
50
  match = re.search(r'\d+', text)
51
  if match:
52
  return int(match.group())
 
3
  from .tree_of_thought import TreeOfThoughtStrategy, default_tot_config
4
  from .chain_of_thought import ChainOfThoughtStrategy, default_cot_confg
5
  from .reasoning_strategy import ReasoningConfig
6
+ from typing import Tuple, Callable, Optional
7
  import re
8
  import os
9
 
 
36
 
37
  """
38
  self.template = """
39
+ Consider the following problem or puzzle: {question}. Based on the characteristics of the problem,
40
+ identify the most suitable approach among the three techniques described below. consider each carefully
41
+ in the context of the question, write out the likelihood of success of each, and then select the most
42
+ appropriate approach:""" + self.usage_block + """
43
+ Based on the characteristics of the given problem or puzzle, select the technique that aligns most closely with the nature of the problem. It is important to first provide the number of the technique that best solves the problem, followed by a period. Then you may provide your reason why you have chosen this technique.
 
 
 
44
 
45
+ The number of the selected technique is...
46
+ """
47
+
48
  @staticmethod
49
+ def find_first_integer(text: str) -> Optional[int]:
50
+ """Finds the first integer in a string.
51
+
52
+ Args:
53
+ text (str): The string to search for an integer.
54
+
55
+ Returns:
56
+ int or None: The first integer found in the string, or None if no integer is found.
57
+ """
58
  match = re.search(r'\d+', text)
59
  if match:
60
  return int(match.group())
src/reasoning/reasoning_strategy.py CHANGED
@@ -9,15 +9,13 @@ import os
9
 
10
  class ReasoningConfig(BaseModel):
11
  """
12
- A class representing a reasoning strategy for answering questions.
13
-
14
- Args:
15
- config (ReasoningConfig): The configuration for the reasoning strategy.
16
- display (Callable): A function for displaying output.
17
 
18
  Attributes:
19
- llm (BaseLLM): The language model used for reasoning.
20
- display (Callable): The function for displaying output.
 
 
21
  """
22
  temperature: float = 0.7
23
  max_tokens: int = 1500
@@ -25,6 +23,7 @@ class ReasoningConfig(BaseModel):
25
  usage: str
26
 
27
  class ReasoningStrategy:
 
28
  def __init__(self, config: ReasoningConfig, display: Callable):
29
  self.llm = config.llm_class(temperature=config.temperature, max_tokens=config.max_tokens) # ign
30
  self.display = display
 
9
 
10
  class ReasoningConfig(BaseModel):
11
  """
12
+ A configuration class for the reasoning strategy.
 
 
 
 
13
 
14
  Attributes:
15
+ temperature (float): The temperature parameter for the language model.
16
+ max_tokens (int): The maximum number of tokens to generate.
17
+ llm_class (Type[BaseLLM]): The language model class to use for reasoning.
18
+ usage (str): String describing when it is appropriate to use this reasoning strategy.
19
  """
20
  temperature: float = 0.7
21
  max_tokens: int = 1500
 
23
  usage: str
24
 
25
  class ReasoningStrategy:
26
+ """Base class for Reasoning Strategies"""
27
  def __init__(self, config: ReasoningConfig, display: Callable):
28
  self.llm = config.llm_class(temperature=config.temperature, max_tokens=config.max_tokens) # ign
29
  self.display = display