File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # -*- coding: utf-8 -*--
3+
4+ # Copyright (c) 2023 Oracle and/or its affiliates.
5+ # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6+
7+
8+ from typing import Any
9+ from langchain .schema .output_parser import BaseOutputParser
10+
11+
12+ class SingleKeyDictOutputParser (BaseOutputParser [Any ]):
13+ """Stores the text into a dictionary with a single key.
14+
15+ Example::
16+
17+ # Putting the output of the LLM into a dictionary
18+ chain = GenerativeAI(...) | SingleKeyDictOutputParser(key="my_key")
19+ # The ``output`` will be a dictionary like ``{"my_key": "..."}``
20+ output = chain.invoke("...")
21+
22+ """
23+
24+ key : str
25+ """The key in the dictionary. The the input text will be store as the value of this key."""
26+
27+ def parse (self , text : str ) -> dict :
28+ return {self .key : text }
You can’t perform that action at this time.
0 commit comments