ensure ascii default to false (#817)

This commit is contained in:
Preston Rasmussen 2025-08-08 11:20:02 -04:00 committed by GitHub
parent ce9ef3ca79
commit baa6825708
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 22 additions and 22 deletions

View file

@ -123,7 +123,7 @@ class Graphiti:
store_raw_episode_content: bool = True,
graph_driver: GraphDriver | None = None,
max_coroutines: int | None = None,
ensure_ascii: bool = True,
ensure_ascii: bool = False,
):
"""
Initialize a Graphiti instance.
@ -157,7 +157,7 @@ class Graphiti:
The maximum number of concurrent operations allowed. Overrides SEMAPHORE_LIMIT set in the environment.
If not set, the Graphiti default is used.
ensure_ascii : bool, optional
Whether to escape non-ASCII characters in JSON serialization for prompts. Defaults to True.
Whether to escape non-ASCII characters in JSON serialization for prompts. Defaults to False.
Set to False to preserve non-ASCII characters (e.g., Korean, Japanese, Chinese) in their
original form, making them readable in LLM logs and improving model understanding.

View file

@ -27,6 +27,6 @@ class GraphitiClients(BaseModel):
llm_client: LLMClient
embedder: EmbedderClient
cross_encoder: CrossEncoderClient
ensure_ascii: bool = True
ensure_ascii: bool = False
model_config = ConfigDict(arbitrary_types_allowed=True)

View file

@ -67,11 +67,11 @@ def edge(context: dict[str, Any]) -> list[Message]:
Given the following context, determine whether the New Edge represents any of the edges in the list of Existing Edges.
<EXISTING EDGES>
{to_prompt_json(context['related_edges'], ensure_ascii=context.get('ensure_ascii', True), indent=2)}
{to_prompt_json(context['related_edges'], ensure_ascii=context.get('ensure_ascii', False), indent=2)}
</EXISTING EDGES>
<NEW EDGE>
{to_prompt_json(context['extracted_edges'], ensure_ascii=context.get('ensure_ascii', True), indent=2)}
{to_prompt_json(context['extracted_edges'], ensure_ascii=context.get('ensure_ascii', False), indent=2)}
</NEW EDGE>
Task:
@ -98,7 +98,7 @@ def edge_list(context: dict[str, Any]) -> list[Message]:
Given the following context, find all of the duplicates in a list of facts:
Facts:
{to_prompt_json(context['edges'], ensure_ascii=context.get('ensure_ascii', True), indent=2)}
{to_prompt_json(context['edges'], ensure_ascii=context.get('ensure_ascii', False), indent=2)}
Task:
If any facts in Facts is a duplicate of another fact, return a new fact with one of their uuid's.

View file

@ -64,20 +64,20 @@ def node(context: dict[str, Any]) -> list[Message]:
role='user',
content=f"""
<PREVIOUS MESSAGES>
{to_prompt_json([ep for ep in context['previous_episodes']], ensure_ascii=context.get('ensure_ascii', True), indent=2)}
{to_prompt_json([ep for ep in context['previous_episodes']], ensure_ascii=context.get('ensure_ascii', False), indent=2)}
</PREVIOUS MESSAGES>
<CURRENT MESSAGE>
{context['episode_content']}
</CURRENT MESSAGE>
<NEW ENTITY>
{to_prompt_json(context['extracted_node'], ensure_ascii=context.get('ensure_ascii', True), indent=2)}
{to_prompt_json(context['extracted_node'], ensure_ascii=context.get('ensure_ascii', False), indent=2)}
</NEW ENTITY>
<ENTITY TYPE DESCRIPTION>
{to_prompt_json(context['entity_type_description'], ensure_ascii=context.get('ensure_ascii', True), indent=2)}
{to_prompt_json(context['entity_type_description'], ensure_ascii=context.get('ensure_ascii', False), indent=2)}
</ENTITY TYPE DESCRIPTION>
<EXISTING ENTITIES>
{to_prompt_json(context['existing_nodes'], ensure_ascii=context.get('ensure_ascii', True), indent=2)}
{to_prompt_json(context['existing_nodes'], ensure_ascii=context.get('ensure_ascii', False), indent=2)}
</EXISTING ENTITIES>
Given the above EXISTING ENTITIES and their attributes, MESSAGE, and PREVIOUS MESSAGES; Determine if the NEW ENTITY extracted from the conversation

View file

@ -68,7 +68,7 @@ def query_expansion(context: dict[str, Any]) -> list[Message]:
Bob is asking Alice a question, are you able to rephrase the question into a simpler one about Alice in the third person
that maintains the relevant context?
<QUESTION>
{to_prompt_json(context['query'], ensure_ascii=context.get('ensure_ascii', True))}
{to_prompt_json(context['query'], ensure_ascii=context.get('ensure_ascii', False))}
</QUESTION>
"""
return [
@ -84,10 +84,10 @@ def qa_prompt(context: dict[str, Any]) -> list[Message]:
Your task is to briefly answer the question in the way that you think Alice would answer the question.
You are given the following entity summaries and facts to help you determine the answer to your question.
<ENTITY_SUMMARIES>
{to_prompt_json(context['entity_summaries'], ensure_ascii=context.get('ensure_ascii', True))}
{to_prompt_json(context['entity_summaries'], ensure_ascii=context.get('ensure_ascii', False))}
</ENTITY_SUMMARIES>
<FACTS>
{to_prompt_json(context['facts'], ensure_ascii=context.get('ensure_ascii', True))}
{to_prompt_json(context['facts'], ensure_ascii=context.get('ensure_ascii', False))}
</FACTS>
<QUESTION>
{context['query']}

View file

@ -73,7 +73,7 @@ def edge(context: dict[str, Any]) -> list[Message]:
</FACT TYPES>
<PREVIOUS_MESSAGES>
{to_prompt_json([ep for ep in context['previous_episodes']], ensure_ascii=context.get('ensure_ascii', True), indent=2)}
{to_prompt_json([ep for ep in context['previous_episodes']], ensure_ascii=context.get('ensure_ascii', False), indent=2)}
</PREVIOUS_MESSAGES>
<CURRENT_MESSAGE>
@ -132,7 +132,7 @@ def reflexion(context: dict[str, Any]) -> list[Message]:
user_prompt = f"""
<PREVIOUS MESSAGES>
{to_prompt_json([ep for ep in context['previous_episodes']], ensure_ascii=context.get('ensure_ascii', True), indent=2)}
{to_prompt_json([ep for ep in context['previous_episodes']], ensure_ascii=context.get('ensure_ascii', False), indent=2)}
</PREVIOUS MESSAGES>
<CURRENT MESSAGE>
{context['episode_content']}
@ -166,7 +166,7 @@ def extract_attributes(context: dict[str, Any]) -> list[Message]:
content=f"""
<MESSAGE>
{to_prompt_json(context['episode_content'], ensure_ascii=context.get('ensure_ascii', True), indent=2)}
{to_prompt_json(context['episode_content'], ensure_ascii=context.get('ensure_ascii', False), indent=2)}
</MESSAGE>
<REFERENCE TIME>
{context['reference_time']}

View file

@ -25,7 +25,7 @@ def format_edge_date_range(edge: EntityEdge) -> str:
def search_results_to_context_string(
search_results: SearchResults, ensure_ascii: bool = True
search_results: SearchResults, ensure_ascii: bool = False
) -> str:
"""Reformats a set of SearchResults into a single string to pass directly to an LLM as context"""
fact_json = [

View file

@ -48,7 +48,7 @@ async def extract_nodes_reflexion(
episode: EpisodicNode,
previous_episodes: list[EpisodicNode],
node_names: list[str],
ensure_ascii: bool = True,
ensure_ascii: bool = False,
) -> list[str]:
# Prepare context for LLM
context = {
@ -331,7 +331,7 @@ async def extract_attributes_from_node(
episode: EpisodicNode | None = None,
previous_episodes: list[EpisodicNode] | None = None,
entity_type: type[BaseModel] | None = None,
ensure_ascii: bool = True,
ensure_ascii: bool = False,
) -> EntityNode:
node_context: dict[str, Any] = {
'name': node.name,

View file

@ -35,7 +35,7 @@ async def extract_edge_dates(
edge: EntityEdge,
current_episode: EpisodicNode,
previous_episodes: list[EpisodicNode],
ensure_ascii: bool = True,
ensure_ascii: bool = False,
) -> tuple[datetime | None, datetime | None]:
context = {
'edge_fact': edge.fact,
@ -75,7 +75,7 @@ async def get_edge_contradictions(
llm_client: LLMClient,
new_edge: EntityEdge,
existing_edges: list[EntityEdge],
ensure_ascii: bool = True,
ensure_ascii: bool = False,
) -> list[EntityEdge]:
start = time()

View file

@ -1,7 +1,7 @@
[project]
name = "graphiti-core"
description = "A temporal graph building library"
version = "0.18.4"
version = "0.18.5"
authors = [
{ name = "Paul Paliychuk", email = "paul@getzep.com" },
{ name = "Preston Rasmussen", email = "preston@getzep.com" },