mirror of https://github.com/jlelse/GoBlog
aitldr: Make model configurable
This commit is contained in:
parent
d84e33bb57
commit
58cee1be2b
|
@ -140,6 +140,7 @@ config:
|
||||||
# Required
|
# Required
|
||||||
apikey: YOUR_OPEN_AI_API_KEY
|
apikey: YOUR_OPEN_AI_API_KEY
|
||||||
# Optional:
|
# Optional:
|
||||||
|
model: gpt-4-turbo-preview # Choose a specific model, default is gpt-3.5-turbo
|
||||||
default: # Name of the blog
|
default: # Name of the blog
|
||||||
title: "Custom title for the summary box:"
|
title: "Custom title for the summary box:"
|
||||||
```
|
```
|
2
go.mod
2
go.mod
|
@ -121,7 +121,7 @@ require (
|
||||||
github.com/valyala/fastjson v1.6.4 // indirect
|
github.com/valyala/fastjson v1.6.4 // indirect
|
||||||
go.mau.fi/util v0.4.1 // indirect
|
go.mau.fi/util v0.4.1 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f // indirect
|
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 // indirect
|
||||||
golang.org/x/image v0.15.0 // indirect
|
golang.org/x/image v0.15.0 // indirect
|
||||||
golang.org/x/oauth2 v0.18.0 // indirect
|
golang.org/x/oauth2 v0.18.0 // indirect
|
||||||
golang.org/x/sys v0.18.0 // indirect
|
golang.org/x/sys v0.18.0 // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -312,8 +312,8 @@ golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
|
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
|
||||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||||
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f h1:3CW0unweImhOzd5FmYuRsD4Y4oQFKZIjAnKbjV4WIrw=
|
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 h1:6R2FC06FonbXQ8pK11/PDFY6N6LWlf9KlzibaCapmqc=
|
||||||
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
|
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ=
|
||||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
|
golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8=
|
||||||
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
|
golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
|
||||||
|
|
|
@ -19,6 +19,8 @@ type plugin struct {
|
||||||
|
|
||||||
config map[string]any
|
config map[string]any
|
||||||
initCSS sync.Once
|
initCSS sync.Once
|
||||||
|
|
||||||
|
apikey, model string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPlugin() (
|
func GetPlugin() (
|
||||||
|
@ -37,6 +39,17 @@ func (p *plugin) SetApp(app plugintypes.App) {
|
||||||
|
|
||||||
func (p *plugin) SetConfig(config map[string]any) {
|
func (p *plugin) SetConfig(config map[string]any) {
|
||||||
p.config = config
|
p.config = config
|
||||||
|
|
||||||
|
if k, ok := p.config["apikey"]; ok {
|
||||||
|
if ks, ok := k.(string); ok {
|
||||||
|
p.apikey = ks
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if m, ok := p.config["model"]; ok {
|
||||||
|
if ms, ok := m.(string); ok {
|
||||||
|
p.model = ms
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *plugin) PostCreated(post plugintypes.Post) {
|
func (p *plugin) PostCreated(post plugintypes.Post) {
|
||||||
|
@ -147,24 +160,23 @@ func (p *plugin) summarize(post plugintypes.Post) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apikey := ""
|
if p.apikey == "" {
|
||||||
if k, ok := p.config["apikey"]; ok {
|
|
||||||
if ks, ok := k.(string); ok {
|
|
||||||
apikey = ks
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if apikey == "" {
|
|
||||||
log.Println("Config for aitldr plugin not correct! apikey missing!")
|
log.Println("Config for aitldr plugin not correct! apikey missing!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var response apiResponse
|
var response apiResponse
|
||||||
|
|
||||||
|
model := "gpt-3.5-turbo"
|
||||||
|
if p.model != "" {
|
||||||
|
model = p.model
|
||||||
|
}
|
||||||
|
|
||||||
err := requests.URL("https://api.openai.com/v1/chat/completions").
|
err := requests.URL("https://api.openai.com/v1/chat/completions").
|
||||||
Method(http.MethodPost).
|
Method(http.MethodPost).
|
||||||
Header("Authorization", "Bearer "+apikey).
|
Header("Authorization", "Bearer "+p.apikey).
|
||||||
BodyJSON(map[string]any{
|
BodyJSON(map[string]any{
|
||||||
"model": "gpt-3.5-turbo-0125",
|
"model": model,
|
||||||
"messages": []apiMessage{
|
"messages": []apiMessage{
|
||||||
{
|
{
|
||||||
Role: "system",
|
Role: "system",
|
||||||
|
|
Loading…
Reference in New Issue