Skip to content

Commit

Permalink
feat: eli5 module
Browse files Browse the repository at this point in the history
  • Loading branch information
av committed Sep 25, 2024
1 parent 7a575c5 commit 32c1579
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
17 changes: 17 additions & 0 deletions boost/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,20 @@ def _convert_value(self, value: str) -> T:
default='1.414',
description='The exploration constant for the MCTS algorithm'
)

# ----------------- ELI5 -----------------

ELI5_STRAT = Config[str](
name='HARBOR_ELI5_STRAT',
type=str,
default='match',
description='The strategy that selects messages to target for the eli5 module'
)

ELI5_STRAT_PARAMS = Config[ConfigDict](
name='HARBOR_ELI5_STRAT_PARAMS',
type=ConfigDict,
# Default - last user message
default='role=user,index=-1',
description='Parameters for eli5 message selection'
)
66 changes: 66 additions & 0 deletions boost/src/modules/eli5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import llm
import log
import chat as ch
import config
import selection

ID_PREFIX = "eli5"
logger = log.setup_logger(ID_PREFIX)

eli5_prompt = """
My friend asked me this question: "{question}".
Explain it to me like I'm stupid. Explain every word and its specific impact on the question.
Do not asnwer the question, though, I want to figure it out myself.
I just need a simpler explanation thats easy to understand and follow.
""".strip()

answer_prompt = """
<instruction>
Given the initial question and its dedetailed explanation, provide the answer to the question.
</instruction>
<question>
{question}
</question>
<explanation>
{explanation}
</explanation>
""".strip()


async def apply(chat: 'ch.Chat', llm: 'llm.LLM'):
strat = config.ELI5_STRAT.value
strat_params = config.ELI5_STRAT_PARAMS.value
debug_info = {
"strat": strat,
"strat_params": strat_params,
}
logger.debug(f"{ID_PREFIX}: {debug_info}")

nodes = selection.apply_strategy(chat, strategy=strat, params=strat_params)

if (len(nodes) > 1):
logger.warning(
f"{ID_PREFIX}: Matched multiple nodes, only the first one will be processed."
)

if len(nodes) == 0:
log.info(f"{ID_PREFIX}: No nodes matched, skipping.")
return await llm.stream_final_completion()

node = nodes[0]
question = node.content

await llm.emit_status("Explaining the question to myself...")
explanation = await llm.stream_chat_completion(
prompt=eli5_prompt.format(question=question),
)

await llm.emit_status('ELI5 Response')
await llm.stream_final_completion(
prompt=answer_prompt.format(
question=question,
explanation=explanation,
)
)
2 changes: 1 addition & 1 deletion profiles/default.env
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ HARBOR_KTRANSFORMERS_EXTRA_ARGS=""
HARBOR_BOOST_HOST_PORT=34131
HARBOR_BOOST_OPENAI_URLS=""
HARBOR_BOOST_OPENAI_KEYS=""
HARBOR_BOOST_MODULES="klmbr;rcn;g1;mcts"
HARBOR_BOOST_MODULES="klmbr;rcn;g1;mcts;eli5"
HARBOR_BOOST_MODULE_FOLDERS="modules;custom_modules"
HARBOR_BOOST_INTERMEDIATE_OUTPUT=true
HARBOR_BOOST_STATUS_STYLE="md:codeblock"
Expand Down

0 comments on commit 32c1579

Please sign in to comment.