Skip to content

Commit

Permalink
Append encoding='utf-8' to open
Browse files Browse the repository at this point in the history
  • Loading branch information
bear0330 committed May 27, 2024
1 parent ec894cd commit b7d7655
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion memgpt/cli/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ def add(
ms = MetadataStore(config)
if filename: # read from file
assert text is None, "Cannot specify both text and filename"
with open(filename, "r") as f:
with open(filename, "r", encoding='utf-8') as f:
text = f.read()
if option == "persona":
persona = ms.get_persona(name=name, user_id=user_id)
Expand Down
2 changes: 1 addition & 1 deletion memgpt/client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _reset_server(self):
# tools (currently only available for admin)
def create_tool(self, name: str, file_path: str, source_type: Optional[str] = "python", tags: Optional[List[str]] = None) -> ToolModel:
"""Add a tool implemented in a file path"""
source_code = open(file_path, "r").read()
source_code = open(file_path, "r", encoding='utf-8').read()
data = {"name": name, "source_code": source_code, "source_type": source_type, "tags": tags}
response = requests.post(f"{self.base_url}/api/tools", json=data, headers=self.headers)
if response.status_code != 200:
Expand Down
2 changes: 1 addition & 1 deletion memgpt/functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def write_function(module_name: str, function_name: str, function_code: str):

# Write the function to a file
file_path = os.path.join(USER_FUNCTIONS_DIR, f"{module_name}.py")
with open(file_path, "w") as f:
with open(file_path, "w", encoding='utf-8') as f:
f.write(function_code)
succ, error = validate_function(module_name, file_path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def save_to_yaml(self, file_path: str):
"default_stop_sequences": self.default_stop_sequences,
}

with open(file_path, "w") as yaml_file:
with open(file_path, "w", encoding='utf-8') as yaml_file:
yaml.dump(data, yaml_file, default_flow_style=False)

@staticmethod
Expand All @@ -357,7 +357,7 @@ def load_from_yaml(file_path: str):
Args:
file_path (str): The path to the YAML file.
"""
with open(file_path, "r") as yaml_file:
with open(file_path, "r", encoding='utf-8') as yaml_file:
data = yaml.safe_load(yaml_file)

wrapper = ConfigurableJSONWrapper()
Expand Down
4 changes: 2 additions & 2 deletions memgpt/presets/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ def add_default_tools(user_id: uuid.UUID, ms: MetadataStore):

def add_default_humans_and_personas(user_id: uuid.UUID, ms: MetadataStore):
for persona_file in list_persona_files():
text = open(persona_file, "r").read()
text = open(persona_file, "r", encoding='utf-8').read()
name = os.path.basename(persona_file).replace(".txt", "")
if ms.get_persona(user_id=user_id, name=name) is not None:
printd(f"Persona '{name}' already exists for user '{user_id}'")
continue
persona = PersonaModel(name=name, text=text, user_id=user_id)
ms.add_persona(persona)
for human_file in list_human_files():
text = open(human_file, "r").read()
text = open(human_file, "r", encoding='utf-8').read()
name = os.path.basename(human_file).replace(".txt", "")
if ms.get_human(user_id=user_id, name=name) is not None:
printd(f"Human '{name}' already exists for user '{user_id}'")
Expand Down
4 changes: 2 additions & 2 deletions memgpt/server/rest_api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def on_startup():
memgpt_api = app.openapi_schema.copy()
memgpt_api["paths"] = {key: value for key, value in memgpt_api["paths"].items() if not key.startswith(OPENAI_API_PREFIX)}
memgpt_api["info"]["title"] = "MemGPT API"
with open("openapi_memgpt.json", "w") as file:
with open("openapi_memgpt.json", "w", encoding='utf-8') as file:
print(f"Writing out openapi_memgpt.json file")
json.dump(memgpt_api, file, indent=2)

Expand All @@ -132,7 +132,7 @@ def on_startup():
if not (key.startswith(API_PREFIX) or key.startswith(ADMIN_PREFIX))
}
openai_assistants_api["info"]["title"] = "OpenAI Assistants API"
with open("openapi_assistants.json", "w") as file:
with open("openapi_assistants.json", "w", encoding='utf-8') as file:
print(f"Writing out openapi_assistants.json file")
json.dump(openai_assistants_api, file, indent=2)

Expand Down
6 changes: 3 additions & 3 deletions memgpt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ def get_human_text(name: str, enforce_limit=True):
for file_path in list_human_files():
file = os.path.basename(file_path)
if f"{name}.txt" == file or name == file:
human_text = open(file_path, "r").read().strip()
human_text = open(file_path, "r", encoding='utf-8').read().strip()
if enforce_limit and len(human_text) > CORE_MEMORY_HUMAN_CHAR_LIMIT:
raise ValueError(f"Contents of {name}.txt is over the character limit ({len(human_text)} > {CORE_MEMORY_HUMAN_CHAR_LIMIT})")
return human_text
Expand All @@ -990,7 +990,7 @@ def get_persona_text(name: str, enforce_limit=True):
for file_path in list_persona_files():
file = os.path.basename(file_path)
if f"{name}.txt" == file or name == file:
persona_text = open(file_path, "r").read().strip()
persona_text = open(file_path, "r", encoding='utf-8').read().strip()
if enforce_limit and len(persona_text) > CORE_MEMORY_PERSONA_CHAR_LIMIT:
raise ValueError(
f"Contents of {name}.txt is over the character limit ({len(persona_text)} > {CORE_MEMORY_PERSONA_CHAR_LIMIT})"
Expand All @@ -1004,7 +1004,7 @@ def get_human_text(name: str):
for file_path in list_human_files():
file = os.path.basename(file_path)
if f"{name}.txt" == file or name == file:
return open(file_path, "r").read().strip()
return open(file_path, "r", encoding='utf-8').read().strip()


def get_schema_diff(schema_a, schema_b):
Expand Down

0 comments on commit b7d7655

Please sign in to comment.