Skip to content

Commit 203e6a9

Browse files
authored
Chat block fix: ignore available models list based on web app update (#1340)
1 parent b8d56fe commit 203e6a9

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pydatalab/src/pydatalab/apps/chat/blocks.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ChatBlockResponse(DataBlockResponse):
1919
messages: list[dict] = Field(default_factory=list)
2020
prompt: str | None
2121
model: str
22-
available_models: dict[str, ModelCard] = Field(exclude=True)
22+
available_models: dict[str, ModelCard]
2323
token_count: int | None
2424
temperature: float
2525

@@ -120,7 +120,7 @@ def continue_conversation(self, prompt: str | None) -> None:
120120
if self.data["messages"][-1]["role"] not in ("user", "system"):
121121
return
122122

123-
if self.data.get("model") not in self.data.get("available_models", {}):
123+
if self.data.get("model") not in AVAILABLE_MODELS:
124124
bad_model = self.data.get("model")
125125
warnings.warn(
126126
f"Chatblock received an unknown or deprecated model: {bad_model}. Reverting to default model {self.defaults['model']}."
@@ -130,7 +130,12 @@ def continue_conversation(self, prompt: str | None) -> None:
130130
try:
131131
model_name = self.data["model"]
132132

133-
model_cls = self.data["available_models"][model_name]
133+
model_cls = AVAILABLE_MODELS[model_name]
134+
135+
if model_cls.chat_client is None:
136+
raise RuntimeError(
137+
f"The model {model_name} is not available. Please choose a different model."
138+
)
134139

135140
chat_client = model_cls.chat_client(model=model_cls.name)
136141

pydatalab/src/pydatalab/apps/chat/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from langchain_anthropic import ChatAnthropic
22
from langchain_core.language_models import BaseChatModel, ParrotFakeChatModel
33
from langchain_openai import ChatOpenAI
4-
from pydantic import BaseModel
4+
from pydantic import BaseModel, Field
55

66

77
class ModelCard(BaseModel):
88
name: str
99
context_window: int
1010
input_cost_usd_per_MTok: float
1111
output_cost_usd_per_MTok: float
12-
chat_client: type[BaseChatModel]
12+
chat_client: type[BaseChatModel] | None = Field(exclude=True)
1313

1414

1515
__all__ = ("AVAILABLE_MODELS", "ModelCard")

0 commit comments

Comments
 (0)