From abe4ae6fea9ca3f45581707ec55c9646cf364170 Mon Sep 17 00:00:00 2001
From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com>
Date: Tue, 17 Sep 2024 21:24:33 -0700
Subject: [PATCH] Update AI Library (#784)

The AI library was outdated and seemed to prevent newer project-based
keys from working. This update should hopefully correct that.
---
 wavesrv/go.mod                      | 2 +-
 wavesrv/go.sum                      | 2 ++
 wavesrv/pkg/remote/openai/openai.go | 4 ++--
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/wavesrv/go.mod b/wavesrv/go.mod
index e98fc5433..5e5f00200 100644
--- a/wavesrv/go.mod
+++ b/wavesrv/go.mod
@@ -17,7 +17,7 @@ require (
 	github.com/jmoiron/sqlx v1.3.5
 	github.com/kevinburke/ssh_config v1.2.0
 	github.com/mattn/go-sqlite3 v1.14.16
-	github.com/sashabaranov/go-openai v1.9.0
+	github.com/sashabaranov/go-openai v1.30.0
 	github.com/sawka/txwrap v0.1.2
 	github.com/wavetermdev/waveterm/waveshell v0.0.0
 	golang.org/x/crypto v0.24.0
diff --git a/wavesrv/go.sum b/wavesrv/go.sum
index de688c7c9..03df3aa14 100644
--- a/wavesrv/go.sum
+++ b/wavesrv/go.sum
@@ -51,6 +51,8 @@ github.com/rogpeppe/go-internal v1.10.1-0.20230524175051-ec119421bb97 h1:3RPlVWz
 github.com/rogpeppe/go-internal v1.10.1-0.20230524175051-ec119421bb97/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
 github.com/sashabaranov/go-openai v1.9.0 h1:NoiO++IISxxJ1pRc0n7uZvMGMake0G+FJ1XPwXtprsA=
 github.com/sashabaranov/go-openai v1.9.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
+github.com/sashabaranov/go-openai v1.30.0 h1:fHv9urGxABfm885xGWsXFSk5cksa+8dJ4jGli/UQQcI=
+github.com/sashabaranov/go-openai v1.30.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
 github.com/sawka/txwrap v0.1.2 h1:v8xS0Z1LE7/6vMZA81PYihI+0TSR6Zm1MalzzBIuXKc=
 github.com/sawka/txwrap v0.1.2/go.mod h1:T3nlw2gVpuolo6/XEetvBbk1oMXnY978YmBFy1UyHvw=
 github.com/skeema/knownhosts v1.3.0 h1:AM+y0rI04VksttfwjkSTNQorvGqmwATnvnAHpSgc0LY=
diff --git a/wavesrv/pkg/remote/openai/openai.go b/wavesrv/pkg/remote/openai/openai.go
index 4b060d2d6..a8fb16542 100644
--- a/wavesrv/pkg/remote/openai/openai.go
+++ b/wavesrv/pkg/remote/openai/openai.go
@@ -190,7 +190,7 @@ func RunCompletionStream(ctx context.Context, opts *sstore.OpenAIOptsType, promp
 				pk := packet.MakeOpenAIPacket()
 				pk.Index = choice.Index
 				pk.Text = choice.Delta.Content
-				pk.FinishReason = choice.FinishReason
+				pk.FinishReason = string(choice.FinishReason)
 				rtn <- pk
 			}
 		}
@@ -209,7 +209,7 @@ func marshalResponse(resp openaiapi.ChatCompletionResponse) []*packet.OpenAIPack
 		choicePk := packet.MakeOpenAIPacket()
 		choicePk.Index = choice.Index
 		choicePk.Text = choice.Message.Content
-		choicePk.FinishReason = choice.FinishReason
+		choicePk.FinishReason = string(choice.FinishReason)
 		rtn = append(rtn, choicePk)
 	}
 	return rtn