Replies: 1 comment
-
|
A practical example: Support you want output in structured XML And now: fabric --context xml-format 'Why is the sky blue?'Produces this output: <response>
<question>Why is the sky blue?</question>
<answer>
<explanation>The sky appears blue due to a phenomenon called Rayleigh scattering.</explanation>
<details>
<cause>When sunlight enters Earth's atmosphere, it collides with molecules and small particles.</cause>
<effect>Shorter wavelengths of light, such as blue, are scattered more than longer wavelengths like red.</effect>
<result>This scattering causes the sky to appear blue to our eyes during the day.</result>
</details>
</answer>
</response> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Contexts and Sessions in Fabric
Fabric uses contexts and sessions to manage conversation state and reusable prompt data. This guide focuses on how to use them from the CLI and REST API.
What is a Context?
A context is named text that Fabric injects at the beginning of a conversation. Contexts live on disk under
~/.config/fabric/contexts; each file name is the context name, and its contents are included as a system message.Command-line helpers:
--context <name>select a context--listcontextslist available contexts--printcontext <name>show the contents--wipecontext <name>delete itWhat is a Session?
A session tracks the message history of a conversation. When you specify a session name, Fabric loads any existing messages, appends new ones, and saves back to disk. Sessions are stored as JSON under
~/.config/fabric/sessions.Command-line helpers:
--session <name>attach to a session--listsessionslist stored sessions--printsession <name>print a session--wipesession <name>delete itEveryday Use Cases
Contexts and sessions serve different everyday needs:
Example workflow:
~/.config/fabric/contexts/writerwith your writing guidelines.fabric --session mychat).Sessions are automatically created if they don't exist.
How Contexts and Sessions Interact
When Fabric handles a chat request, it loads any named context, combines it with pattern text, and adds the result as a system message before sending the conversation history to the model. The assistant's reply is appended to the session so future calls continue from the same state.
REST API Endpoints
The REST server exposes CRUD endpoints for managing contexts and sessions:
/contexts/:name– get or save a context/contexts/names– list available contexts/sessions/:name– get or save a session/sessions/names– list available sessionsSummary
Contexts provide reusable system-level instructions, while sessions maintain conversation history. Together they allow Fabric to build rich, stateful interactions with language models.
For Developers
Loading Contexts from Disk
Handling Sessions
Building a Session
Beta Was this translation helpful? Give feedback.
All reactions