Merge pull request #64 from lallouslab/fixidxtool

This commit is contained in:
LouisShark 2023-12-19 13:13:34 +08:00 committed by GitHub
commit 0ff994a810
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -65,16 +65,8 @@ class GptMarkdownFile:
Return the GPT identifier. Return the GPT identifier.
:return: GptIdentifier object. :return: GptIdentifier object.
""" """
url = self.fields.get('url') return parse_gpturl(self.fields.get('url'))
if url and url.startswith(GPT_BASE_URL):
id = url[GPT_BASE_URL_L:].split('\n')[0]
i = id.find('-')
if i != -1:
return GptIdentifier(id[:i], id[i+1:].strip())
else:
return GptIdentifier(id, '')
return None
def __str__(self) -> str: def __str__(self) -> str:
sorted_fields = sorted(self.fields.items(), key=lambda x: SUPPORTED_FIELDS[x[0]].order) sorted_fields = sorted(self.fields.items(), key=lambda x: SUPPORTED_FIELDS[x[0]].order)
# Check if the field value contains the start marker of the markdown block and add a blank line before it # Check if the field value contains the start marker of the markdown block and add a blank line before it
@ -129,6 +121,15 @@ class GptMarkdownFile:
except Exception as e: except Exception as e:
return (False, f"Failed to save file '{file_path}': {e}") return (False, f"Failed to save file '{file_path}': {e}")
def parse_gpturl(url: str) -> Union[GptIdentifier, None]:
if url and url.startswith(GPT_BASE_URL):
id = url[GPT_BASE_URL_L:].split('\n')[0]
i = id.find('-')
if i != -1:
return GptIdentifier(id[:i], id[i+1:])
else:
return GptIdentifier(id, '')
def get_prompts_path() -> str: def get_prompts_path() -> str:
"""Return the path to the prompts directory.""" """Return the path to the prompts directory."""