aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2024-07-26 10:34:46 -0400
committerXe Iaso <me@xeiaso.net>2024-07-26 10:35:34 -0400
commit3773fbdc51ee368589c18b4365dcc4c473e4ddd5 (patch)
tree9b342ee5f704af04e50e6f293d15b6c3af9a24ca
parent63e4926b55e358a6127649c1ee723e25ddd366a0 (diff)
downloadx-3773fbdc51ee368589c18b4365dcc4c473e4ddd5.tar.xz
x-3773fbdc51ee368589c18b4365dcc4c473e4ddd5.zip
try making alvis better
Signed-off-by: Xe Iaso <me@xeiaso.net>
-rw-r--r--.go.mod.sri2
-rw-r--r--cmd/alvis/main.go7
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--web/algora/algora.go7
-rw-r--r--web/openai/chatgpt/chatgpt.go9
6 files changed, 25 insertions, 4 deletions
diff --git a/.go.mod.sri b/.go.mod.sri
index 718ce78..75131cc 100644
--- a/.go.mod.sri
+++ b/.go.mod.sri
@@ -1 +1 @@
-sha256-qQ09aOo/3t3yvZgCrdoW2Ob/BKB/Yb3er1RV6kRPGqg=
+sha256-mxsGupy7mN884X31Zzm+WuPV/O7RBHPo87vsy2OhmG8=
diff --git a/cmd/alvis/main.go b/cmd/alvis/main.go
index ac6268c..3b5b233 100644
--- a/cmd/alvis/main.go
+++ b/cmd/alvis/main.go
@@ -23,8 +23,9 @@ import (
var (
flyAPIBaseURL = flag.String("fly-base-url", "https://api.fly.io", "Fly API base URL")
flyToken = flag.String("fly-token", "", "Fly API token")
- openAIToken = flag.String("openai-token", "", "OpenAI API token")
openAIModel = flag.String("openai-model", "gpt-3.5-turbo-16k", "OpenAI model to use")
+ openAIToken = flag.String("openai-token", "", "OpenAI API token")
+ openAIURL = flag.String("openai-url", "", "OpenAI API base URL")
//go:embed playbooks/*
playbooks embed.FS
@@ -43,6 +44,10 @@ func main() {
cli := chatgpt.NewClient(*openAIToken)
+ if *openAIURL != "" {
+ cli = cli.WithBaseURL(*openAIURL)
+ }
+
flyapi.SetBaseURL(*flyAPIBaseURL)
fly := flyapi.NewClient(*flyToken, "alvis", "devel", flySlogger{})
diff --git a/go.mod b/go.mod
index dd49123..9efe09e 100644
--- a/go.mod
+++ b/go.mod
@@ -287,7 +287,7 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/mux v1.8.1
- github.com/gorilla/websocket v1.5.1
+ github.com/gorilla/websocket v1.5.3
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.2.0 // indirect
diff --git a/go.sum b/go.sum
index a2fd8d8..0e0efea 100644
--- a/go.sum
+++ b/go.sum
@@ -562,6 +562,8 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
+github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
+github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grbit/go-json v0.11.0 h1:bAbyMdYrYl/OjYsSqLH99N2DyQ291mHy726Mx+sYrnc=
github.com/grbit/go-json v0.11.0/go.mod h1:IYpHsdybQ386+6g3VE6AXQ3uTGa5mquBme5/ZWmtzek=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
diff --git a/web/algora/algora.go b/web/algora/algora.go
new file mode 100644
index 0000000..ff97802
--- /dev/null
+++ b/web/algora/algora.go
@@ -0,0 +1,7 @@
+package algora
+
+import "github.com/gorilla/websocket"
+
+type ChatConn struct {
+ *websocket.Conn
+}
diff --git a/web/openai/chatgpt/chatgpt.go b/web/openai/chatgpt/chatgpt.go
index ea375df..2fb044f 100644
--- a/web/openai/chatgpt/chatgpt.go
+++ b/web/openai/chatgpt/chatgpt.go
@@ -83,12 +83,19 @@ type Response struct {
type Client struct {
httpCli *http.Client
apiKey string
+ baseURL string
+}
+
+func (c Client) WithBaseURL(baseURL string) Client {
+ c.baseURL = baseURL
+ return c
}
func NewClient(apiKey string) Client {
return Client{
httpCli: &http.Client{},
apiKey: apiKey,
+ baseURL: "https://api.openai.com",
}
}
@@ -102,7 +109,7 @@ func (c Client) Complete(ctx context.Context, r Request) (*Response, error) {
return nil, err
}
- req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://api.openai.com/v1/chat/completions", bytes.NewBuffer(data))
+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/v1/chat/completions", bytes.NewBuffer(data))
if err != nil {
return nil, fmt.Errorf("chatgpt: [unexpected] can't make request???: %w", err)
}