Build powerful AI chains with intuitive composition patterns
Build powerful AI chains with intuitive composition patterns.The UEL (Upsonic Expression Language) provides a declarative way to compose AI components into sophisticated chains. Without UEL, building complex AI workflows requires verbose code with manual data passing and error handling. With UEL, you can:
UEL can be used with minimal configuration or with extensive customization to suit your specific needs. The system provides a robust foundation for AI-powered applications with built-in support for various advanced features.
from upsonic.uel import ChatPromptTemplate, StrOutputParserfrom upsonic.models import infer_model# Create a simple chain with output parserchain = ( ChatPromptTemplate.from_template("Tell me about {topic}") | infer_model("anthropic/claude-sonnet-4-5") | StrOutputParser())# Execute the chainresult = chain.invoke({"topic": "quantum computing"})print(result)
When using infer_model() without specifying a model, it defaults to "openai/gpt-4o". Make sure you have the appropriate API key set in your environment.
from upsonic.uel import ChatPromptTemplate, StrOutputParserfrom upsonic.models import infer_model# Create model with memorymodel = infer_model("anthropic/claude-sonnet-4-5").add_memory(history=True)# Create chain with conversation history and output parserchain = ( ChatPromptTemplate.from_messages([ ("system", "You are a helpful assistant."), ("placeholder", {"variable_name": "chat_history"}), ("human", "{input}") ]) | model | StrOutputParser())# First interactionresponse1 = chain.invoke({ "input": "My name is Alice", "chat_history": []})print(response1)# Second interaction - model remembers contextresponse2 = chain.invoke({ "input": "What's my name?", "chat_history": [ ("human", "My name is Alice"), ("ai", response1) ]})print(response2) # Output: Your name is Alice