Skip to content

Commit 312bacb

Browse files
perf: Optimize VLLM OpenAI integration vLLM model validation result parsing
1 parent 684cb4f commit 312bacb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

backend/apps/ai_model/model_factory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ def _init_llm(self) -> VLLMOpenAI:
6666
openai_api_key=self.config.api_key or 'Empty',
6767
openai_api_base=self.config.api_base_url,
6868
model_name=self.config.model_name,
69+
streaming=True,
6970
**self.config.additional_params,
7071
)
7172
class OpenAILLM(BaseLLM):
7273
def _init_llm(self) -> BaseChatModel:
7374
return BaseChatOpenAI(
7475
model=self.config.model_name,
75-
api_key=self.config.api_key,
76+
api_key=self.config.api_key or 'Empty',
7677
base_url=self.config.api_base_url,
7778
stream_usage=True,
7879
**self.config.additional_params,

backend/apps/system/api/aimodel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ async def generate():
2828
)
2929
llm_instance = LLMFactory.create_llm(config)
3030
async for chunk in llm_instance.llm.astream("1+1=?"):
31-
if chunk and chunk.content:
31+
SQLBotLogUtil.info(chunk)
32+
if chunk and isinstance(chunk, str):
33+
yield json.dumps({"content": chunk}) + "\n"
34+
if chunk and isinstance(chunk, dict) and chunk.content:
3235
yield json.dumps({"content": chunk.content}) + "\n"
3336

3437
except Exception as e:

0 commit comments

Comments
 (0)