-
Notifications
You must be signed in to change notification settings - Fork 1
Resources
While you can certainly use MCP servers and functions to access resources, Frags provides a more convenient way to load resources that are already available for the plan to use, and that is resources.
Resources can be text files (plain text, csv, json...) or binary files (pdf).
As a default, a resource is simply loaded into the LLM context (in: ai). In this way the LLM will be capable of using
the resource and answer questions about it.
By declaring its route as in: vars text files can be used by the plan as a variable. This allows to use a resource
to control the behavior of plan. When routed to vars, its content will be available to expressions, such as:
iterateOn: vars.my_resource or to templates, as in: {{ .vars.my_resource }}.
Important: if routed to vars, the attribute var with the variable name is required.
Resources can be transformed using transformers. Depending on the routing, this could lead to a modified resource to be available in the LLM context, or even make a resource in session vars into a structured object.
A resource loader is assigned to a Runner, and the plan is almost entirely oblivious of how the files are loaded. From the plan point of view, all resource loaders have the same interface.
It's the default resource loader in the CLI, and allows you to access the local file system.
BEWARE Security concern: do not use this resource loader in internet accessible or shared applications! This resource loader will load any file described in a plan.
This resource loader, to be used mostly in integrations scenarios, allows the plan to load a file that has already been loaded into memory by the integration layer.
Is an aggregation loader in which a plan can define which sub-loader to use using the loader parameter.
The CLI uses the FileResourceLoader by default. To load a resource into the LLM context, use the resources block,
as in:
sessions:
basic_extraction:
prompt: extract the patient details details from the attached discharge note
resources:
- identifier: discharge.pdfIf we want to route a text file to the session vars, you can:
sessions:
basic_extraction:
prompt: What is the patient name in {{ .vars.patient }}
resources:
- identifier: data.txt
in: vars
var: patientTo instantiate a runner with a given resource loader:
runner := frags.NewRunner[frags.ProgMap](sm, frags.NewFileResourceLoader(dir), ai)and in the session, reference the resource loader by:
session.Resources = []frags.Resource{
{
Identifier: "patient.pdf",
},
}To implement your own resource loader, implement the
frags.ResourceLoader interface.
The nature of the usable resources depends on the LLM implementation.
- Gemini supports most type of document files
- ChatGPT supports PDF and most text files
- Ollama currently supports only text files