mirror of
https://github.com/microsoft/graphrag.git
synced 2026-01-14 09:07:20 +08:00
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:
parent
d4a0a590f4
commit
9fa6b91684
@ -0,0 +1,4 @@
|
||||
{
|
||||
"type": "patch",
|
||||
"description": "Small cleanup in community context history building"
|
||||
}
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user