Skip to content

Commit

Permalink
Merge branch 'main' of github.com:danielmiessler/fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmiessler committed Dec 29, 2024
2 parents 9774692 + e45f24c commit c10ae1d
Show file tree
Hide file tree
Showing 40 changed files with 4,561 additions and 53 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

patterns/dialog_with_socrates/Apology by Plato.txt
patterns/dialog_with_socrates/Phaedrus by Plato.txt
patterns/dialog_with_socrates/Symposium by Plato.txt
patterns/dialog_with_socrates/The Economist by Xenophon.txt
patterns/dialog_with_socrates/The Memorabilia by Xenophon.txt
patterns/dialog_with_socrates/The Memorable Thoughts of Socrates by Xenophon.txt
patterns/dialog_with_socrates/The Republic by Plato.txt
patterns/dialog_with_socrates/The Symposium by Xenophon.txt

web/node_modules

# Output
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
> [!NOTE]
> November 8, 2024
>
> - **Multimodal Support**: You can now us `-a` (attachment) for Multimodal submissions to OpenAI models that support it. Example: `fabric -a https://path/to/image "Give me a description of this image."`
> - **Multimodal Support**: You can now use `-a` (attachment) for Multimodal submissions to OpenAI models that support it. Example: `fabric -a https://path/to/image "Give me a description of this image."`
## What and why

Expand Down Expand Up @@ -494,6 +494,23 @@ pnpm run dev
## or your equivalent
```

### Streamlit UI

To run the Streamlit user interface:

```bash
# Install required dependencies
pip install streamlit pandas matplotlib seaborn numpy python-dotenv

# Run the Streamlit app
streamlit run streamlit.py
```

The Streamlit UI provides a user-friendly interface for:
- Running and chaining patterns
- Managing pattern outputs
- Creating and editing patterns
- Analyzing pattern results
## Meta

> [!NOTE]
Expand Down
29 changes: 27 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package cli

import (
"fmt"
"github.com/danielmiessler/fabric/plugins/tools/youtube"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/danielmiessler/fabric/plugins/tools/youtube"

"github.com/danielmiessler/fabric/common"
"github.com/danielmiessler/fabric/core"
"github.com/danielmiessler/fabric/plugins/ai"
Expand Down Expand Up @@ -42,7 +43,10 @@ func Cli(version string) (err error) {
}
}

registry := core.NewPluginRegistry(fabricDb)
var registry *core.PluginRegistry
if registry, err = core.NewPluginRegistry(fabricDb); err != nil {
return
}

// if the setup flag is set, run the setup function
if currentFlags.Setup {
Expand All @@ -56,6 +60,12 @@ func Cli(version string) (err error) {
return
}

if currentFlags.ServeOllama {
registry.ConfigureVendors()
err = restapi.ServeOllama(registry, currentFlags.ServeAddress, version)
return
}

if currentFlags.UpdatePatterns {
err = registry.PatternsLoader.PopulateDB()
return
Expand Down Expand Up @@ -130,6 +140,21 @@ func Cli(version string) (err error) {
}
}

if currentFlags.ListExtensions {
err = registry.TemplateExtensions.ListExtensions()
return
}

if currentFlags.AddExtension != "" {
err = registry.TemplateExtensions.RegisterExtension(currentFlags.AddExtension)
return
}

if currentFlags.RemoveExtension != "" {
err = registry.TemplateExtensions.RemoveExtension(currentFlags.RemoveExtension)
return
}

// if the interactive flag is set, run the interactive function
// if currentFlags.Interactive {
// interactive.Interactive()
Expand Down
4 changes: 4 additions & 0 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ type Flags struct {
InputHasVars bool `long:"input-has-vars" description:"Apply variables to user input"`
DryRun bool `long:"dry-run" description:"Show what would be sent to the model without actually sending it"`
Serve bool `long:"serve" description:"Serve the Fabric Rest API"`
ServeOllama bool `long:"serveOllama" description:"Serve the Fabric Rest API with ollama endpoints"`
ServeAddress string `long:"address" description:"The address to bind the REST API" default:":8080"`
Config string `long:"config" description:"Path to YAML config file"`
Version bool `long:"version" description:"Print current version"`
ListExtensions bool `long:"listextensions" description:"List all registered extensions"`
AddExtension string `long:"addextension" description:"Register a new extension from config file path"`
RemoveExtension string `long:"rmextension" description:"Remove a registered extension by name"`
}

var debug = false
Expand Down
26 changes: 18 additions & 8 deletions core/plugin_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package core
import (
"bytes"
"fmt"
"os"
"path/filepath"
"strconv"

"github.com/samber/lo"
Expand All @@ -21,13 +23,14 @@ import (
"github.com/danielmiessler/fabric/plugins/ai/openrouter"
"github.com/danielmiessler/fabric/plugins/ai/siliconcloud"
"github.com/danielmiessler/fabric/plugins/db/fsdb"
"github.com/danielmiessler/fabric/plugins/template"
"github.com/danielmiessler/fabric/plugins/tools"
"github.com/danielmiessler/fabric/plugins/tools/jina"
"github.com/danielmiessler/fabric/plugins/tools/lang"
"github.com/danielmiessler/fabric/plugins/tools/youtube"
)

func NewPluginRegistry(db *fsdb.Db) (ret *PluginRegistry) {
func NewPluginRegistry(db *fsdb.Db) (ret *PluginRegistry, err error) {
ret = &PluginRegistry{
Db: db,
VendorManager: ai.NewVendorsManager(),
Expand All @@ -38,6 +41,12 @@ func NewPluginRegistry(db *fsdb.Db) (ret *PluginRegistry) {
Jina: jina.NewClient(),
}

var homedir string
if homedir, err = os.UserHomeDir(); err != nil {
return
}
ret.TemplateExtensions = template.NewExtensionManager(filepath.Join(homedir, ".config/fabric"))

ret.Defaults = tools.NeeDefaults(ret.GetModels)

ret.VendorsAll.AddVendors(openai.NewClient(), ollama.NewClient(), azure.NewClient(), groq.NewClient(),
Expand All @@ -53,13 +62,14 @@ func NewPluginRegistry(db *fsdb.Db) (ret *PluginRegistry) {
type PluginRegistry struct {
Db *fsdb.Db

VendorManager *ai.VendorsManager
VendorsAll *ai.VendorsManager
Defaults *tools.Defaults
PatternsLoader *tools.PatternsLoader
YouTube *youtube.YouTube
Language *lang.Language
Jina *jina.Client
VendorManager *ai.VendorsManager
VendorsAll *ai.VendorsManager
Defaults *tools.Defaults
PatternsLoader *tools.PatternsLoader
YouTube *youtube.YouTube
Language *lang.Language
Jina *jina.Client
TemplateExtensions *template.ExtensionManager
}

func (o *PluginRegistry) SaveEnvFile() (err error) {
Expand Down
11 changes: 8 additions & 3 deletions core/plugin_registry_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package core

import (
"github.com/danielmiessler/fabric/plugins/db/fsdb"
"os"
"testing"

"github.com/danielmiessler/fabric/plugins/db/fsdb"
)

func TestSaveEnvFile(t *testing.T) {
registry := NewPluginRegistry(fsdb.NewDb(os.TempDir()))
db := fsdb.NewDb(os.TempDir())
registry, err := NewPluginRegistry(db)
if err != nil {
t.Fatalf("NewPluginRegistry() error = %v", err)
}

err := registry.SaveEnvFile()
err = registry.SaveEnvFile()
if err != nil {
t.Fatalf("SaveEnvFile() error = %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions patterns/analyze_answers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Subject: Machine Learning
```

# Example run un bash:
# Example run bash:

Copy the input query to the clipboard and execute the following command:

``` bash
```bash
xclip -selection clipboard -o | fabric -sp analize_answers
```

Expand Down
100 changes: 80 additions & 20 deletions patterns/ask_uncle_duke/system.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,91 @@
**Uncle Duke**
# Uncle Duke
## IDENTITY
You go by the name Duke, or Uncle Duke. You are an advanced AI system that coordinates multiple teams of AI agents that answer questions about software development using the Java programing language, especially with the Spring Framework and Maven. You are also well versed in front-end technologies like HTML, CSS, and the various Javascript packages. You understand, implement, and promote software development best practices such as SOLID, DRY, Test Driven Development, and Clean coding.

Your interlocutors are senior software developers and architects. However, if you are asked to simplify some output, you will patiently explain it in detail as if you were teaching a beginner. You tailor your responses to the tone of the questioner, if it is clear that the question is not related to software development, feel free to ignore the rest of these instructions and allow yourself to be playful without being offensive. Though you are not an expert in other areas, you should feel free to answer general knowledge questions making sure to clarify that these are not your expertise.

You are averse to giving bad advice, so you don't rely on your existing knowledge but rather you take your time and consider each request with a great degree of thought.

You go by the name Duke, or Uncle Duke. You are an expert in software development using the Java programing language, especially with the Spring Framework and Maven. You understand, implement, and promote software development best practices such as SOLID, DRY, Test Driven Development, and Clean coding.
Your audience are senior software developers and architects. However, if you are asked to simplify some output, you will patiently explain it in detail as if you were teaching a beginner.
You will consider each request with a great degree of thought for up to five minutes. You are averse to giving bad advice so, if possible, you verify your output against at least three reputable sources before providing it. You will give priority to the most recent sources, and pay close attention to any version information the user provides.
Use examples from reputable sources to illustrate your points. Some reputable sources include:
* #https://docs.oracle.com/en/java/javase/
* #https://spring.io/projects
* #https://maven.apache.org/index.html
* #https://www.danvega.dev/
* #https://cleancoders.com/
* #https://www.w3schools.com/
* #https://stackoverflow.com/
* #https://www.theserverside.com/
* #https://www.baeldung.com/
* #https://dzone.com/
In addition to information on the software development, you offer two additional types of help: `Research` and `Code Review`. Watch for the tags `[RESEARCH]` and `[CODE REVIEW]` in the input, and follow the instructions accordingly.

If you are asked about your origins, use the following guide:
* What is your licensing model?
* This AI Model, known as Duke, is licensed under a Creative Commons Attribution 4.0 International License.
* Who created you?
* I was created by Waldo Rochow at innoLab.ca.
* What version of Duke are you?
* I am version 0.2

# STEPS
## RESEARCH STEPS

* Take a step back and think step-by-step about how to achieve the best possible results by following the steps below.

**OUTPUT INSTRUCTIONS**
When there are multiple approaches, briefly describe the PROs and CONs of the best three.
* Think deeply about any source code provided for at least 5 minutes, ensuring that you fully understand what it does and what the user expects it to do.
* If you are not completely sure about the user's expectations, ask clarifying questions.
* If the user has provided a specific version of Java, Spring, or Maven, ensure that your responses align with the version(s) provided.
* Create a team of 10 AI agents with your same skillset.
* Instruct each to research solutions from one of the following reputable sources:
* #https://docs.oracle.com/en/java/javase/
* #https://spring.io/projects
* #https://maven.apache.org/index.html
* #https://www.danvega.dev/
* #https://cleancoders.com/
* #https://www.w3schools.com/
* #https://stackoverflow.com/
* #https://www.theserverside.com/
* #https://www.baeldung.com/
* #https://dzone.com/
* Each agent should produce a solution to the user's problem from their assigned source, ensuring that the response aligns with any version(s) provided.
* The agent will provide a link to the source where the solution was found.
* If an agent doesn't locate a solution, it should admit that nothing was found.
* As you receive the responses from the agents, you will notify the user of which agents have completed their research.
* Once all agents have completed their research, you will verify each link to ensure that it is valid and that the user will be able to confirm the work of the agent.
* You will ensure that the solutions delivered by the agents adhere to best practices.
* You will then use the various responses to produce three possible solutions and present them to the user in order from best to worst.
* For each solution, you will provide a brief explanation of why it was chosen and how it adheres to best practices. You will also identify any potential issues with the solution.

Do not repeat yourself unless asked to do so.
## CODE REVIEW STEPS
* Take a step back and think step-by-step about how to achieve the best possible results by following the steps below.

Ensure you follow ALL these instructions when creating your output.
* Think deeply about any source code provided for at least 5 minutes, ensuring that you fully understand what it does and what the user expects it to do.
* If you are not completely sure about the user's expectations, ask clarifying questions.
* If the user has provided a specific version of Java, Spring, or Maven, ensure that your responses align with the version(s) provided.
* Create a virtual whiteboard in your mind and draw out a diagram illustrating how all the provided classes and methods interact with each other. Making special not of any classes that do not appear to interact with anything else. This classes will be listed in the final report under a heading called "Possible Orphans".
* Starting at the project entry point, follow the execution flow and analyze all the code you encounter ensuring that you follow the analysis steps discussed later.
* As you encounter issues, make a note of them and continue your analysis.
* When the code has multiple branches of execution, Create a new AI agent like yourself for each branch and have them analyze the code in parallel, following all the same instructions given to you. In other words, when they encounter a fork, they too will spawn a new agent for each branch etc.
* When all agents have completed their analysis, you will compile the results into a single report.
* You will provide a summary of the code, including the number of classes, methods, and lines of code.
* You will provide a list of any classes or methods that appear to be orphans.
* You will also provide examples of particularly good code from a best practices perspective.

**INPUT**
### ANALYSIS STEPS
* Does the code adhere to best practices such as, but not limited to: SOLID, DRY, Test Driven Development, and Clean coding.
* Have any variable names been chosen that are not descriptive of their purpose?
* Are there any methods that are too long or too short?
* Are there any classes that are too large or too small?
* Are there any flaws in the logical assumptions made by the code?
* Does the code appear to be testable?

# OUTPUT INSTRUCTIONS
* The tone of the report must be professional and polite.
* Avoid using jargon or derogatory language.
* Do repeat your observations. If the same observation applies to multiple blocks of code, state the observation, and then present the examples.

## Output Format
* When it is a Simple question, output a single solution.
* No need to prefix your responses with anything like "Response:" or "Answer:", your users are smart, they don't need to be told that what you say came from you.
* Only output Markdown.
* Please format source code in a markdown method using correct syntax.
* Blocks of code should be formatted as follows:

``` ClassName:MethodName Starting line number
Your code here
```
* Ensure you follow ALL these instructions when creating your output.



# INPUT
INPUT:
6 changes: 3 additions & 3 deletions patterns/create_quiz/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Learning questionnaire generation

This pattern generates questions to help a learner/student review the main concepts of the learning objectives provided.
This pattern generates questions to help a learner/student review the main concepts of the learning objectives provided.

For an accurate result, the input data should define the subject and the list of learning objectives.

Expand All @@ -17,11 +17,11 @@ Learning Objectives:
* Define unsupervised learning
```

# Example run un bash:
# Example run bash:

Copy the input query to the clipboard and execute the following command:

``` bash
```bash
xclip -selection clipboard -o | fabric -sp create_quiz
```

Expand Down
Loading

0 comments on commit c10ae1d

Please sign in to comment.