Skip to content

Commit

Permalink
Chore/community context clean (#1262)
Browse files Browse the repository at this point in the history
* Update community_context.py to check conversation_history_context's value

For the following code (line 90 - 96), conversation_history_context is concatenated with community_context, but the case where conversation_history_context is empty("") has not been considered. When conversation_history_context is empty (""), concatenation should not be performed, as it would result in community_context or each element in community_context having an extra "\n\n".

Therefore, by introducing a context_prefix to check the state of conversation_history_context, concatenation can be handled appropriately. When conversation_history_context is empty (""), the following code will use "" for concatenation. When conversation_history_context is not empty (""), the functionality will be similar to the previous code.

* Format and semver

* Code cleanup

---------

Co-authored-by: ZeyuTeng96 <[email protected]>
  • Loading branch information
AlonsoGuevara and ZeyuTeng96 authored Oct 9, 2024
1 parent d4a0a59 commit 9fa6b91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .semversioner/next-release/patch-20241009221929632018.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "patch",
"description": "Small cleanup in community context history building"
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,21 @@ def build_context(
context_name=context_name,
random_state=self.random_state,
)
if isinstance(community_context, list):
final_context = [
f"{conversation_history_context}\n\n{context}"
for context in community_context
]
else:
final_context = f"{conversation_history_context}\n\n{community_context}"

# Prepare context_prefix based on whether conversation_history_context exists
context_prefix = (
f"{conversation_history_context}\n\n"
if conversation_history_context
else ""
)

final_context = (
[f"{context_prefix}{context}" for context in community_context]
if isinstance(community_context, list)
else f"{context_prefix}{community_context}"
)

# Update the final context data with the provided community_context_data
final_context_data.update(community_context_data)
return (final_context, final_context_data)

return final_context, final_context_data

0 comments on commit 9fa6b91

Please sign in to comment.