mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-04 18:40:10 +00:00
chore: Add pylint for DB-GPT core lib (#1076)
This commit is contained in:
@@ -1,27 +1,34 @@
|
||||
"""Example selector base class"""
|
||||
|
||||
from abc import ABC
|
||||
from enum import Enum
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from dbgpt._private.pydantic import BaseModel
|
||||
|
||||
|
||||
class ExampleType(Enum):
|
||||
"""Example type"""
|
||||
|
||||
ONE_SHOT = "one_shot"
|
||||
FEW_SHOT = "few_shot"
|
||||
|
||||
|
||||
class ExampleSelector(BaseModel, ABC):
|
||||
"""Example selector base class"""
|
||||
|
||||
examples_record: List[dict]
|
||||
use_example: bool = False
|
||||
type: str = ExampleType.ONE_SHOT.value
|
||||
|
||||
def examples(self, count: int = 2):
|
||||
"""Return examples"""
|
||||
if ExampleType.ONE_SHOT.value == self.type:
|
||||
return self.__one_show_context()
|
||||
return self.__one_shot_context()
|
||||
else:
|
||||
return self.__few_shot_context(count)
|
||||
|
||||
def __few_shot_context(self, count: int = 2) -> List[dict]:
|
||||
def __few_shot_context(self, count: int = 2) -> Optional[List[dict]]:
|
||||
"""
|
||||
Use 2 or more examples, default 2
|
||||
Returns: example text
|
||||
@@ -31,14 +38,14 @@ class ExampleSelector(BaseModel, ABC):
|
||||
return need_use
|
||||
return None
|
||||
|
||||
def __one_show_context(self) -> dict:
|
||||
def __one_shot_context(self) -> Optional[dict]:
|
||||
"""
|
||||
Use one examples
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if self.use_example:
|
||||
need_use = self.examples_record[:1]
|
||||
need_use = self.examples_record[-1]
|
||||
return need_use
|
||||
|
||||
return None
|
||||
|
@@ -1,8 +1,12 @@
|
||||
"""Prompt template registry.
|
||||
|
||||
This module is deprecated. we will remove it in the future.
|
||||
"""
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from collections import defaultdict
|
||||
from typing import Dict, List
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
_DEFAULT_MODEL_KEY = "___default_prompt_template_model_key__"
|
||||
_DEFUALT_LANGUAGE_KEY = "___default_prompt_template_language_key__"
|
||||
@@ -14,15 +18,15 @@ class PromptTemplateRegistry:
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.registry = defaultdict(dict)
|
||||
self.registry = defaultdict(dict) # type: ignore
|
||||
|
||||
def register(
|
||||
self,
|
||||
prompt_template,
|
||||
language: str = "en",
|
||||
is_default: bool = False,
|
||||
model_names: List[str] = None,
|
||||
scene_name: str = None,
|
||||
model_names: Optional[List[str]] = None,
|
||||
scene_name: Optional[str] = None,
|
||||
) -> None:
|
||||
"""Register prompt template with scene name, language
|
||||
registry dict format:
|
||||
@@ -43,7 +47,7 @@ class PromptTemplateRegistry:
|
||||
if not scene_name:
|
||||
raise ValueError("Prompt template scene name cannot be empty")
|
||||
if not model_names:
|
||||
model_names: List[str] = [_DEFAULT_MODEL_KEY]
|
||||
model_names = [_DEFAULT_MODEL_KEY]
|
||||
scene_registry = self.registry[scene_name]
|
||||
_register_scene_prompt_template(
|
||||
scene_registry, prompt_template, language, model_names
|
||||
@@ -64,7 +68,7 @@ class PromptTemplateRegistry:
|
||||
scene_name: str,
|
||||
language: str,
|
||||
model_name: str,
|
||||
proxyllm_backend: str = None,
|
||||
proxyllm_backend: Optional[str] = None,
|
||||
):
|
||||
"""Get prompt template with scene name, language and model name
|
||||
proxyllm_backend: see CFG.PROXYLLM_BACKEND
|
||||
|
Reference in New Issue
Block a user