Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Append encoding='utf-8' to open #1423

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading