Skip to content

Commit

Permalink
Merge pull request #35 from barakplasma/change-openai-base-url
Browse files Browse the repository at this point in the history
feat: allow user to change openai base url and model for LocalAI support
  • Loading branch information
piqoni committed Sep 1, 2023
2 parents d3ab370 + adbfe47 commit 1a456de
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 52 deletions.
78 changes: 54 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Matcha is a daily digest generator for your RSS feeds and interested topics/keyw
### In Obsidian
<img width="900" alt="image" src="https://user-images.githubusercontent.com/3144671/219786799-55db70c1-5860-4d4b-9df4-b81a89f8161d.png">

### On the terminal
### On the terminal

<img width="596" alt="image" src="https://user-images.githubusercontent.com/3144671/208323296-af2d6a51-7d33-42a9-a827-0e96a4a383fd.png">

Expand All @@ -31,47 +31,77 @@ Matcha is a daily digest generator for your RSS feeds and interested topics/keyw
- Quick bookmarking of articles to Instapaper
- Interested Topics/Keywords to follow (through [Google News](https://news.google.com/))
- Hacker News comments direct link and distinguishing mostly dicussed posts 🔥
- Terminal Mode by calling `./matcha -t`
- Terminal Mode by calling `./matcha -t`



## Installation / Usage
1. Since Matcha generates markdown, any markdown reader should do the job. Currently it has been tested on [Obsidian](https://obsidian.md/) so you need a markdown reader before moving on, unless you will use terminal mode (-t option), then a markdown reader is not needed.
2. **Download the [corresponding binary](https://github.com/piqoni/matcha/releases)** based on your OS and after executing (if on mac/linux run `chmod +x matcha-darwin-amd64` to make it executable), a sample `config.yml` will be generated, which you can add in your rss feeds, keywords and the `markdown_dir_path` where you want the markdown files to be generated (if left empty, it will generate the daily digest on current dir).
3. You can either execute matcha on-demand (a terminal alias) or set a cron to run matcha as often as you want. Even if you set it to execute every hour, matcha will still generate daily digests, one file per day, and will add more articles to it if new articles are published throughout the day.
1. Since Matcha generates markdown, any markdown reader should do the job. Currently it has been tested on [Obsidian](https://obsidian.md/) so you need a markdown reader before moving on, unless you will use terminal mode (-t option), then a markdown reader is not needed.
2. **Download the [corresponding binary](https://github.com/piqoni/matcha/releases)** based on your OS and after executing (if on mac/linux run `chmod +x matcha-darwin-amd64` to make it executable), a sample `config.yml` will be generated, which you can add in your rss feeds, keywords and the `markdown_dir_path` where you want the markdown files to be generated (if left empty, it will generate the daily digest on current dir).
3. You can either execute matcha on-demand (a terminal alias) or set a cron to run matcha as often as you want. Even if you set it to execute every hour, matcha will still generate daily digests, one file per day, and will add more articles to it if new articles are published throughout the day.

Note to Go developers: You can also install matcha using `go install github.com/piqoni/matcha@latest`
## Configuration
On first execution, Matcha will generate the following config.yaml and a markdown file on the same directory as the application. Change the 'feeds' to your actual RSS feeds, and google_news_keywords to the keywords you are interested in. And if you want to change where the markdown files are generated, set the full directory path in `markdown_dir_path`.
On first execution, Matcha will generate the following config.yaml and a markdown file on the same directory as the application. Change the 'feeds' to your actual RSS feeds, and google_news_keywords to the keywords you are interested in. And if you want to change where the markdown files are generated, set the full directory path in `markdown_dir_path`.

```yaml
markdown_dir_path:
```yaml
markdown_dir_path:
feeds:
- http://hnrss.org/best 10
- https://waitbutwhy.com/feed
- http://tonsky.me/blog/atom.xml
- http://www.joelonsoftware.com/rss.xml
- https://www.youtube.com/feeds/videos.xml?channel_id=UCHnyfMqiRRG1u-2MsSQLbXA
google_news_keywords: George Hotz,ChatGPT,Copenhagen
instapaper: true
google_news_keywords: George Hotz,ChatGPT,Copenhagen
instapaper: true
weather_latitude: 37.77
weather_longitude: 122.41
terminal_mode: false
opml_file_path:
markdown_file_prefix:
markdown_file_suffix:
opml_file_path:
markdown_file_prefix:
markdown_file_suffix:
reading_time: false
openai_api_key:
summary_feeds:
openai_api_key:
openai_base_url:
openai_model:
summary_feeds:
```
### Summary of Articles using ChatGPT
To use the summary feature, you need to an OpanAI account ([sign up here](https://openai.com/api/)) then get your API key [here](https://openai.com/api/).

Then update the configuration with the feeds you want to be summarized under "summary_feeds" setting, example:
```
openai_api_key: xxxxxxxxxxxxxxxxx
### Summarization of Articles using ChatGPT

In order to use the summarization feature, you'll first need to set up an OpenAI account. If you haven't already done so, you can sign up [here](https://platform.openai.com/login?launch). Once registered, you'll need to acquire an OpenAI API key which can be found [here](https://platform.openai.com/account/api-keys).

Alternatively, you may use LocalAI (see the "LocalAI Support" section below for more information).

Next, update the configuration file with the desired feeds you want to summarize. This can be done under the "summary_feeds" section. Here is an example configuration:

```yaml
openai_api_key: sk-xxxxxxxxxxxxxxxxx
summary_feeds:
- http://hnrss.org/best
- http://hnrss.org/best 10
```

Replace `sk-xxxxxxxxxxxxxxxxx` with your OpenAI API key and include the RSS feeds under `summary_feeds` for articles you're interested in summarizing.

You can also customize which model you use for summarization by changing the openai_model to one of the values [here](https://github.com/sashabaranov/go-openai/blob/a14bc103f4bc2b3ac40c844079fdf59dfdf62b0b/completion.go#L30) which defaults to 'gpt-3.5-turbo' for now. 'gpt-4' is also a valid model name.

```yaml
openai_model: gpt-3.5-turbo
```

#### LocalAI Support

For those interested in using LocalAI for summarization, whether for cost-efficiency or privacy reasons, you'll first need to set it up and run it. For setup instructions, please visit the LocalAI repository on GitHub [here](https://github.com/go-skynet/LocalAI).

After setting up LocalAI, you'll need to direct Matcha to the openai-compatible base URL of LocalAI. This is done by updating the "openai_base_url" in the configuration file. For instance, if your LocalAI server is running locally on port 8080, your configuration would look like this:

```yaml
openai_base_url: http://localhost:8080/v1
openai_model: openllama-3b
```

In this case, 'http://localhost:8080/v1' represents the base URL where your LocalAI server is running. 'openai_model' could be any model compatible with LocalAI. You can also replace the openai_base_url with another hosted url like the Azure openai endpoint.
Please note in case of errors that you may need to change the openai_model to match the model you downloaded in LocalAI.

### Command line Options
Run matcha with --help option to see current cli options:
```
Expand All @@ -80,10 +110,10 @@ Run matcha with --help option to see current cli options:
-o filepath
OPML file path to append feeds from opml files
-t Run Matcha in Terminal Mode, no markdown files will be created
```
```

#### OPML Import
To use OPML files (exported from other services), rename your file to `config.opml` and leave it in the directory where matcha is located. The other option is to run the command with -o option pointing to the opml filepath.
To use OPML files (exported from other services), rename your file to `config.opml` and leave it in the directory where matcha is located. The other option is to run the command with -o option pointing to the opml filepath.

<div align="center">
<a href="https://www.buymeacoffee.com/matchaRSS" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
Expand Down
24 changes: 16 additions & 8 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@ import (
"github.com/spf13/viper"
)

var config string = `markdown_dir_path:
var config string = `markdown_dir_path:
feeds:
- http://hnrss.org/best 10
- https://waitbutwhy.com/feed
- http://tonsky.me/blog/atom.xml
- http://www.joelonsoftware.com/rss.xml
- https://www.youtube.com/feeds/videos.xml?channel_id=UCHnyfMqiRRG1u-2MsSQLbXA
google_news_keywords: George Hotz,ChatGPT,Copenhagen
instapaper: true
google_news_keywords: George Hotz,ChatGPT,Copenhagen
instapaper: true
weather_latitude: 37.77
weather_longitude: 122.41
terminal_mode: false
opml_file_path:
markdown_file_prefix:
opml_file_path:
markdown_file_prefix:
markdown_file_suffix:
reading_time: false
openai_api_key:
summary_feeds:
reading_time: false
openai_api_key:
openai_base_url:
openai_model:
summary_feeds:
show_images: false`

func parseOPML(xmlContent []byte) []RSS {
Expand Down Expand Up @@ -124,6 +126,12 @@ func bootstrapConfig() {
if viper.IsSet("openai_api_key") {
openaiApiKey = viper.Get("openai_api_key").(string)
}
if viper.IsSet("openai_base_url") {
openaiBaseURL = viper.Get("openai_base_url").(string)
}
if viper.IsSet("openai_model") {
openaiModel = viper.Get("openai_model").(string)
}

if viper.IsSet("summary_feeds") {
summaryFeeds := viper.Get("summary_feeds")
Expand Down
2 changes: 2 additions & 0 deletions feeds_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var currentDate = time.Now().Format("2006-01-02")
var lat, lon float64
var instapaper bool
var openaiApiKey string
var openaiBaseURL string
var openaiModel string
var reading_time bool
var show_images bool
var myFeeds []RSS
Expand Down
34 changes: 17 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.18

require (
github.com/mmcdole/gofeed v1.1.3
github.com/sashabaranov/go-openai v1.9.0
github.com/spf13/viper v1.12.0
github.com/sashabaranov/go-openai v1.14.2
github.com/spf13/viper v1.16.0
modernc.org/sqlite v1.20.0
)

Expand All @@ -18,38 +18,38 @@ require (
require (
github.com/PuerkitoBio/goquery v1.5.1 // indirect
github.com/andybalholm/cascadia v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-shiori/go-readability v0.0.0-20220215145315-dd6828d2f09b
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jwalton/go-supportscolor v1.1.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/savioxavier/termlink v1.2.1
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
golang.org/x/mod v0.4.1 // indirect
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
modernc.org/ccgo/v3 v3.16.13 // indirect
Expand Down
Loading

0 comments on commit 1a456de

Please sign in to comment.