format code

This commit is contained in:
seehi 2024-07-15 16:00:05 +08:00
parent 482d78f6e0
commit b20316d6cd
5 changed files with 9 additions and 1 deletions

View file

@ -24,6 +24,7 @@ class ActionNodeContextBuilder(BaseContextBuilder):
If there are no experiences, returns the original `req`;
otherwise returns context with `req` and formatted experiences.
"""
exps = self.format_exps()
return ACTION_NODE_CONTEXT_TEMPLATE.format(req=req, exps=exps) if exps else req

View file

@ -16,6 +16,7 @@ class RoleZeroContextBuilder(BaseContextBuilder):
2. Returns the original `req` if it is empty, incorrectly formatted or there are no experiences.
3. Creates a copy of req and replaces the example content in the copied req with actual experiences.
"""
if not req or len(req) < 2:
return req

View file

@ -39,7 +39,7 @@ class ExperienceManager(BaseModel):
similarity_top_k=DEFAULT_SIMILARITY_TOP_K,
)
]
ranker_configs = [LLMRankerConfig()]
ranker_configs = [LLMRankerConfig(top_n=DEFAULT_SIMILARITY_TOP_K)]
self.storage = SimpleEngine.from_objs(retriever_configs=retriever_configs, ranker_configs=ranker_configs)
@ -57,6 +57,7 @@ class ExperienceManager(BaseModel):
Args:
exp (Experience): The experience to add.
"""
if not self.config.exp_pool.enable_write:
return
@ -74,6 +75,7 @@ class ExperienceManager(BaseModel):
Returns:
list[Experience]: A list of experiences that match the args.
"""
if not self.config.exp_pool.enable_read:
return []
@ -90,6 +92,8 @@ class ExperienceManager(BaseModel):
return exps
def get_exps_count(self) -> int:
"""Get the total number of experiences."""
return self.vector_store._collection.count()

View file

@ -57,6 +57,7 @@ class SimpleScorer(BaseScorer):
Returns:
Score: An object containing the score (1-10) and the reasoning.
"""
prompt = SIMPLE_SCORER_TEMPLATE.format(req=req, resp=resp)
resp = await self.llm.aask(prompt)
resp_json = json.loads(CodeParser.parse_code(resp, lang="json"))

View file

@ -24,6 +24,7 @@ class RoleZeroSerializer(SimpleSerializer):
Returns:
str: The serialized request as a JSON string.
"""
if not req:
return ""