Skip to content

Commit

Permalink
Added subcommand summarize to generate a draft bragging documents usi…
Browse files Browse the repository at this point in the history
…nd large language models
  • Loading branch information
bovem committed Jan 16, 2024
1 parent b12a375 commit 716b583
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 37 deletions.
38 changes: 38 additions & 0 deletions cmd/summarize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"github.com/bovem/brag/utils"
"github.com/spf13/cobra"
"strings"
)

var model string
var prompt string

var summarizeCmd = &cobra.Command{
Use: "summarize",
Short: "Summarizes the brags from the specified time period in a draft bragging document.",
Long: `Summarizes brags from the specified time period using Large Language Models hosted on Ollama (https://ollama.ai/)
and generates a draft bragging document.
Requires following environment variable (assuming Ollama is already deployed and the model is downloaded).
$ export OLLAMA_URL="http://localhost:11434"
For Example:
brag summarize --model llama2:latest last-month
brag summarize --model llama2:latest 2-weeks
The time period has to be specified in any of the following formats
* <numeric-time>-<range-of-days> (brag about 2-months/brag about 3-years)
* today/yesterday/last-week/last-month (brag about last-week/brag about yesterday)
`,
Run: func(cmd *cobra.Command, args []string) {
utils.Summarize(strings.Join(args, " "), model, prompt)
},
}

func init() {
rootCmd.AddCommand(summarizeCmd)
summarizeCmd.PersistentFlags().StringVarP(&model, "model", "m", "llama2:latest", "LLM Model to be used while generating the bragging document")
summarizeCmd.PersistentFlags().StringVarP(&prompt, "prompt", "p", utils.BragDocTemplate, "LLM Prompt for generating the bragging document")
}
47 changes: 10 additions & 37 deletions utils/bragDocument.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,23 @@ The document should be written in a formal tone as it has to be shared
with my manager and stakeholders and it impacts my personal growth.
Omit the fields you think don't have enough information in journals.
The document should be in the following format:
The document should be in the following format, the project names and content
mentioned in following format is just an example don't use it in the final output
Use the pointers provided in the format below and omit them in the final output:
# Work Accomplishments
Insert the list of personal work done in great detail, mentioning important
hyperlinks like Jira tickets, pull request links, and other relevant document links
. It should be grouped by projects like the following
## AIS Maritime Traffic Dashboard
### Completed
* Created a scraper to fetch the data for current maritime traffic.
* Integrated PostgresDB to store the daily data for maritime traffic.
* Created a GraphQL API to access the data from different services.
### In progress
* Working on a Grafana Dashboard to visualize the maritime traffic.
### Todos
* Exploring methodologies to improve scraping performance.
## Work Project 2
### Completed
* Completed tasks
### In progress
* In Progress tasks
### Todos
* Task not started yet but planning to be
. It should be grouped by projects.
Emphasize the following points
* If I designed or built something from scratch
* Useful insights during the design or coding process
* Impact of individual projects
* Using numbers to show impact like reduced response time by X%, decreased cloud costs by X%\
* Using numbers to show impact like reduced response time by X%, decreased cloud costs by X%.
# Collaboration and Mentorship
Write about collaboration and mentorship work done by me in bullet points like the following:
* Helped intern with a task he was stuck on
* Worked with multiple teams to resolve a crucial production bug.
Write about collaboration and mentorship work done by me in bullet points.
Emphasize the following points
* Write about each point in great detail supporting it with hyperlinks when necessary
Expand All @@ -57,14 +35,7 @@ Emphasize the following points
* Giving talks or conducting workshops and hackathons internally
# Design and Documentation
Write about design and documentation efforts done in the following format
## Project 1
* Designed API services for Project 1
## Project 2
* Improved documentation for Project 2 by adding information for new features.
* Added a FAQ section for Project 2 with the questions frequently asked by our partners and customers.
Write about design and documentation efforts.
# Company Building
Write in bullet points about the interviewing and recruiting process contributions from my side.
Expand All @@ -81,4 +52,6 @@ the work. Also, write about
* Talks and event participation
* Contributing to OpenSource projects
* Recognition from any other part of the industry. Like awards.
Additional information about personal projects and blogs will be mentioned after the journal.
`
78 changes: 78 additions & 0 deletions utils/bragSummarize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package utils

import (
"fmt"
"net/http"
"io/ioutil"
"bytes"
"encoding/json"
)

type ModelResponse struct {
Response string `json:"response"`
}

func Summarize(timeFrame string, model string, prompt string) () {
ollamaUrl := os.Getenv("OLLAMA_URL")
url := fmt.Sprintf("%s/api/generate", ollamaUrl)

bragJournal := Bragging(timeFrame)
prompt += fmt.Sprintf("\nJournal:\ns", bragJournal)

var workProjects string
var personalProjects string
var blogsAndVideos string

fmt.Print("Enter the name of your work projects:")
fmt.Scanf("s", workProjects)
prompt += "\nNames of Work Projects: " + workProjects

fmt.Print("Enter the name of your personal projects:")
fmt.Scanf("s", personalProjects)
prompt += "\nNames of Personal Projects: " + personalProjects

fmt.Print("Enter the name of your blog, youtube or any other content creation channels:")
fmt.Scanf("s", blogsAndVideos)
prompt += "\nNames of blog, youtube channels or any other content creation channels: " + blogsAndVideos

client := &http.Client{}
body, err := json.Marshal(map[string]interface{}{
"model": model,
"prompt": prompt,
"stream": false,
})
if err != nil {
fmt.Println("Error marshaling JSON body")
return
}

req, err := http.NewRequest("POST", url, bytes.NewReader(body))
if err != nil {
fmt.Println("Error creating new HTTP request")
return
}

req.Header.Set("Content-Type", "application/json")

resp, err := client.Do(req)
if err != nil {
fmt.Println("Error making POST request to URL", url)
return
}

// Read the response body
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response body")
return
}

var modelResponse ModelResponse
err = json.Unmarshal(body, &modelResponse)
if err != nil {
fmt.Println("Error unmarshaling JSON response body")
return
}

fmt.Println(modelResponse.Response)
}

0 comments on commit 716b583

Please sign in to comment.