autorag.deploy package¶
Submodules¶
autorag.deploy.api module¶
- class autorag.deploy.api.ApiRunner(config: Dict, project_dir: str | None = None)[source]¶
Bases:
BaseRunner
- extract_retrieve_passage(df: DataFrame) List[RetrievedPassage] [source]¶
- run_api_server(host: str = '0.0.0.0', port: int = 8000, remote: bool = True, **kwargs)[source]¶
Run the pipeline as an api server. Here is api endpoint documentation => https://docs.auto-rag.com/deploy/api_endpoint.html
- Parameters:
host – The host of the api server.
port – The port of the api server.
remote – Whether to expose the api server to the public internet using ngrok.
kwargs – Other arguments for Flask app.run.
- class autorag.deploy.api.Passage(*, doc_id: str, content: str, score: float)[source]¶
Bases:
BaseModel
- content: str¶
- doc_id: str¶
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}¶
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'content': FieldInfo(annotation=str, required=True), 'doc_id': FieldInfo(annotation=str, required=True), 'score': FieldInfo(annotation=float, required=True)}¶
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- score: float¶
- class autorag.deploy.api.QueryRequest(*, query: str, result_column: str | None = 'generated_texts')[source]¶
Bases:
BaseModel
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}¶
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'query': FieldInfo(annotation=str, required=True), 'result_column': FieldInfo(annotation=Union[str, NoneType], required=False, default='generated_texts')}¶
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- query: str¶
- result_column: str | None¶
- class autorag.deploy.api.RetrievalResponse(*, passages: List[Passage])[source]¶
Bases:
BaseModel
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}¶
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'passages': FieldInfo(annotation=List[Passage], required=True)}¶
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- class autorag.deploy.api.RetrievedPassage(*, content: str, doc_id: str, filepath: str | None = None, file_page: int | None = None, start_idx: int | None = None, end_idx: int | None = None)[source]¶
Bases:
BaseModel
- content: str¶
- doc_id: str¶
- end_idx: int | None¶
- file_page: int | None¶
- filepath: str | None¶
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}¶
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'content': FieldInfo(annotation=str, required=True), 'doc_id': FieldInfo(annotation=str, required=True), 'end_idx': FieldInfo(annotation=Union[int, NoneType], required=False, default=None), 'file_page': FieldInfo(annotation=Union[int, NoneType], required=False, default=None), 'filepath': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'start_idx': FieldInfo(annotation=Union[int, NoneType], required=False, default=None)}¶
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- start_idx: int | None¶
- class autorag.deploy.api.RunResponse(*, result: str | List[str], retrieved_passage: List[RetrievedPassage])[source]¶
Bases:
BaseModel
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}¶
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'result': FieldInfo(annotation=Union[str, List[str]], required=True), 'retrieved_passage': FieldInfo(annotation=List[RetrievedPassage], required=True)}¶
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- result: str | List[str]¶
- retrieved_passage: List[RetrievedPassage]¶
- class autorag.deploy.api.StreamResponse(*, type: Literal['generated_text', 'retrieved_passage'], generated_text: str | None, retrieved_passage: RetrievedPassage | None, passage_index: int | None)[source]¶
Bases:
BaseModel
When the type is generated_text, only generated_text is returned. The other fields are None. When the type is retrieved_passage, only retrieved_passage and passage_index are returned. The other fields are None.
- generated_text: str | None¶
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}¶
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'generated_text': FieldInfo(annotation=Union[str, NoneType], required=True), 'passage_index': FieldInfo(annotation=Union[int, NoneType], required=True), 'retrieved_passage': FieldInfo(annotation=Union[RetrievedPassage, NoneType], required=True), 'type': FieldInfo(annotation=Literal['generated_text', 'retrieved_passage'], required=True)}¶
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- passage_index: int | None¶
- retrieved_passage: RetrievedPassage | None¶
- type: Literal['generated_text', 'retrieved_passage']¶
- class autorag.deploy.api.VersionResponse(*, version: str)[source]¶
Bases:
BaseModel
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}¶
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'version': FieldInfo(annotation=str, required=True)}¶
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.
This replaces Model.__fields__ from Pydantic V1.
- version: str¶
autorag.deploy.base module¶
- class autorag.deploy.base.BaseRunner(config: Dict, project_dir: str | None = None)[source]¶
Bases:
object
- classmethod from_trial_folder(trial_path: str)[source]¶
Load Runner from the evaluated trial folder. Must already be evaluated using Evaluator class. It sets the project_dir as the parent directory of the trial folder.
- Parameters:
trial_path – The path of the trial folder.
- Returns:
Initialized Runner.
- classmethod from_yaml(yaml_path: str, project_dir: str | None = None)[source]¶
Load Runner from the YAML file. Must be extracted YAML file from the evaluated trial using the extract_best_config method.
- Parameters:
yaml_path – The path of the YAML file.
project_dir – The path of the project directory. Default is the current directory.
- Returns:
Initialized Runner.
- class autorag.deploy.base.Runner(config: Dict, project_dir: str | None = None)[source]¶
Bases:
BaseRunner
- run(query: str, result_column: str = 'generated_texts')[source]¶
Run the pipeline with query. The loaded pipeline must start with a single query, so the first module of the pipeline must be query_expansion or retrieval module.
- Parameters:
query – The query of the user.
result_column – The result column name for the answer. Default is generated_texts, which is the output of the generation module.
- Returns:
The result of the pipeline.
- autorag.deploy.base.extract_best_config(trial_path: str, output_path: str | None = None) Dict [source]¶
Extract the optimal pipeline from the evaluated trial.
- Parameters:
trial_path – The path to the trial directory that you want to extract the pipeline from. Must already be evaluated.
output_path – Output path that pipeline yaml file will be saved. Must be .yaml or .yml file. If None, it does not save YAML file and just returns dict values. Default is None.
- Returns:
The dictionary of the extracted pipeline.
- autorag.deploy.base.extract_node_line_names(config_dict: Dict) List[str] [source]¶
Extract node line names with the given config dictionary order.
- Parameters:
config_dict – The YAML configuration dict for the pipeline. You can load this to access trail_folder/config.yaml.
- Returns:
The list of node line names. It is the order of the node line names in the pipeline.
- autorag.deploy.base.extract_node_strategy(config_dict: Dict) Dict [source]¶
Extract node strategies with the given config dictionary. The return value is a dictionary of the node type and its strategy.
- Parameters:
config_dict – The YAML configuration dict for the pipeline. You can load this to access trail_folder/config.yaml.
- Returns:
Key is node_type and value is strategy dict.
- autorag.deploy.base.summary_df_to_yaml(summary_df: DataFrame, config_dict: Dict) Dict [source]¶
Convert trial summary dataframe to config yaml file.
- Parameters:
summary_df – The trial summary dataframe of the evaluated trial.
config_dict – The yaml configuration dict for the pipeline. You can load this to access trail_folder/config.yaml.
- Returns:
Dictionary of config yaml file. You can save this dictionary to yaml file.
autorag.deploy.gradio module¶
- class autorag.deploy.gradio.GradioRunner(config: Dict, project_dir: str | None = None)[source]¶
Bases:
BaseRunner
- run(query: str, result_column: str = 'generated_texts')[source]¶
Run the pipeline with query. The loaded pipeline must start with a single query, so the first module of the pipeline must be query_expansion or retrieval module.
- Parameters:
query – The query of the user.
result_column – The result column name for the answer. Default is generated_texts, which is the output of the generation module.
- Returns:
The result of the pipeline.
- run_web(server_name: str = '0.0.0.0', server_port: int = 7680, share: bool = False, **kwargs)[source]¶
Run web interface to interact pipeline. You can access the web interface at http://server_name:server_port in your browser
- Parameters:
server_name – The host of the web. Default is 0.0.0.0.
server_port – The port of the web. Default is 7680.
share – Whether to create a publicly shareable link. Default is False.
kwargs – Other arguments for gr.ChatInterface.launch.