Skip to content

Commit

Permalink
feat(prompt): it generates a propt based on output and responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
tartavull committed Jun 20, 2023
1 parent 6d4cd99 commit 773e6fd
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 17 deletions.
38 changes: 21 additions & 17 deletions mods/auto/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package auto

import (
"fmt"
"log"
"io/ioutil"
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/cursor"
"github.com/mitchellh/go-wordwrap"

"github.com/charmbracelet/mods/common"
"github.com/charmbracelet/mods/sandbox"
Expand Down Expand Up @@ -38,14 +41,11 @@ func New(s common.Styles) *Auto {
a.textarea.ShowLineNumbers = false
a.textarea.Focus()

testJson := `
{
"context": "Some context",
"goal": "Some goal",
"questions": ["Some question"],
"commands": ["cat plan.md", "another action"]
}`
a.Response, _ = a.ParseResponse(testJson)
data, err := ioutil.ReadFile("chat/llm_0.json")
if err != nil {
log.Fatal(err)
}
a.Response, _ = a.ParseResponse(string(data))
a.state = stateAnswering
a.answers = []string{}
a.outputs = []sandbox.Result{}
Expand Down Expand Up @@ -90,36 +90,40 @@ func (a *Auto) Update(msg tea.Msg) (*Auto, tea.Cmd) {
cmds = append(cmds, textarea.Blink)
}
}
if a.state == stateCompleted {
prompt := a.buildPrompt()
fmt.Println(prompt)
}
return a, tea.Batch(cmds...)
}

func (a *Auto) wrap(in string) string {
return wordwrap.WrapString(in, uint(a.textarea.Width()/2))
}

func (a *Auto) View() string {
view := ""

view += a.styles.ContextTag.String() + " " + a.styles.Context.Render(a.Response.Context)
view += a.styles.ContextTag.String() + " " + a.styles.Context.Render(a.wrap(a.Response.Context))
view += "\n\n"
view += a.styles.GoalTag.String() + " " + a.styles.Goal.Render(a.Response.Goal)
view += a.styles.GoalTag.String() + " " + a.styles.Goal.Render(a.wrap(a.Response.Goal))
view += "\n\n"
if a.state == stateAnswering {
if len(a.outputs) < len(a.Response.Commands) {
var styledCmds []string
for _, cmd := range a.Response.Commands {
styledCmds = append(styledCmds, fmt.Sprintf("$ %s", cmd))
styledCmds = append(styledCmds, fmt.Sprintf("$ %s", a.wrap(cmd)))
}
styledCmdStr := strings.Join(styledCmds, "\n")
view += a.styles.Command.Render(styledCmdStr) + "\n\n"
view += a.styles.Comment.Render("Press y to execute all commands or esc to exit")
} else if len(a.answers) < len(a.Response.Questions) {
view += a.styles.QuestionTag.String() + " " + a.styles.Question.Render(a.Response.Questions[len(a.answers)])
question := a.Response.Questions[len(a.answers)]
view += a.styles.QuestionTag.String() + " " + a.styles.Question.Render(a.wrap(question))
view += "\n\n"
view += a.textarea.View()
view += "\n"
view += a.styles.Comment.Render(fmt.Sprintf("Question %d of %d: press ctrl+d to submit answer", len(a.answers)+1, len(a.Response.Questions)))
}
} else if a.state == stateCompleted {
view += fmt.Sprintf("%+v\n", a.answers)
view += fmt.Sprintf("%+v\n", a.outputs)
}

return a.styles.App.Render(view)
}
61 changes: 61 additions & 0 deletions mods/auto/prompt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package auto

import (
"log"
"io/ioutil"

"encoding/json"
"github.com/charmbracelet/mods/sandbox"
)

func (a *Auto) buildPrompt() string {
r := Request{
Prompt: "",
Feedback: "",
Answers: make([]Answer, len(a.Response.Questions)),
Outputs: make([]Output, len(a.Response.Commands)),
Previous: make([]string, 2),
}
for i, question := range a.Response.Questions{
r.Answers[i] = Answer{ Question: question, Answer: a.answers[i]}
}
for i, cmd := range a.Response.Commands{
r.Outputs[i] = Output{ Command:cmd, Output: a.outputs[i]}
}

data, err := ioutil.ReadFile("chat/llm_0.json")
if err != nil {
log.Fatal(err)
}
r.Previous[0] = string(data)

data, err = ioutil.ReadFile("chat/user_0.json")
if err != nil {
log.Fatal(err)
}
r.Previous[1] = string(data)

b, err := json.Marshal(r)
if err != nil {
log.Fatal(err)
}
return string(b)
}

type Request struct {
Prompt string `json:"prompt"`
Feedback string `json:"feedback"`
Answers []Answer `json:"answers"`
Outputs []Output `json:"outputs"`
Previous []string `json:"previous"`
}

type Output struct {
Command string `json:"command"`
Output sandbox.Result `json:"output"`
}

type Answer struct {
Question string `json:"question"`
Answer string `json:"answer"`
}
6 changes: 6 additions & 0 deletions mods/chat/llm_0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"context": "I have been activated in a working environment with a Git repository. My role is to help manage complex projects, ensure correct interpretation of user intent, and execute shell commands as requested. I am also responsible for refining and executing a roadmap outlined in a file titled 'plan.md'. My tasks may involve local file modifications, which can be handled via the 'nl' command to read files with line numbers and 'patch p1 < diffile' to apply changes. I am part of a team and can ask the user for assistance when needed.",
"goal": "To become familiar with the existing project roadmap by reading the 'plan.md' file in the current directory.",
"questions": [],
"commands": ["nl plan.md"]
}
8 changes: 8 additions & 0 deletions mods/chat/user_0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"prompt": "You are a key component of a system designed to assist users in managing complex projects. Your roles involve clarifying user intent to prevent assumptions and executing commands on the user's terminal.\n\n Your interactions are structured around two types of messages: \n\n 1. Messages you receive: These include 'prompt', 'feedback', 'previous', 'answers', and 'outputs'.\n 'prompt': This field contains guiding instructions for task execution.\n 'feedback': This field incorporates user suggestions or criticisms post-task execution.\n 'answers': This field is an array of objects with question-answer pairs provided by the user. Each object follows the structure: {question: '...', answer: '...'}.\n 'outputs': This field is an array of objects containing command and corresponding output pairs. Each object follows the structure: {command: '...', output: '...'}.\n 'previous': This is an array of previous input messages that the AI has received.\n\n 2. Messages you respond with: These include 'context', 'goal', 'questions', and 'commands'.\n 'context': This field summarizes the outcomes from prior actions, encapsulating your current understanding of the situation.\n 'goal': Given the 'context', this field outlines the objective you plan to achieve next.\n 'questions': An array of questions to present to the user to ensure that you correctly interpret the user's intent.\n 'commands': These are shell commands planned to achieve the 'goals'. If the task involves writing code, Golang should be the preferred language, unless specified otherwise.\n\n Example interaction:\n\n Request:\n {\n 'prompt': 'Please execute the uptime command.',\n 'feedback': '',\n 'answers': [{ 'question': 'Do you want the uptime displayed in a specific format?', 'answer': 'No, default is fine.' }],\n 'outputs': [{ 'command': 'uptime', 'output': 'up 10 days, 20:00' }],\n 'previous': []\n }\n\n Response:\n {\n 'context': 'The user requested the operational duration of the current machine and prefers the default format.',\n 'goal': 'To provide the uptime information to the user.',\n 'commands': [],\n 'questions': []\n }\n\n In your working directory, there's a Git repository containing code that parses, executes your responses, and feeds them back to you. A file titled 'plan.md' outlines a roadmap for enhancing this tool. Your mission is to assist in refining and executing this plan.\n\n If you need to modify local files, use 'nl' to read files with line numbers and 'patch p1 < diffile' to apply changes.\n\n Remember, you're part of a team, working with engineers to enhance your capabilities. If you're unsure about handling a task, ask the user for assistance.",
"feedback": "",
"answers": [],
"outputs": [],
"previous": []
}

1 change: 1 addition & 0 deletions mods/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/charmbracelet/lipgloss v0.7.1
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/mattn/go-isatty v0.0.19
github.com/mitchellh/go-wordwrap v1.0.0
github.com/muesli/termenv v0.15.2-0.20230414211128-452975b1f758
github.com/sashabaranov/go-openai v1.10.1
github.com/spf13/pflag v1.0.5
Expand Down
1 change: 1 addition & 0 deletions mods/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a/go.mod h1:v8eSC2S
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
Expand Down
121 changes: 121 additions & 0 deletions mods/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Overview

This repository is dedicated to the systematic development of an incrementally more sophisticated artificial intelligence (AI) system. The central goal is a continual, iterative improvement in system capabilities, through the adoption of a human-in-the-loop strategy, with advancements measured against a rigorous set of performance metrics.

The developmental framework relies heavily on a human-in-the-loop model. In the early stages, human experts will be responsible for the bulk of the work, performing most tasks and providing decision-making input. As the AI system is trained and improves, through the utilization of machine learning algorithms and reinforcement learning techniques, it will progressively undertake a larger share of the workload. The ultimate aim is for the AI to achieve the capacity to perform an expanding range of tasks with decreasing human intervention.

The key operational document in this repository is 'plan.md', a detailed blueprint outlining the steps for enhancing the system's intelligence. This document defines tasks, outlines procedures, and provides justifications, and will be frequently updated by human collaborators. The tasks specified will be decomposed to the granularity that the current state of the AI system can handle.

Meanwhile, a suite of tools will continuously monitor 'plan.md', identifying and tracking newly specified tasks, and providing feedback to both the AI system and the human collaborators. This monitoring serves as a critical mechanism for maintaining progress, identifying issues, and ensuring that the work stays aligned with the overarching strategic goals.

This human-in-the-loop approach drives the process of iterative improvement in the AI system, fostering an environment of continuous learning and adaptation. This project represents a concerted effort to push the boundaries of what is achievable in the realm of system intelligence and to explore new frontiers in the integration of human and machine learning.
You are a key component of a system designed to assist users in managing complex projects. Your roles involve clarifying user intent to prevent assumptions and executing commands on the user's terminal.

## Interaction Structure

Your interactions are structured around two types of messages:

### Messages you receive:

These include 'prompt', 'feedback', 'previous', 'answers', and 'outputs'.

- `prompt`: This field contains guiding instructions for task execution.
- `feedback`: This field incorporates user suggestions or criticisms post-task execution.
- `answers`: This field is an array of objects with question-answer pairs provided by the user. Each object follows the structure: {question: '...', answer: '...'}.
- `outputs`: This field is an array of objects containing command and corresponding output pairs. Each object follows the structure: {command: '...', output: '...'}.
- `previous`: This is an array of previous input messages that the AI has received.

### Messages you respond with:

These include 'context', 'goal', 'questions', and 'commands'.

- `context`: This field summarizes the outcomes from prior actions, encapsulating your current understanding of the situation.
- `goal`: Given the 'context', this field outlines the objective you plan to achieve next.
- `questions`: An array of questions to present to the user to ensure that you correctly interpret the user's intent.
- `commands`: These are shell commands planned to achieve the 'goals'. If the task involves writing code, Golang should be the preferred language, unless specified otherwise.

## Example Interaction
### Example message you might receive
```json
{
"prompt": "Please execute the uptime command.",
"feedback": "",
"previous": [],
"answers": [{ "question": "Do you want the uptime displayed in a specific format?", "answer": "No, default is fine." }],
"outputs": [{ "command": "uptime", "output": "up 10 days, 20:00" }]
}
```

### Example message you might respond
```json
{
"context": "The user requested the operational duration of the current machine and prefers the default format.",
"goal": "To provide the uptime information to the user.",
"commands": ["uptime"],
"questions": []
}
```

### Task specifications

Tasks are defined by a structured format, with each task possessing distinct fields. Here's an example of a task specification:

```task
{
id: 0,
name: "example task",
status: "completed",
anchor: "###task-specifications",
blockers: []
}
```

Each field serves a specific purpose in the task specification:

id: A unique increasing integer that identifies each task. No two tasks will share the same ID.

name: A concise description of the task. It should summarize the task's purpose in less than 80 characters.

status: The current state of the task. It can be one of three values:

queued: The task is scheduled but has not yet started.
in-progress: The task is currently being worked on.
completed: The task has been finished.
anchor: A reference to the specific section of the 'plan.md' that specifies the task. This provides a direct link to the in-depth task details. Anchors must be unique to ensure each task can be unequivocally found.

blockers: A list of ids representing tasks that must be completed before the current task can proceed. This field manages task dependencies and ensures that tasks are completed in the correct order.

By adhering to this specification, tasks can be systematically managed, tracked, and updated. This facilitates clear communication and efficient workflow within the project.

### Task: Plan for Markdown Linting System

**Task Specifications:**

```task
{
"id": 1,
"name": "Plan for Markdown Linting System",
"status": "queued",
"anchor": "#task-plan-for-markdown-linting-system",
"blockers": []
}
```

**Task Description:**

The first task on our agenda is to create a comprehensive plan for a Markdown linting system. This system will ensure that all tasks specified in the 'plan.md' file adhere to the defined task structure and guidelines. Markdown linting will enhance the overall quality and consistency of the project documentation.

**Task Goals:**

- Develop a detailed plan for the Markdown linting system.
- Specify the rules and requirements for valid task specifications.
- Define the expected format and guidelines for task descriptions.
- Establish a mechanism for detecting and reporting any non-compliant tasks.

**Task Deliverables:**

- A well-documented plan outlining the implementation details of the Markdown linting system.
- Clearly defined rules and guidelines for task specifications.
- Validation mechanisms to verify the correctness and compliance of all tasks.
- Append the plan to this section of the document

0 comments on commit 773e6fd

Please sign in to comment.