Chore/community context clean (#1262)

* 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 <96521059+ZeyuTeng96@users.noreply.github.com>
This commit is contained in:
Alonso Guevara 2024-10-09 17:01:54 -06:00 committed by GitHub
parent d4a0a590f4
commit 9fa6b91684
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 8 deletions

View File

@ -0,0 +1,4 @@
{
"type": "patch",
"description": "Small cleanup in community context history building"
}

View File

@ -87,13 +87,21 @@ class GlobalCommunityContext(GlobalContextBuilder):
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