Table-like Output Parser #18903
Replies: 2 comments 10 replies
-
Hey @machung2001, great to see you diving into the world of LangChain again! Hope you're doing fantastic. 😄 Based on the context provided, it seems you're looking to create a structured output from the language model in a table-like format. The context suggests using a Pydantic model to define the structure of your table and the However, it's important to note that the current version of LangChain you're using (0.1.0) might not support the Here's a simplified example of how you might implement this: from pydantic import BaseModel, Field
from typing import List
class ComparisonItem(BaseModel):
attribute: str = Field(..., description="The attribute being compared")
java: str = Field(..., description="Value of the attribute for Java")
python: str = Field(..., description="Value of the attribute for Python")
class ComparisonTable(BaseModel):
comparisons: List[ComparisonItem] = Field(..., description="List of comparisons between Java and Python")
# Example usage
comparison_table = ComparisonTable(
comparisons=[
ComparisonItem(attribute="Type", java="Compiled language", python="Interpreted language"),
ComparisonItem(attribute="Use Case", java="GUI apps and web app services", python="Scientific and numeric computing, especially ML"),
# Add more ComparisonItems as needed
]
)
print(comparison_table.json()) This will output a JSON representation of your comparison table. You can then use this JSON to generate a table-like output in your desired format. Please note that this is a simplified example and might not cover all your needs. You might need to adjust it according to your specific requirements. Also, remember to update your LangChain to the latest version to access the most recent features and improvements. For more information on Pydantic models, you can refer to the Pydantic documentation. For more details on the Sources
|
Beta Was this translation helpful? Give feedback.
-
Can I use pyDantic for dynamic data ? Suppose I am using an API which collects data from vector db and it passes to Next js my frontend and I want to show it in tabular form for various categories . eg of my data response
For the fiscal year ended January 29, 2023, the revenue by reportable segments is as follows:
These figures indicate significant growth in both segments from the previous fiscal year. [Page No: 178] but sometime I am getting data which are in paragraph for those I didn't require any tabular form data representation then How it can be done ? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
Hi, I'm trying to make a LLM that compares items and print output in form of table. For example, the question is "Compare Java and Python" and the output will be:
How can i make the LLM gives table-like answer? Maybe using Custom Output Parser?
Thanks in advance.
System Info
System Information
Package Information
Beta Was this translation helpful? Give feedback.
All reactions