File tree Expand file tree Collapse file tree 3 files changed +16
-9
lines changed
frontend/src/views/system/model Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 1+ from functools import lru_cache
12import json
23from abc import ABC , abstractmethod
34from typing import Optional , Dict , Any , Type
@@ -21,6 +22,18 @@ class LLMConfig(BaseModel):
2122 api_key : Optional [str ] = None
2223 api_base_url : Optional [str ] = None
2324 additional_params : Dict [str , Any ] = {}
25+ class Config :
26+ frozen = True
27+
28+ def __hash__ (self ):
29+ return hash ((
30+ self .model_id ,
31+ self .model_type ,
32+ self .model_name ,
33+ self .api_key ,
34+ self .api_base_url ,
35+ frozenset (self .additional_params .items ())
36+ ))
2437
2538
2639class BaseLLM (ABC ):
@@ -66,6 +79,7 @@ class LLMFactory:
6679 }
6780
6881 @classmethod
82+ @lru_cache (maxsize = 32 )
6983 def create_llm (cls , config : LLMConfig ) -> BaseLLM :
7084 llm_class = cls ._llm_types .get (config .model_type )
7185 if not llm_class :
Original file line number Diff line number Diff line change @@ -27,12 +27,8 @@ async def generate():
2727 additional_params = additional_params ,
2828 )
2929 llm_instance = LLMFactory .create_llm (config )
30-
31- res = llm_instance .llm .stream ("who are you?" )
32-
33- for chunk in res :
30+ async for chunk in llm_instance .llm .astream ("1+1=?" ):
3431 if chunk and chunk .content :
35- SQLBotLogUtil .info (chunk )
3632 yield json .dumps ({"content" : chunk .content }) + "\n "
3733
3834 except Exception as e :
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ const activeName = ref('')
3535const activeType = ref (' ' )
3636const modelFormRef = ref ()
3737const cardRefs = ref <any []>([])
38- // const showCardError = ref(true ) // if you don`t want card mask error, just change this to false
38+ const showCardError = ref (false ) // if you don`t want card mask error, just change this to false
3939reactive ({
4040 form: {
4141 id: ' ' ,
@@ -71,8 +71,6 @@ const defaultModelListWithSearch = computed(() => {
7171})
7272
7373const modelCheckHandler = async (item : any ) => {
74- console .log (item )
75- /**
7674 const response = await modelApi .check (item )
7775 const reader = response .body .getReader ()
7876 const decoder = new TextDecoder ()
@@ -112,7 +110,6 @@ const modelCheckHandler = async (item: any) => {
112110 currentRef ?.showErrorMask (checkMsg )
113111 }
114112 })
115- */
116113}
117114const duplicateName = async (item : any ) => {
118115 const res = await modelApi .queryAll ()
You can’t perform that action at this time.
0 commit comments