format
This commit is contained in:
parent
5ab8eee576
commit
c8d2f147ea
4 changed files with 7 additions and 19 deletions
|
|
@ -552,9 +552,7 @@ class Graphiti:
|
||||||
if update_communities:
|
if update_communities:
|
||||||
communities, community_edges = await semaphore_gather(
|
communities, community_edges = await semaphore_gather(
|
||||||
*[
|
*[
|
||||||
update_community(
|
update_community(self.driver, self.llm_client, self.embedder, node)
|
||||||
self.driver, self.llm_client, self.embedder, node
|
|
||||||
)
|
|
||||||
for node in nodes
|
for node in nodes
|
||||||
],
|
],
|
||||||
max_coroutines=self.max_coroutines,
|
max_coroutines=self.max_coroutines,
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,7 @@ def format_edge_date_range(edge: EntityEdge) -> str:
|
||||||
return f'{edge.valid_at if edge.valid_at else "date unknown"} - {(edge.invalid_at if edge.invalid_at else "present")}'
|
return f'{edge.valid_at if edge.valid_at else "date unknown"} - {(edge.invalid_at if edge.invalid_at else "present")}'
|
||||||
|
|
||||||
|
|
||||||
def search_results_to_context_string(
|
def search_results_to_context_string(search_results: SearchResults) -> str:
|
||||||
search_results: SearchResults
|
|
||||||
) -> str:
|
|
||||||
"""Reformats a set of SearchResults into a single string to pass directly to an LLM as context"""
|
"""Reformats a set of SearchResults into a single string to pass directly to an LLM as context"""
|
||||||
fact_json = [
|
fact_json = [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -131,9 +131,7 @@ def label_propagation(projection: dict[str, list[Neighbor]]) -> list[list[str]]:
|
||||||
return clusters
|
return clusters
|
||||||
|
|
||||||
|
|
||||||
async def summarize_pair(
|
async def summarize_pair(llm_client: LLMClient, summary_pair: tuple[str, str]) -> str:
|
||||||
llm_client: LLMClient, summary_pair: tuple[str, str]
|
|
||||||
) -> str:
|
|
||||||
# Prepare context for LLM
|
# Prepare context for LLM
|
||||||
context = {
|
context = {
|
||||||
'node_summaries': [{'summary': summary} for summary in summary_pair],
|
'node_summaries': [{'summary': summary} for summary in summary_pair],
|
||||||
|
|
@ -148,9 +146,7 @@ async def summarize_pair(
|
||||||
return pair_summary
|
return pair_summary
|
||||||
|
|
||||||
|
|
||||||
async def generate_summary_description(
|
async def generate_summary_description(llm_client: LLMClient, summary: str) -> str:
|
||||||
llm_client: LLMClient, summary: str
|
|
||||||
) -> str:
|
|
||||||
context = {
|
context = {
|
||||||
'summary': summary,
|
'summary': summary,
|
||||||
}
|
}
|
||||||
|
|
@ -178,9 +174,7 @@ async def build_community(
|
||||||
new_summaries: list[str] = list(
|
new_summaries: list[str] = list(
|
||||||
await semaphore_gather(
|
await semaphore_gather(
|
||||||
*[
|
*[
|
||||||
summarize_pair(
|
summarize_pair(llm_client, (str(left_summary), str(right_summary)))
|
||||||
llm_client, (str(left_summary), str(right_summary))
|
|
||||||
)
|
|
||||||
for left_summary, right_summary in zip(
|
for left_summary, right_summary in zip(
|
||||||
summaries[: int(length / 2)], summaries[int(length / 2) :], strict=False
|
summaries[: int(length / 2)], summaries[int(length / 2) :], strict=False
|
||||||
)
|
)
|
||||||
|
|
@ -315,9 +309,7 @@ async def update_community(
|
||||||
if community is None:
|
if community is None:
|
||||||
return [], []
|
return [], []
|
||||||
|
|
||||||
new_summary = await summarize_pair(
|
new_summary = await summarize_pair(llm_client, (entity.summary, community.summary))
|
||||||
llm_client, (entity.summary, community.summary)
|
|
||||||
)
|
|
||||||
new_name = await generate_summary_description(llm_client, new_summary)
|
new_name = await generate_summary_description(llm_client, new_summary)
|
||||||
|
|
||||||
community.summary = new_summary
|
community.summary = new_summary
|
||||||
|
|
|
||||||
|
|
@ -542,7 +542,7 @@ async def resolve_extracted_edge(
|
||||||
'episode_content': episode.content,
|
'episode_content': episode.content,
|
||||||
'reference_time': episode.valid_at,
|
'reference_time': episode.valid_at,
|
||||||
'fact': resolved_edge.fact,
|
'fact': resolved_edge.fact,
|
||||||
}
|
}
|
||||||
|
|
||||||
edge_model = edge_type_candidates.get(fact_type) if edge_type_candidates else None
|
edge_model = edge_type_candidates.get(fact_type) if edge_type_candidates else None
|
||||||
if edge_model is not None and len(edge_model.model_fields) != 0:
|
if edge_model is not None and len(edge_model.model_fields) != 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue