🔨 refactor(embeddings.py): move openai fields formatting to a separate method
✅ test(embeddings_template.py): add tests for openai fields formatting
The openai fields formatting is now done in a separate method, which improves the readability and maintainability of the code. Tests were added to ensure that the formatting is done correctly.
This commit is contained in:
parent
fa9a3a210b
commit
023df99ecc
2 changed files with 76 additions and 4 deletions
|
|
@ -22,6 +22,22 @@ class EmbeddingFrontendNode(FrontendNode):
|
|||
field.display_name = "Jina API URL"
|
||||
field.password = False
|
||||
|
||||
@staticmethod
|
||||
def format_openai_fields(field: TemplateField):
|
||||
if "openai" in field.name:
|
||||
field.show = True
|
||||
field.advanced = True
|
||||
split_name = field.name.split("_")
|
||||
title_name = " ".join([s.capitalize() for s in split_name])
|
||||
field.display_name = title_name.replace("Openai", "OpenAI").replace(
|
||||
"Api", "API"
|
||||
)
|
||||
|
||||
if "api_key" in field.name:
|
||||
field.password = True
|
||||
field.show = True
|
||||
field.advanced = False
|
||||
|
||||
@staticmethod
|
||||
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
|
||||
FrontendNode.format_field(field, name)
|
||||
|
|
@ -30,9 +46,6 @@ class EmbeddingFrontendNode(FrontendNode):
|
|||
if field.name == "headers":
|
||||
field.show = False
|
||||
|
||||
if "openai" in field.name:
|
||||
field.show = True
|
||||
field.advanced = "api_key" not in field.name
|
||||
|
||||
# Format Jina fields
|
||||
EmbeddingFrontendNode.format_jina_fields(field)
|
||||
EmbeddingFrontendNode.format_openai_fields(field)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue