-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added subcommand summarize to generate a draft bragging documents usi…
…nd large language models
- Loading branch information
Showing
3 changed files
with
126 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |