-
Notifications
You must be signed in to change notification settings - Fork 0
feat(config): enhance configs with descriptions for fields #15
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,22 +46,48 @@ def validate_template(template: str): | |
|
|
||
|
|
||
| class QDrantConfig(BaseSettings): | ||
| host: str = Field("test", validation_alias="QDRANT_HOST") | ||
| port: int = Field(6333, gt=0, validation_alias="QDRANT_PORT") | ||
| collection: str = Field("news", validation_alias="QDRANT_COLLECTION") | ||
| host: str = Field( | ||
| "test", | ||
| validation_alias="QDRANT_HOST", | ||
| description="Qdrant vector database host address. Default is 'test'.", | ||
| ) | ||
| port: int = Field( | ||
| 6333, | ||
| gt=0, | ||
| validation_alias="QDRANT_PORT", | ||
| description="Qdrant vector database port. Default is 6333.", | ||
| ) | ||
| collection: str = Field( | ||
| "news", | ||
| validation_alias="QDRANT_COLLECTION", | ||
| description="Qdrant vector database collection name. Default is 'news'.", | ||
| ) | ||
|
|
||
|
|
||
| class RetrieveConfig(BaseModel): | ||
| vector_database: QDrantConfig = QDrantConfig() # type: ignore | ||
| embedding_model: str = Field( | ||
| DEFAULT_EMBEDDING_MODEL, | ||
| description="Name of embedding model." | ||
| "All available models can be found [here](https://huggingface.co/models?library=sentence-transformers&language=zh).", | ||
| description=( | ||
| "Embedding model name. " | ||
| "See https://huggingface.co/models?library=sentence-transformers&language=zh for available models. " | ||
| f"Default is '{DEFAULT_EMBEDDING_MODEL}'." | ||
| ), | ||
| ) | ||
| prompt_template: Annotated[ | ||
| str, AfterValidator(contains_placeholder("keywords")) | ||
| ] = DEFAULT_QUERY_PROMPT_TEMPLATE | ||
| similarity_top_k: int = Field(DEFAULT_SIMILARITY_TOP_K, gt=1) | ||
| ] = Field( | ||
| DEFAULT_QUERY_PROMPT_TEMPLATE, | ||
| description="Prompt template for retrieval. Must contain the {keywords} placeholder.", | ||
|
Comment on lines
+79
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
| similarity_top_k: int = Field( | ||
| DEFAULT_SIMILARITY_TOP_K, | ||
| gt=1, | ||
| description=( | ||
| "Number of top similar results to return during retrieval. " | ||
| f"Default is {DEFAULT_SIMILARITY_TOP_K}." | ||
| ), | ||
|
Comment on lines
+86
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
|
|
||
|
|
||
| def is_available_model(model_name: str): | ||
|
|
@@ -73,25 +99,41 @@ def is_available_model(model_name: str): | |
|
|
||
|
|
||
| class ChatGptConfig(BaseSettings): | ||
| api_key: str = Field(validation_alias="OPENAI_API_KEY") | ||
| api_key: str = Field( | ||
| validation_alias="OPENAI_API_KEY", description="OpenAI API key." | ||
| ) | ||
| model: Annotated[ | ||
| str, | ||
| Field(DEFAULT_OPENAI_MODEL), | ||
| AfterValidator(is_available_model), | ||
| ] | ||
| ] = Field( | ||
| DEFAULT_OPENAI_MODEL, | ||
| description=f"OpenAI LLM model name. Default is '{DEFAULT_OPENAI_MODEL}'.", | ||
| ) | ||
|
|
||
|
|
||
| class SummarizeConfig(BaseModel): | ||
| llm: ChatGptConfig = ChatGptConfig() # type: ignore | ||
| system_template: str = DEFAULT_SYSTEM_TEMPLATE | ||
| llm: ChatGptConfig = Field( | ||
| default_factory=ChatGptConfig, # type: ignore | ||
| description="Configuration for the LLM used for summarization.", | ||
| ) | ||
| system_template: str = Field( | ||
| DEFAULT_SYSTEM_TEMPLATE, | ||
| description="System prompt template for the LLM, used to set the role and rules.", | ||
| ) | ||
| user_template: Annotated[ | ||
| str, AfterValidator(contains_placeholder("context_str", "query_str")) | ||
| ] = DEFAULT_USER_TEMPLATE | ||
| ] = Field( | ||
| DEFAULT_USER_TEMPLATE, | ||
| description="User prompt template for the LLM. Must contain {context_str} and {query_str} placeholders.", | ||
|
Comment on lines
+125
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
| query_str: str = Field( | ||
| DEFAULT_QUERY_STR, | ||
| description="The content of `{query_str}` placeholder in the user template.", | ||
| description="Content for the {query_str} placeholder in user_template.", | ||
| ) | ||
| content_format: ContentFormat = Field( | ||
| ContentFormat.PLAIN, | ||
| description=f"Format of the summary content. Options: {', '.join(e.value for e in ContentFormat)}.", | ||
| ) | ||
| content_format: ContentFormat = ContentFormat.PLAIN | ||
|
|
||
|
|
||
| class RagConfig(BaseModel): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a default value to the description for better clarity and user experience. Also, the link is in Chinese; consider providing an English alternative or mentioning that the linked page is in Chinese.