diff --git a/libs/langchain/langchain/llms/openllm.py b/libs/langchain/langchain/llms/openllm.py index df8d4bc38183a..d0d70f1494f0b 100644 --- a/libs/langchain/langchain/llms/openllm.py +++ b/libs/langchain/langchain/llms/openllm.py @@ -265,10 +265,16 @@ def _call( self._identifying_params["model_name"], **copied ) if self._client: - return self._client.query(prompt, **config.model_dump(flatten=True)) + o = self._client.query(prompt, **config.model_dump(flatten=True)) + if isinstance(o, dict) and "text" in o: + return o["text"] + return o else: assert self._runner is not None - return self._runner(prompt, **config.model_dump(flatten=True)) + o = self._runner(prompt, **config.model_dump(flatten=True)) + if isinstance(o, dict) and "text" in o: + return o["text"] + return o async def _acall( self, @@ -291,9 +297,12 @@ async def _acall( self._identifying_params["model_name"], **copied ) if self._client: - return await self._client.acall( + o = await self._client.acall( "generate", prompt, **config.model_dump(flatten=True) ) + if isinstance(o, dict) and "text" in o: + return o["text"] + return o else: assert self._runner is not None ( @@ -304,6 +313,9 @@ async def _acall( generated_result = await self._runner.generate.async_run( prompt, **generate_kwargs ) - return self._runner.llm.postprocess_generate( + o = self._runner.llm.postprocess_generate( prompt, generated_result, **postprocess_kwargs ) + if isinstance(o, dict) and "text" in o: + return o["text"] + return o