File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed
pydatalab/src/pydatalab/apps/chat Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11from langchain_anthropic import ChatAnthropic
22from langchain_core .language_models import BaseChatModel , ParrotFakeChatModel
33from langchain_openai import ChatOpenAI
4- from pydantic import BaseModel
4+ from pydantic import BaseModel , Field
55
66
77class 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" )
You can’t perform that action at this time.
0 commit comments