0.0.5 • Published 1 year ago

opensage v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

OpenSage

OpenSage is a general purpose knowledge base that is powered by OpenAI's ChatGPT API.

This project draws inspiration from:

Installation

You can install OpenSage using npm:

$ npm install -g opensage

Additionally, the OPENAI_API_KEY environment variable must be exported, perhaps within the confines of a ~/.bashrc file:

export OPENAI_API_KEY="<your key here>"

Examples

Example 1

$ osage --role "digital graphics/color expert" \
           "Suggest a 5-color pallete that goes with `#ab0091`. Explain Why the colors make sense."

㋡ I am assuming the role of digital graphics/color expert and will try to answer your question.
㋡ You asked: Suggest a 5-color pallete that goes with #ab0091. Explain Why the colors make sense.
㋡ OpenSage thinks the answer is:

Here's a 5-color palette suggestion that goes well with #ab0091:

    1. #ffffff - This is a clean and crisp white that provides a nice contrast to the bold and intense #ab0091 shade.
    2. #fa8072 - This is a warm and vibrant coral color that compliments the pinkish shades in #ab0091.
    3. #00bfff - This is a cool and soothing blue-green color that helps to offset the intensity of the #ab0091 shade.
    4. #f5f5f5 - This is a soft and neutral gray that can help to balance out the other bold colors in the palette.
    5. #ffbf00 - This is a bright and cheerful yellow-orange color that adds a pop of fun and energy to the palette.

These colors make sense together as they create a harmonious balance between warm and cool colors, 
and also provide a good mix of light and dark shades to create contrast and interest in any design. 
The white and gray provide a good neutral base for the other colors to stand out, while the coral and 
yellow-orange add vibrancy and warmth, and the blue-green adds a calming touch. 

Overall, this palette is cohesive and eye-catching while also being versatile and flexible 
for a variety of design needs.

Example 2

$ osage --role "Scala 3, data structures, and algorithms expert" \
           "Implement Dijkstra's algorithm in Scala 3."

㋡ I am assuming the role of Scala 3, data structures, and algorithms expert and will try to answer your question.
㋡ You asked: Implement Dijkstra's algorithm in Scala 3.
㋡ OpenSage thinks the answer is:

Sure, here is an implementation of Dijkstra's shortest path algorithm in Scala 3:

    import scala.collection.mutable.PriorityQueue
    
    class Graph(val adjacencyList: Map[Int, List[(Int, Int)]]) {
      def shortestPath(start: Int, end: Int): Option[List[Int]] = {
        val distances = Array.fill(adjacencyList.size + 1)(Int.MaxValue)
        val pq = PriorityQueue[(Int, Int)](start -> 0)(Ordering.by((_: (Int, Int))._2).reverse)
        val previous = Array.fill(adjacencyList.size + 1)(-1)
        distances(start) = 0
    
        def dijkstra(): Unit = {
          while (pq.nonEmpty) {
            val (node, distance) = pq.dequeue()
            if (node == end) {
              return
            }
            if (distance <= distances(node)) {
              for ((neighbor, weight) <- adjacencyList.getOrElse(node, List.empty)) {
                val newDist = distances(node) + weight
                if (newDist < distances(neighbor)) {
                  pq.enqueue(neighbor -> newDist)
                  distances(neighbor) = newDist
                  previous(neighbor) = node
                }
              }
            }
          }
        }
    
        dijkstra()
    
        if (previous(end) == -1) {
          None
        } else {
          val path = Seq.iterate(end)(previous(_)).takeWhile(_ != -1).reverse.toList
          Some(path)
        }
      }
    }

Here is an example of how to use it:

    val adjacencyList = Map(
      1 -> List((2, 7), (3, 9), (6, 14)),
      2 -> List((1, 7), (3, 10), (4, 15)),
      3 -> List((1, 9), (2, 10), (4, 11), (6, 2)),
      4 -> List((2, 15), (3, 11), (5, 6)),
      5 -> List((4, 6), (6, 9)),
      6 -> List((1, 14), (3, 2), (5, 9))
    )
    
    val graph = new Graph(adjacencyList)
    val path = graph.shortestPath(1, 5)
    println(path) // Some(List(1, 3, 6, 5))

In this example, we create a Graph object with an adjacency list representing the edges and weights of a 
directed graph. We then call the shortestPath method on this object with a start node of 1 and an end 
node of 5. 

The method returns an optional list of node ids representing the shortest path from the start to the end node, 
which in this case is Some(List(1, 3, 6, 5)). If no path exists between the start and the end node, it returns None.

Example 3

$ osage --role "BeOS programming expert" \
           "Write a BeOS application that displays a window with a button that says 'Hello World'."


㋡ I am assuming the role of BeOS programming expert and will try to answer your question.
㋡ You asked: Write a BeOS application that displays a window with a button that says 'Hello World'.
㋡ OpenSage thinks the answer is:

Here is a sample code in C++ that creates a BeOS window and displays a "Hello World" button:

    #include <Application.h>
    #include <Button.h>
    #include <Window.h>
    #include <View.h>
    
    class HelloWorldWindow : public BWindow {
    public:
        HelloWorldWindow(BRect frame)
            : BWindow(frame, "Hello World", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
        {
            BButton* button = new BButton(BRect(25, 25, 125, 50), "helloButton", "Hello World", new BMessage('HWBT'));
            button->MakeDefault(true);
            AddChild(button);
        }
    };
    
    class HelloWorldApp : public BApplication {
    public:
        HelloWorldApp()
            : BApplication("application/x-vnd.helloworld")
        {
        }
    
        void ReadyToRun()
        {
            BRect frame(50, 50, 200, 100);
            HelloWorldWindow* window = new HelloWorldWindow(frame);
            window->Show();
        }
    };
    
    int main()
    {
        HelloWorldApp app;
        app.Run();
        return 0;
    }

In this code, we first include the necessary BeOS header files for creating windows, buttons, 
and views.

We create a new BWindow subclass called HelloWorldWindow, which has a constructor that takes 
a BRect object for the window's frame. We pass the frame, window title, window type (B_TITLED_WINDOW), 
and quit flag (B_QUIT_ON_WINDOW_CLOSE) to the BWindow constructor. 

We then create a BButton object with a specified frame, label, message, and add it as a child of the window.

We then create a BApplication subclass called HelloWorldApp with an empty constructor. 
In the ReadyToRun method, we create a new HelloWorldWindow object with a specific frame and call its Show 
method to display it on the screen.

Finally, we create a main function that creates an instance of the HelloWorldApp class and calls 
the Run method to start the BeOS application.

When you compile and run this code, you should see a window with a "Hello World" button that 
exits the application when clicked.

Example 4

$ osage --role "writing style transfer expert" \
           "Transfer the style of the following quote to Shakespeare's writing style: > There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult."

㋡ I am assuming the role of writing style transfer expert and will try to answer your question.
㋡ You asked: Transfer the style of the following quote to Shakespeare's writing style: > There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.
㋡ OpenSage thinks the answer is:

Verily, in the art of creating of a software design, there be two paths to take: 
one, to make it so simple that no faults can be seen, and t'other, to make it so 
complicated that fault remains hidden. The former way is a far more arduous task.

Example 5

$ osage "Write a poem inspired by the B+ Trees, in the style of Edgar Allan Poe"

㋡ I am assuming the role of a helpful assistant and will try to answer your question.
㋡ You asked: Write a poem inspired by the B+ Trees, in the style of Edgar Allan Poe
㋡ OpenSage thinks the answer is:

In a forest of nodes, where pointers doth grow
And branches spread wide like a twisted tableau
There lies a tree with a name quite unique
Its leaves marked with keys, so perfectly sleek

The B+ tree they call it, a marvel of sorts
With nodes so mature, their pointers are taut
And when it is time to find a key in the fray
It quickly retrieves it, without any delay

But beware the depths, where shadows do dwell
And leaves do wither, in a silent farewell
For there lies the tomb, of nodes long forgot
Where keys do gather, in a tangled knot

And in these dark depths, a monster doth wait
With branches like claws, and leaves full of hate
It wraps round the tree, like a serpentine coil
And sucks it dry, of its life and its spoil

So venture forth, with care in your heart
And avoid the depths, lest you meet your depart
For the B+ tree is a delicate breed
And the monster below, is all but decreed.

Dedications

This project is dedicated to the memories of SA and BF.

License

This software artifact is licensed under the MIT License.

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago