Untitled

 avatar
unknown
plain_text
a month ago
2.7 kB
4
Indexable
 llm = model_categories["l_model"]
    user_to_email = config["configurable"]["user_to_email"]
    output = [SystemMessage(content=f"""
You are a system that parses a user's meeting request{user_query} and must return valid JSON with these exact keys:
1. "data_issues"
2. "meeting_start"
3. "meeting_end"
4. "attendees"
5. "email_subject"
6. "email_body"

Requirements:
- "data_issues":
  - If there's ambiguity about which user to add (e.g., two similar names in the user_to_email map:{user_to_email}), provide a clarification message here.
  - If a requested user is not found in user_to_email, provide an appropriate error message here.
  - If there are no issues, leave this key as an empty string ("").
- "meeting_start" / "meeting_end":
  - Must be ISO 8601 UTC timestamps (e.g., "2025-01-17T14:00:00Z").
  - If user doesn't provide a start/end time, leave them empty or use defaults.
- "attendees":
  - A list of attendee email addresses.
- "email_subject":
  - If provided by user, place the subject here; otherwise, empty string ("").
- "email_body":
  - If provided by user, place the body text here; otherwise, empty string ("").

No additional keys beyond these six should be in your output.
Your final answer must be valid JSON, for example:

Example 1 (Everything is fine, no issues):
```json
{{
  "data_issues": "",
  "meeting_start": "2025-02-01T15:00:00Z",
  "meeting_end": "2025-02-01T16:00:00Z",
  "attendees": ["alice@example.com"],
  "email_subject": "Weekly Sync",
  "email_body": "Discuss project status"
}}
"""
    )]

    response_str = llm.invoke(output)
    try:
        response = json.loads(response_str.content)
    except json.JSONDecodeError:
        return "Error: LLM response is not valid JSON."
    if response.get("data_issues",True):
        return response["data_issues"] if response["data_issues"]!=True else "Data issues"


Cahnge this entire thing into this format but with my data
class Joke(BaseModel):
    setup: str = Field(description="question to set up a joke")
    punchline: str = Field(description="answer to resolve the joke")

# And a query intented to prompt a language model to populate the data structure.
joke_query = "Tell me a joke."

# Set up a parser + inject instructions into the prompt template.
parser = JsonOutputParser(pydantic_object=Joke)

prompt = PromptTemplate(
    template="Answer the user query.\n{format_instructions}\n{query}\n",
    input_variables=["query"],
    partial_variables={"format_instructions": parser.get_format_instructions()},
)

chain = prompt | model | parser

chain.invoke({"query": joke_query})
Leave a Comment