code: import asyncio
  import inspect
  import warnings
  from abc import ABC, abstractmethod
  from functools import partial
  from typing import (
      Any,
      AsyncIterator,
      Dict,
      Iterator,
      List,
      Optional,
      Sequence,
      cast,
  )
  
  import langchain
  from langchain.callbacks.base import BaseCallbackManager
  from langchain.callbacks.manager import (
      AsyncCallbackManager,
      AsyncCallbackManagerForLLMRun,
      CallbackManager,
      CallbackManagerForLLMRun,
      Callbacks,
  )
  from langchain.load.dump import dumpd, dumps
  from langchain.prompts.base import StringPromptValue
  from langchain.prompts.chat import ChatPromptValue
  from langchain.pydantic_v1 import Field, root_validator
  from langchain.schema import (
      ChatGeneration,
      ChatResult,
      LLMResult,
      PromptValue,
      RunInfo,
  )
  from langchain.schema.language_model import BaseLanguageModel, LanguageModelInput
  from langchain.schema.messages import (
      AIMessage,
      BaseMessage,
      BaseMessageChunk,
      HumanMessage,
  )
  from langchain.schema.output import ChatGenerationChunk
  from langchain.schema.runnable import RunnableConfig
  
  
  def _get_verbosity() -> bool:
      return langchain.verbose
  
  
  class BaseChatModel(BaseLanguageModel[BaseMessageChunk], ABC):
      """Base class for Chat models."""
  
      cache: Optional[bool] = None
      """Whether to cache the response."""
      verbose: bool = Field(default_factory=_get_verbosity)
      """Whether to print out response text."""
      callbacks: Callbacks = Field(default=None, exclude=True)
      """Callbacks to add to the run trace."""
      callback_manager: Optional[BaseCallbackManager] = Field(default=None, exclude=True)
      """Callback manager to add to the run trace."""
      tags: Optional[List[str]] = Field(default=None, exclude=True)
      """Tags to add to the run trace."""
      metadata: Optional[Dict[str, Any]] = Field(default=None, exclude=True)
      """Metadata to add to the run trace."""
  
      @root_validator()
      def raise_deprecation(cls, values: Dict) -> Dict:
          """Raise deprecation warning if callback_manager is used."""
          if values.get("callback_manager") is not None:
              warnings.warn(
                  "callback_manager is deprecated. Please use callbacks instead.",
                  DeprecationWarning,
              )
              values["callbacks"] = values.pop("callback_manager", None)
          return values
  
      class Config:
          """Configuration for this pydantic object."""
  
          arbitrary_types_allowed = True
  
      # --- Runnable methods ---
  
      def _convert_input(self, input: LanguageModelInput) -> PromptValue:
          if isinstance(input, PromptValue):
              return input
          elif isinstance(input, str):
              return StringPromptValue(text=input)
          elif isinstance(input, list):
              return ChatPromptValue(messages=input)
          else:
              raise ValueError(
                  f"Invalid input type {type(input)}. "
                  "Must be a PromptValue, str, or list of BaseMessages."
              )
  
      def invoke(
          self,
          input: LanguageModelInput,
          config: Optional[RunnableConfig] = None,
          *,
          stop: Optional[List[str]] = None,
          **kwargs: Any,
      ) -> BaseMessageChunk:
          config = config or {}
          return cast(
              BaseMessageChunk,
              cast(
                  ChatGeneration,
                  self.generate_prompt(
                      [self._convert_input(input)],
                      stop=stop,
                      callbacks=config.get("callbacks"),
                      tags=config.get("tags"),
                      metadata=config.get("metadata"),
                      **kwargs,
                  ).generations[0][0],
              ).message,
          )
  
      async def ainvoke(
          self,
          input: LanguageModelInput,
          config: Optional[RunnableConfig] = None,
          *,
          stop: Optional[List[str]] = None,
          **kwargs: Any,
      ) -> BaseMessageChunk:
          if type(self)._agenerate == BaseChatModel._agenerate:
              # model doesn't implement async generation, so use default implementation
              return await asyncio.get_running_loop().run_in_executor(
                  None, partial(self.invoke, input, config, stop=stop, **kwargs)
              )
  
          config = config or {}
          llm_result = await self.agenerate_prompt(
              [self._convert_input(input)],
              stop=stop,
              callbacks=config.get("callbacks"),
              tags=config.get("tags"),
              metadata=config.get("metadata"),
              **kwargs,
          )
          return cast(
              BaseMessageChunk, cast(ChatGeneration, llm_result.generations[0][0]).message
          )
  
      def stream(
          self,
          input: LanguageModelInput,
          config: Optional[RunnableConfig] = None,
          *,
          stop: Optional[List[str]] = None,
          **kwargs: Any,
      ) -> Iterator[BaseMessageChunk]:
          if type(self)._stream == BaseChatModel._stream:
              # model doesn't implement streaming, so use default implementation
              yield self.invoke(input, config=config, stop=stop, **kwargs)
          else:
              config = config or {}
              messages = self._convert_input(input).to_messages()
              params = self._get_invocation_params(stop=stop, **kwargs)
              options = {"stop": stop, **kwargs}
              callback_manager = CallbackManager.configure(
                  config.get("callbacks"),
                  self.callbacks,
                  self.verbose,
                  config.get("tags"),
                  self.tags,
                  config.get("metadata"),
                  self.metadata,
              )
              (run_manager,) = callback_manager.on_chat_model_start(
                  dumpd(self), [messages], invocation_params=params, options=options
              )
              try:
                  message: Optional[BaseMessageChunk] = None
                  for chunk in self._stream(
                      messages, stop=stop, run_manager=run_manager, **kwargs
                  ):
                      yield chunk.message
                      if message is None:
                          message = chunk.message
                      else:
                          message += chunk.message
                  assert message is not None
              except (KeyboardInterrupt, Exception) as e:
                  run_manager.on_llm_error(e)
                  raise e
              else:
                  run_manager.on_llm_end(
                      LLMResult(generations=[[ChatGeneration(message=message)]]),
                  )
  
      async def astream(
          self,
          input: LanguageModelInput,
          config: Optional[RunnableConfig] = None,
          *,
          stop: Optional[List[str]] = None,
          **kwargs: Any,
      ) -> AsyncIterator[BaseMessageChunk]:
          if type(self)._astream == BaseChatModel._astream:
              # model doesn't implement streaming, so use default implementation
              yield self.invoke(input, config=config, stop=stop, **kwargs)
          else:
              config = config or {}
              messages = self._convert_input(input).to_messages()
              params = self._get_invocation_params(stop=stop, **kwargs)
              options = {"stop": stop, **kwargs}
              callback_manager = AsyncCallbackManager.configure(
                  config.get("callbacks"),
                  self.callbacks,
                  self.verbose,
                  config.get("tags"),
                  self.tags,
                  config.get("metadata"),
                  self.metadata,
              )
              (run_manager,) = await callback_manager.on_chat_model_start(
                  dumpd(self), [messages], invocation_params=params, options=options
              )
              try:
                  message: Optional[BaseMessageChunk] = None
                  async for chunk in self._astream(
                      messages, stop=stop, run_manager=run_manager, **kwargs
                  ):
                      yield chunk.message
                      if message is None:
                          message = chunk.message
                      else:
                          message += chunk.message
                  assert message is not None
              except (KeyboardInterrupt, Exception) as e:
                  await run_manager.on_llm_error(e)
                  raise e
              else:
                  await run_manager.on_llm_end(
                      LLMResult(generations=[[ChatGeneration(message=message)]]),
                  )
  
      # --- Custom methods ---
  
      def _combine_llm_outputs(self, llm_outputs: List[Optional[dict]]) -> dict:
          return {}
  
      def _get_invocation_params(
          self,
          stop: Optional[List[str]] = None,
          **kwargs: Any,
      ) -> dict:
          params = self.dict()
          params["stop"] = stop
          return {**params, **kwargs}
  
      def _get_llm_string(self, stop: Optional[List[str]] = None, **kwargs: Any) -> str:
          if self.lc_serializable:
              params = {**kwargs, **{"stop": stop}}
              param_string = str(sorted([(k, v) for k, v in params.items()]))
              llm_string = dumps(self)
              return llm_string + "---" + param_string
          else:
              params = self._get_invocation_params(stop=stop, **kwargs)
              params = {**params, **kwargs}
              return str(sorted([(k, v) for k, v in params.items()]))
  
      def generate(
          self,
          messages: List[List[BaseMessage]],
          stop: Optional[List[str]] = None,
          callbacks: Callbacks = None,
          *,
          tags: Optional[List[str]] = None,
          metadata: Optional[Dict[str, Any]] = None,
          **kwargs: Any,
      ) -> LLMResult:
          """Top Level call"""
          params = self._get_invocation_params(stop=stop, **kwargs)
          options = {"stop": stop}
  
          callback_manager = CallbackManager.configure(
              callbacks,
              self.callbacks,
              self.verbose,
              tags,
              self.tags,
              metadata,
              self.metadata,
          )
          run_managers = callback_manager.on_chat_model_start(
              dumpd(self), messages, invocation_params=params, options=options
          )
          results = []
          for i, m in enumerate(messages):
              try:
                  results.append(
                      self._generate_with_cache(
                          m,
                          stop=stop,
                          run_manager=run_managers[i] if run_managers else None,
                          **kwargs,
                      )
                  )
              except (KeyboardInterrupt, Exception) as e:
                  if run_managers:
                      run_managers[i].on_llm_error(e)
                  raise e
          flattened_outputs = [
              LLMResult(generations=[res.generations], llm_output=res.llm_output)
              for res in results
          ]
          llm_output = self._combine_llm_outputs([res.llm_output for res in results])
          generations = [res.generations for res in results]
          output = LLMResult(generations=generations, llm_output=llm_output)
          if run_managers:
              run_infos = []
              for manager, flattened_output in zip(run_managers, flattened_outputs):
                  manager.on_llm_end(flattened_output)
                  run_infos.append(RunInfo(run_id=manager.run_id))
              output.run = run_infos
          return output
  
      async def agenerate(
          self,
          messages: List[List[BaseMessage]],
          stop: Optional[List[str]] = None,
          callbacks: Callbacks = None,
          *,
          tags: Optional[List[str]] = None,
          metadata: Optional[Dict[str, Any]] = None,
          **kwargs: Any,
      ) -> LLMResult:
          """Top Level call"""
          params = self._get_invocation_params(stop=stop, **kwargs)
          options = {"stop": stop}
  
          callback_manager = AsyncCallbackManager.configure(
              callbacks,
              self.callbacks,
              self.verbose,
              tags,
              self.tags,
              metadata,
              self.metadata,
          )
  
          run_managers = await callback_manager.on_chat_model_start(
              dumpd(self), messages, invocation_params=params, options=options
          )
  
          results = await asyncio.gather(
              *[
                  self._agenerate_with_cache(
                      m,
                      stop=stop,
                      run_manager=run_managers[i] if run_managers else None,
                      **kwargs,
                  )
                  for i, m in enumerate(messages)
              ],
              return_exceptions=True,
          )
          exceptions = []
          for i, res in enumerate(results):
              if isinstance(res, Exception):
                  if run_managers:
                      await run_managers[i].on_llm_error(res)
                  exceptions.append(res)
          if exceptions:
              if run_managers:
                  await asyncio.gather(
                      *[
                          run_manager.on_llm_end(
                              LLMResult(
                                  generations=[res.generations], llm_output=res.llm_output
                              )
                          )
                          for run_manager, res in zip(run_managers, results)
                          if not isinstance(res, Exception)
                      ]
                  )
              raise exceptions[0]
          flattened_outputs = [
              LLMResult(generations=[res.generations], llm_output=res.llm_output)
              for res in results
          ]
          llm_output = self._combine_llm_outputs([res.llm_output for res in results])
          generations = [res.generations for res in results]
          output = LLMResult(generations=generations, llm_output=llm_output)
          await asyncio.gather(
              *[
                  run_manager.on_llm_end(flattened_output)
                  for run_manager, flattened_output in zip(
                      run_managers, flattened_outputs
                  )
              ]
          )
          if run_managers:
              output.run = [
                  RunInfo(run_id=run_manager.run_id) for run_manager in run_managers
              ]
          return output
  
      def generate_prompt(
          self,
          prompts: List[PromptValue],
          stop: Optional[List[str]] = None,
          callbacks: Callbacks = None,
          **kwargs: Any,
      ) -> LLMResult:
          prompt_messages = [p.to_messages() for p in prompts]
          return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
  
      async def agenerate_prompt(
          self,
          prompts: List[PromptValue],
          stop: Optional[List[str]] = None,
          callbacks: Callbacks = None,
          **kwargs: Any,
      ) -> LLMResult:
          prompt_messages = [p.to_messages() for p in prompts]
          return await self.agenerate(
              prompt_messages, stop=stop, callbacks=callbacks, **kwargs
          )
  
      def _generate_with_cache(
          self,
          messages: List[BaseMessage],
          stop: Optional[List[str]] = None,
          run_manager: Optional[CallbackManagerForLLMRun] = None,
          **kwargs: Any,
      ) -> ChatResult:
          new_arg_supported = inspect.signature(self._generate).parameters.get(
              "run_manager"
          )
          disregard_cache = self.cache is not None and not self.cache
          if langchain.llm_cache is None or disregard_cache:
              # This happens when langchain.cache is None, but self.cache is True
              if self.cache is not None and self.cache:
                  raise ValueError(
                      "Asked to cache, but no cache found at `langchain.cache`."
                  )
              if new_arg_supported:
                  return self._generate(
                      messages, stop=stop, run_manager=run_manager, **kwargs
                  )
              else:
                  return self._generate(messages, stop=stop, **kwargs)
          else:
              llm_string = self._get_llm_string(stop=stop, **kwargs)
              prompt = dumps(messages)
              cache_val = langchain.llm_cache.lookup(prompt, llm_string)
              if isinstance(cache_val, list):
                  return ChatResult(generations=cache_val)
              else:
                  if new_arg_supported:
                      result = self._generate(
                          messages, stop=stop, run_manager=run_manager, **kwargs
                      )
                  else:
                      result = self._generate(messages, stop=stop, **kwargs)
                  langchain.llm_cache.update(prompt, llm_string, result.generations)
                  return result
  
      async def _agenerate_with_cache(
          self,
          messages: List[BaseMessage],
          stop: Optional[List[str]] = None,
          run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
          **kwargs: Any,
      ) -> ChatResult:
          new_arg_supported = inspect.signature(self._agenerate).parameters.get(
              "run_manager"
          )
          disregard_cache = self.cache is not None and not self.cache
          if langchain.llm_cache is None or disregard_cache:
              # This happens when langchain.cache is None, but self.cache is True
              if self.cache is not None and self.cache:
                  raise ValueError(
                      "Asked to cache, but no cache found at `langchain.cache`."
                  )
              if new_arg_supported:
                  return await self._agenerate(
                      messages, stop=stop, run_manager=run_manager, **kwargs
                  )
              else:
                  return await self._agenerate(messages, stop=stop, **kwargs)
          else:
              llm_string = self._get_llm_string(stop=stop, **kwargs)
              prompt = dumps(messages)
              cache_val = langchain.llm_cache.lookup(prompt, llm_string)
              if isinstance(cache_val, list):
                  return ChatResult(generations=cache_val)
              else:
                  if new_arg_supported:
                      result = await self._agenerate(
                          messages, stop=stop, run_manager=run_manager, **kwargs
                      )
                  else:
                      result = await self._agenerate(messages, stop=stop, **kwargs)
                  langchain.llm_cache.update(prompt, llm_string, result.generations)
                  return result
  
      @abstractmethod
      def _generate(
          self,
          messages: List[BaseMessage],
          stop: Optional[List[str]] = None,
          run_manager: Optional[CallbackManagerForLLMRun] = None,
          **kwargs: Any,
      ) -> ChatResult:
          """Top Level call"""
  
      async def _agenerate(
          self,
          messages: List[BaseMessage],
          stop: Optional[List[str]] = None,
          run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
          **kwargs: Any,
      ) -> ChatResult:
          """Top Level call"""
          raise NotImplementedError()
  
      def _stream(
          self,
          messages: List[BaseMessage],
          stop: Optional[List[str]] = None,
          run_manager: Optional[CallbackManagerForLLMRun] = None,
          **kwargs: Any,
      ) -> Iterator[ChatGenerationChunk]:
          raise NotImplementedError()
  
      def _astream(
          self,
          messages: List[BaseMessage],
          stop: Optional[List[str]] = None,
          run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
          **kwargs: Any,
      ) -> AsyncIterator[ChatGenerationChunk]:
          raise NotImplementedError()
  
      def __call__(
          self,
          messages: List[BaseMessage],
          stop: Optional[List[str]] = None,
          callbacks: Callbacks = None,
          **kwargs: Any,
      ) -> BaseMessage:
          generation = self.generate(
              [messages], stop=stop, callbacks=callbacks, **kwargs
          ).generations[0][0]
          if isinstance(generation, ChatGeneration):
              return generation.message
          else:
              raise ValueError("Unexpected generation type")
  
      async def _call_async(
          self,
          messages: List[BaseMessage],
          stop: Optional[List[str]] = None,
          callbacks: Callbacks = None,
          **kwargs: Any,
      ) -> BaseMessage:
          result = await self.agenerate(
              [messages], stop=stop, callbacks=callbacks, **kwargs
          )
          generation = result.generations[0][0]
          if isinstance(generation, ChatGeneration):
              return generation.message
          else:
              raise ValueError("Unexpected generation type")
  
      def call_as_llm(
          self, message: str, stop: Optional[List[str]] = None, **kwargs: Any
      ) -> str:
          return self.predict(message, stop=stop, **kwargs)
  
      def predict(
          self, text: str, *, stop: Optional[Sequence[str]] = None, **kwargs: Any
      ) -> str:
          if stop is None:
              _stop = None
          else:
              _stop = list(stop)
          result = self([HumanMessage(content=text)], stop=_stop, **kwargs)
          return result.content
  
      def predict_messages(
          self,
          messages: List[BaseMessage],
          *,
          stop: Optional[Sequence[str]] = None,
          **kwargs: Any,
      ) -> BaseMessage:
          if stop is None:
              _stop = None
          else:
              _stop = list(stop)
          return self(messages, stop=_stop, **kwargs)
  
      async def apredict(
          self, text: str, *, stop: Optional[Sequence[str]] = None, **kwargs: Any
      ) -> str:
          if stop is None:
              _stop = None
          else:
              _stop = list(stop)
          result = await self._call_async(
              [HumanMessage(content=text)], stop=_stop, **kwargs
          )
          return result.content
  
      async def apredict_messages(
          self,
          messages: List[BaseMessage],
          *,
          stop: Optional[Sequence[str]] = None,
          **kwargs: Any,
      ) -> BaseMessage:
          if stop is None:
              _stop = None
          else:
              _stop = list(stop)
          return await self._call_async(messages, stop=_stop, **kwargs)
  
      @property
      def _identifying_params(self) -> Dict[str, Any]:
          """Get the identifying parameters."""
          return {}
  
      @property
      @abstractmethod
      def _llm_type(self) -> str:
          """Return type of chat model."""
  
      def dict(self, **kwargs: Any) -> Dict:
          """Return a dictionary of the LLM."""
          starter_dict = dict(self._identifying_params)
          starter_dict["_type"] = self._llm_type
          return starter_dict
  
  
  class SimpleChatModel(BaseChatModel):
      """Simple Chat Model."""
  
      def _generate(
          self,
          messages: List[BaseMessage],
          stop: Optional[List[str]] = None,
          run_manager: Optional[CallbackManagerForLLMRun] = None,
          **kwargs: Any,
      ) -> ChatResult:
          output_str = self._call(messages, stop=stop, run_manager=run_manager, **kwargs)
          message = AIMessage(content=output_str)
          generation = ChatGeneration(message=message)
          return ChatResult(generations=[generation])
  
      @abstractmethod
      def _call(
          self,
          messages: List[BaseMessage],
          stop: Optional[List[str]] = None,
          run_manager: Optional[CallbackManagerForLLMRun] = None,
          **kwargs: Any,
      ) -> str:
          """Simpler interface."""
  
      async def _agenerate(
          self,
          messages: List[BaseMessage],
          stop: Optional[List[str]] = None,
          run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
          **kwargs: Any,
      ) -> ChatResult:
          func = partial(
              self._generate, messages, stop=stop, run_manager=run_manager, **kwargs
          )
          return await asyncio.get_event_loop().run_in_executor(None, func)
  
apis: langchain.llm_cache.lookup langchain.schema.messages.HumanMessage langchain.prompts.base.StringPromptValue langchain.schema.messages.AIMessage langchain.schema.ChatGeneration langchain.load.dump.dumps langchain.schema.RunInfo langchain.llm_cache.update langchain.pydantic_v1.Field langchain.callbacks.manager.AsyncCallbackManager.configure langchain.schema.ChatResult langchain.callbacks.manager.CallbackManager.configure langchain.pydantic_v1.root_validator langchain.schema.LLMResult langchain.load.dump.dumpd langchain.prompts.chat.ChatPromptValue
extract_api: [((1364, 1401), 'langchain.pydantic_v1.Field', 'Field', ([], {'default_factory': '_get_verbosity'}), '(default_factory=_get_verbosity)\n', (1369, 1401), False, 'from langchain.pydantic_v1 import Field, root_validator\n'), ((1475, 1508), 'langchain.pydantic_v1.Field', 'Field', ([], {'default': 'None', 'exclude': '(True)'}), '(default=None, exclude=True)\n', (1480, 1508), False, 'from langchain.pydantic_v1 import Field, root_validator\n'), ((1608, 1641), 'langchain.pydantic_v1.Field', 'Field', ([], {'default': 'None', 'exclude': '(True)'}), '(default=None, exclude=True)\n', (1613, 1641), False, 'from langchain.pydantic_v1 import Field, root_validator\n'), ((1726, 1759), 'langchain.pydantic_v1.Field', 'Field', ([], {'default': 'None', 'exclude': '(True)'}), '(default=None, exclude=True)\n', (1731, 1759), False, 'from langchain.pydantic_v1 import Field, root_validator\n'), ((1841, 1874), 'langchain.pydantic_v1.Field', 'Field', ([], {'default': 'None', 'exclude': '(True)'}), '(default=None, exclude=True)\n', (1846, 1874), False, 'from langchain.pydantic_v1 import Field, root_validator\n'), ((1925, 1941), 'langchain.pydantic_v1.root_validator', 'root_validator', ([], {}), '()\n', (1939, 1941), False, 'from langchain.pydantic_v1 import Field, root_validator\n'), ((9835, 9947), 'langchain.callbacks.manager.CallbackManager.configure', 'CallbackManager.configure', (['callbacks', 'self.callbacks', 'self.verbose', 'tags', 'self.tags', 'metadata', 'self.metadata'], {}), '(callbacks, self.callbacks, self.verbose, tags,\n    self.tags, metadata, self.metadata)\n', (9860, 9947), False, 'from langchain.callbacks.manager import AsyncCallbackManager, AsyncCallbackManagerForLLMRun, CallbackManager, CallbackManagerForLLMRun, Callbacks\n'), ((11036, 11093), 'langchain.schema.LLMResult', 'LLMResult', ([], {'generations': 'generations', 'llm_output': 'llm_output'}), '(generations=generations, llm_output=llm_output)\n', (11045, 11093), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((11869, 11986), 'langchain.callbacks.manager.AsyncCallbackManager.configure', 'AsyncCallbackManager.configure', (['callbacks', 'self.callbacks', 'self.verbose', 'tags', 'self.tags', 'metadata', 'self.metadata'], {}), '(callbacks, self.callbacks, self.verbose,\n    tags, self.tags, metadata, self.metadata)\n', (11899, 11986), False, 'from langchain.callbacks.manager import AsyncCallbackManager, AsyncCallbackManagerForLLMRun, CallbackManager, CallbackManagerForLLMRun, Callbacks\n'), ((13721, 13778), 'langchain.schema.LLMResult', 'LLMResult', ([], {'generations': 'generations', 'llm_output': 'llm_output'}), '(generations=generations, llm_output=llm_output)\n', (13730, 13778), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((22871, 22900), 'langchain.schema.messages.AIMessage', 'AIMessage', ([], {'content': 'output_str'}), '(content=output_str)\n', (22880, 22900), False, 'from langchain.schema.messages import AIMessage, BaseMessage, BaseMessageChunk, HumanMessage\n'), ((22922, 22953), 'langchain.schema.ChatGeneration', 'ChatGeneration', ([], {'message': 'message'}), '(message=message)\n', (22936, 22953), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((22969, 23005), 'langchain.schema.ChatResult', 'ChatResult', ([], {'generations': '[generation]'}), '(generations=[generation])\n', (22979, 23005), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((23517, 23596), 'functools.partial', 'partial', (['self._generate', 'messages'], {'stop': 'stop', 'run_manager': 'run_manager'}), '(self._generate, messages, stop=stop, run_manager=run_manager, **kwargs)\n', (23524, 23596), False, 'from functools import partial\n'), ((2132, 2234), 'warnings.warn', 'warnings.warn', (['"""callback_manager is deprecated. Please use callbacks instead."""', 'DeprecationWarning'], {}), "('callback_manager is deprecated. Please use callbacks instead.',\n    DeprecationWarning)\n", (2145, 2234), False, 'import warnings\n'), ((9118, 9129), 'langchain.load.dump.dumps', 'dumps', (['self'], {}), '(self)\n', (9123, 9129), False, 'from langchain.load.dump import dumpd, dumps\n'), ((10112, 10123), 'langchain.load.dump.dumpd', 'dumpd', (['self'], {}), '(self)\n', (10117, 10123), False, 'from langchain.load.dump import dumpd, dumps\n'), ((10767, 10834), 'langchain.schema.LLMResult', 'LLMResult', ([], {'generations': '[res.generations]', 'llm_output': 'res.llm_output'}), '(generations=[res.generations], llm_output=res.llm_output)\n', (10776, 10834), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((13452, 13519), 'langchain.schema.LLMResult', 'LLMResult', ([], {'generations': '[res.generations]', 'llm_output': 'res.llm_output'}), '(generations=[res.generations], llm_output=res.llm_output)\n', (13461, 13519), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((16027, 16042), 'langchain.load.dump.dumps', 'dumps', (['messages'], {}), '(messages)\n', (16032, 16042), False, 'from langchain.load.dump import dumpd, dumps\n'), ((16067, 16113), 'langchain.llm_cache.lookup', 'langchain.llm_cache.lookup', (['prompt', 'llm_string'], {}), '(prompt, llm_string)\n', (16093, 16113), False, 'import langchain\n'), ((17747, 17762), 'langchain.load.dump.dumps', 'dumps', (['messages'], {}), '(messages)\n', (17752, 17762), False, 'from langchain.load.dump import dumpd, dumps\n'), ((17787, 17833), 'langchain.llm_cache.lookup', 'langchain.llm_cache.lookup', (['prompt', 'llm_string'], {}), '(prompt, llm_string)\n', (17813, 17833), False, 'import langchain\n'), ((2713, 2742), 'langchain.prompts.base.StringPromptValue', 'StringPromptValue', ([], {'text': 'input'}), '(text=input)\n', (2730, 2742), False, 'from langchain.prompts.base import StringPromptValue\n'), ((4629, 4679), 'typing.cast', 'cast', (['ChatGeneration', 'llm_result.generations[0][0]'], {}), '(ChatGeneration, llm_result.generations[0][0])\n', (4633, 4679), False, 'from typing import Any, AsyncIterator, Dict, Iterator, List, Optional, Sequence, cast\n'), ((5755, 5766), 'langchain.load.dump.dumpd', 'dumpd', (['self'], {}), '(self)\n', (5760, 5766), False, 'from langchain.load.dump import dumpd, dumps\n'), ((12158, 12169), 'langchain.load.dump.dumpd', 'dumpd', (['self'], {}), '(self)\n', (12163, 12169), False, 'from langchain.load.dump import dumpd, dumps\n'), ((14101, 14135), 'langchain.schema.RunInfo', 'RunInfo', ([], {'run_id': 'run_manager.run_id'}), '(run_id=run_manager.run_id)\n', (14108, 14135), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((16181, 16214), 'langchain.schema.ChatResult', 'ChatResult', ([], {'generations': 'cache_val'}), '(generations=cache_val)\n', (16191, 16214), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((16530, 16596), 'langchain.llm_cache.update', 'langchain.llm_cache.update', (['prompt', 'llm_string', 'result.generations'], {}), '(prompt, llm_string, result.generations)\n', (16556, 16596), False, 'import langchain\n'), ((17901, 17934), 'langchain.schema.ChatResult', 'ChatResult', ([], {'generations': 'cache_val'}), '(generations=cache_val)\n', (17911, 17934), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((18264, 18330), 'langchain.llm_cache.update', 'langchain.llm_cache.update', (['prompt', 'llm_string', 'result.generations'], {}), '(prompt, llm_string, result.generations)\n', (18290, 18330), False, 'import langchain\n'), ((20898, 20924), 'langchain.schema.messages.HumanMessage', 'HumanMessage', ([], {'content': 'text'}), '(content=text)\n', (20910, 20924), False, 'from langchain.schema.messages import AIMessage, BaseMessage, BaseMessageChunk, HumanMessage\n'), ((2800, 2831), 'langchain.prompts.chat.ChatPromptValue', 'ChatPromptValue', ([], {'messages': 'input'}), '(messages=input)\n', (2815, 2831), False, 'from langchain.prompts.chat import ChatPromptValue\n'), ((4200, 4256), 'functools.partial', 'partial', (['self.invoke', 'input', 'config'], {'stop': 'stop'}), '(self.invoke, input, config, stop=stop, **kwargs)\n', (4207, 4256), False, 'from functools import partial\n'), ((7657, 7668), 'langchain.load.dump.dumpd', 'dumpd', (['self'], {}), '(self)\n', (7662, 7668), False, 'from langchain.load.dump import dumpd, dumps\n'), ((11315, 11345), 'langchain.schema.RunInfo', 'RunInfo', ([], {'run_id': 'manager.run_id'}), '(run_id=manager.run_id)\n', (11322, 11345), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((15194, 15227), 'inspect.signature', 'inspect.signature', (['self._generate'], {}), '(self._generate)\n', (15211, 15227), False, 'import inspect\n'), ((16899, 16933), 'inspect.signature', 'inspect.signature', (['self._agenerate'], {}), '(self._agenerate)\n', (16916, 16933), False, 'import inspect\n'), ((21574, 21600), 'langchain.schema.messages.HumanMessage', 'HumanMessage', ([], {'content': 'text'}), '(content=text)\n', (21586, 21600), False, 'from langchain.schema.messages import AIMessage, BaseMessage, BaseMessageChunk, HumanMessage\n'), ((23640, 23664), 'asyncio.get_event_loop', 'asyncio.get_event_loop', ([], {}), '()\n', (23662, 23664), False, 'import asyncio\n'), ((4134, 4160), 'asyncio.get_running_loop', 'asyncio.get_running_loop', ([], {}), '()\n', (4158, 4160), False, 'import asyncio\n'), ((6521, 6552), 'langchain.schema.ChatGeneration', 'ChatGeneration', ([], {'message': 'message'}), '(message=message)\n', (6535, 6552), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((13049, 13116), 'langchain.schema.LLMResult', 'LLMResult', ([], {'generations': '[res.generations]', 'llm_output': 'res.llm_output'}), '(generations=[res.generations], llm_output=res.llm_output)\n', (13058, 13116), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n'), ((8442, 8473), 'langchain.schema.ChatGeneration', 'ChatGeneration', ([], {'message': 'message'}), '(message=message)\n', (8456, 8473), False, 'from langchain.schema import ChatGeneration, ChatResult, LLMResult, PromptValue, RunInfo\n')]