Help me, translating this into a JSON schema so I can change this code into JSON Schema…
- User
Help me, translating this into a JSON schema so I can change this code into JSON Schema
from pydantic import BaseModel, Field from langchain_core.prompts import ChatPromptTemplate from langchain_openai import ChatOpenAI
Data model
class code(BaseModel): """Schema for code solutions to questions about LCEL."""
prefix: str = Field(description="Description of the problem and approach") imports: str = Field(description="Code block import statements") code: str = Field(description="Code block not including import statements")llm = ChatOpenAI(temperature=0, model=expt_llm) llm.with_structured_output(code) // change this to use the JSON schema
Here is an example:
json_schema = { "title": "joke", "description": "Joke to tell user.", "type": "object", "properties": { "setup": { "type": "string", "description": "The setup of the joke", }, "punchline": { "type": "string", "description": "The punchline to the joke", }, "rating": { "type": "integer", "description": "How funny the joke is, from 1 to 10", "default": None, }, }, "required": ["setup", "punchline"], } structured_llm = llm.with_structured_output(json_schema)
- Assistant
To create a JSON schema that corresponds to the provided Pydantic model
code, you'll need to define the properties along with their types and descriptions in JSON schema format.Here’s how you can represent the
codemodel in JSON schema:json_schema = { "title": "Code Solution", "description": "Schema for code solutions to questions about LCEL.", "type": "object", "properties": { "prefix": { "type": "string", "description": "Description of the problem and approach", }, "imports": { "type": "string", "description": "Code block import statements", }, "code": { "type": "string", "description": "Code block not including import statements", }, }, "required": ["prefix", "imports", "code"], } # Now you can change the code to use this JSON schema structured_llm = llm.with_structured_output(json_schema)