Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"encoding/gob"
"encoding/hex"
"encoding/json"
"errors"
"io/fs"
"os"
Expand Down Expand Up @@ -71,7 +72,7 @@ func (c *Client) CacheDir() string {

func (c *Client) cacheKey(key any) (string, error) {
hash := sha256.New()
if err := gob.NewEncoder(hash).Encode(key); err != nil {
if err := json.NewEncoder(hash).Encode(key); err != nil {
return "", err
}
digest := hash.Sum(nil)
Expand Down
4 changes: 2 additions & 2 deletions pkg/hash/seed.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package hash

import (
"encoding/gob"
"encoding/json"
"hash/fnv"
)

func Seed(input any) int {
h := fnv.New32a()
if err := gob.NewEncoder(h).Encode(input); err != nil {
if err := json.NewEncoder(h).Encode(input); err != nil {
panic(err)
}
return int(h.Sum32())
Expand Down
4 changes: 2 additions & 2 deletions pkg/openai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func override(left, right string) string {
}

func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest, transactionID string, partial chan<- types.CompletionStatus) (responses []openai.ChatCompletionStreamResponse, _ error) {
request.Stream = os.Getenv("GPTSCRIPT_INTERNAL_OPENAI_STREAMING") != "false"
streamResponse := os.Getenv("GPTSCRIPT_INTERNAL_OPENAI_STREAMING") != "false"

partial <- types.CompletionStatus{
CompletionID: transactionID,
Expand All @@ -459,7 +459,7 @@ func (c *Client) call(ctx context.Context, request openai.ChatCompletionRequest,

slog.Debug("calling openai", "message", request.Messages)

if !request.Stream {
if !streamResponse {
resp, err := c.c.CreateChatCompletion(ctx, request)
if err != nil {
return nil, err
Expand Down
5 changes: 4 additions & 1 deletion pkg/types/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ type CompletionRequest struct {
}

func (r *CompletionRequest) GetCache() bool {
return r.Cache != nil && !*r.Cache
if r.Cache == nil {
return true
}
return *r.Cache
}

type CompletionTool struct {
Expand Down