Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions api/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,40 +315,42 @@
return None


class AppModelConfig(Base):
class AppModelConfig(TypeBase):
__tablename__ = "app_model_configs"
__table_args__ = (sa.PrimaryKeyConstraint("id", name="app_model_config_pkey"), sa.Index("app_app_id_idx", "app_id"))

id = mapped_column(StringUUID, default=lambda: str(uuid4()))
app_id = mapped_column(StringUUID, nullable=False)
provider = mapped_column(String(255), nullable=True)
model_id = mapped_column(String(255), nullable=True)
configs = mapped_column(sa.JSON, nullable=True)
created_by = mapped_column(StringUUID, nullable=True)
created_at = mapped_column(sa.DateTime, nullable=False, server_default=func.current_timestamp())
updated_by = mapped_column(StringUUID, nullable=True)
updated_at = mapped_column(
id: Mapped[str] = mapped_column(StringUUID, default=lambda: str(uuid4()))
app_id: Mapped[str] = mapped_column(StringUUID, nullable=False)

Check failure on line 323 in api/models/model.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
provider: Mapped[str | None] = mapped_column(String(255), nullable=True)

Check failure on line 324 in api/models/model.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
model_id: Mapped[str | None] = mapped_column(String(255), nullable=True)

Check failure on line 325 in api/models/model.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
configs: Mapped[Any | None] = mapped_column(sa.JSON, nullable=True)

Check failure on line 326 in api/models/model.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
created_by: Mapped[str | None] = mapped_column(StringUUID, nullable=True)

Check failure on line 327 in api/models/model.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
created_at: Mapped[datetime] = mapped_column(sa.DateTime, nullable=False, server_default=func.current_timestamp())

Check failure on line 328 in api/models/model.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
updated_by: Mapped[str | None] = mapped_column(StringUUID, nullable=True)

Check failure on line 329 in api/models/model.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
updated_at: Mapped[datetime] = mapped_column(

Check failure on line 330 in api/models/model.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
sa.DateTime, nullable=False, server_default=func.current_timestamp(), onupdate=func.current_timestamp()
)
opening_statement = mapped_column(LongText)
suggested_questions = mapped_column(LongText)
suggested_questions_after_answer = mapped_column(LongText)
speech_to_text = mapped_column(LongText)
text_to_speech = mapped_column(LongText)
more_like_this = mapped_column(LongText)
model = mapped_column(LongText)
user_input_form = mapped_column(LongText)
dataset_query_variable = mapped_column(String(255))
pre_prompt = mapped_column(LongText)
agent_mode = mapped_column(LongText)
sensitive_word_avoidance = mapped_column(LongText)
retriever_resource = mapped_column(LongText)
prompt_type = mapped_column(String(255), nullable=False, server_default=sa.text("'simple'"))
chat_prompt_config = mapped_column(LongText)
completion_prompt_config = mapped_column(LongText)
dataset_configs = mapped_column(LongText)
external_data_tools = mapped_column(LongText)
file_upload = mapped_column(LongText)
opening_statement: Mapped[str | None] = mapped_column(LongText)

Check failure on line 333 in api/models/model.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
suggested_questions: Mapped[str | None] = mapped_column(LongText)
suggested_questions_after_answer: Mapped[str | None] = mapped_column(LongText)
speech_to_text: Mapped[str | None] = mapped_column(LongText)
text_to_speech: Mapped[str | None] = mapped_column(LongText)
more_like_this: Mapped[str | None] = mapped_column(LongText)
model: Mapped[str | None] = mapped_column(LongText)
user_input_form: Mapped[str | None] = mapped_column(LongText)
dataset_query_variable: Mapped[str | None] = mapped_column(String(255))
pre_prompt: Mapped[str | None] = mapped_column(LongText)
agent_mode: Mapped[str | None] = mapped_column(LongText)
sensitive_word_avoidance: Mapped[str | None] = mapped_column(LongText)
retriever_resource: Mapped[str | None] = mapped_column(LongText)
prompt_type: Mapped[str] = mapped_column(
String(255), nullable=False, server_default=sa.text("'simple'"), default="simple"
)
chat_prompt_config: Mapped[str | None] = mapped_column(LongText)
completion_prompt_config: Mapped[str | None] = mapped_column(LongText)
dataset_configs: Mapped[str | None] = mapped_column(LongText)
external_data_tools: Mapped[str | None] = mapped_column(LongText)
file_upload: Mapped[str | None] = mapped_column(LongText)

@property
def app(self) -> App | None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,26 +226,27 @@ def test_export_dsl_chat_app_success(self, db_session_with_containers, mock_exte
app, account = self._create_test_app_and_account(db_session_with_containers, mock_external_service_dependencies)

# Create model config for the app
model_config = AppModelConfig()
model_config.id = fake.uuid4()
model_config.app_id = app.id
model_config.provider = "openai"
model_config.model_id = "gpt-3.5-turbo"
model_config.model = json.dumps(
{
"provider": "openai",
"name": "gpt-3.5-turbo",
"mode": "chat",
"completion_params": {
"max_tokens": 1000,
"temperature": 0.7,
},
}
model_config = AppModelConfig(
id=fake.uuid4(),
app_id=app.id,
provider="openai",
model_id="gpt-3.5-turbo",
model=json.dumps(
{
"provider": "openai",
"name": "gpt-3.5-turbo",
"mode": "chat",
"completion_params": {
"max_tokens": 1000,
"temperature": 0.7,
},
}
),
pre_prompt="You are a helpful assistant.",
prompt_type="simple",
created_by=account.id,
updated_by=account.id,
)
model_config.pre_prompt = "You are a helpful assistant."
model_config.prompt_type = "simple"
model_config.created_by = account.id
model_config.updated_by = account.id

# Set the app_model_config_id to link the config
app.app_model_config_id = model_config.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -925,24 +925,25 @@ def test_convert_to_workflow_chat_mode_success(self, db_session_with_containers)
# Create app model config (required for conversion)
from models.model import AppModelConfig

app_model_config = AppModelConfig()
app_model_config.id = fake.uuid4()
app_model_config.app_id = app.id
app_model_config.tenant_id = app.tenant_id
app_model_config.provider = "openai"
app_model_config.model_id = "gpt-3.5-turbo"
# Set the model field directly - this is what model_dict property returns
app_model_config.model = json.dumps(
{
"provider": "openai",
"name": "gpt-3.5-turbo",
"completion_params": {"max_tokens": 1000, "temperature": 0.7},
}
app_model_config = AppModelConfig(
id=fake.uuid4(),
app_id=app.id,
tenant_id=app.tenant_id,
provider="openai",
model_id="gpt-3.5-turbo",
# Set the model field directly - this is what model_dict property returns
model=json.dumps(
{
"provider": "openai",
"name": "gpt-3.5-turbo",
"completion_params": {"max_tokens": 1000, "temperature": 0.7},
}
),
# Set pre_prompt for PromptTemplateConfigManager
pre_prompt="You are a helpful assistant.",
created_by=account.id,
updated_by=account.id,
)
# Set pre_prompt for PromptTemplateConfigManager
app_model_config.pre_prompt = "You are a helpful assistant."
app_model_config.created_by = account.id
app_model_config.updated_by = account.id

from extensions.ext_database import db

Expand Down Expand Up @@ -987,24 +988,25 @@ def test_convert_to_workflow_completion_mode_success(self, db_session_with_conta
# Create app model config (required for conversion)
from models.model import AppModelConfig

app_model_config = AppModelConfig()
app_model_config.id = fake.uuid4()
app_model_config.app_id = app.id
app_model_config.tenant_id = app.tenant_id
app_model_config.provider = "openai"
app_model_config.model_id = "gpt-3.5-turbo"
# Set the model field directly - this is what model_dict property returns
app_model_config.model = json.dumps(
{
"provider": "openai",
"name": "gpt-3.5-turbo",
"completion_params": {"max_tokens": 1000, "temperature": 0.7},
}
app_model_config = AppModelConfig(
id=fake.uuid4(),
app_id=app.id,
tenant_id=app.tenant_id,
provider="openai",
model_id="gpt-3.5-turbo",
# Set the model field directly - this is what model_dict property returns
model=json.dumps(
{
"provider": "openai",
"name": "gpt-3.5-turbo",
"completion_params": {"max_tokens": 1000, "temperature": 0.7},
}
),
# Set pre_prompt for PromptTemplateConfigManager
pre_prompt="Complete the following text:",
created_by=account.id,
updated_by=account.id,
)
# Set pre_prompt for PromptTemplateConfigManager
app_model_config.pre_prompt = "Complete the following text:"
app_model_config.created_by = account.id
app_model_config.updated_by = account.id

from extensions.ext_database import db

Expand Down
Loading