From 5d32372e209b34ab07faabb559dc262cd8f12238 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Sun, 11 Aug 2024 12:06:56 -0400 Subject: [PATCH] feat: use GPTScript Gateway instead of OpenAI directly Signed-off-by: Donnie Adams Add dataset toolgpt (#79) change: use default blueprint for gateway version Don't use dataset id context (#81) --- main.go | 15 +++++++++++++++ pkg/cmd/client.go | 2 +- tool.gpt | 5 ++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 51265d03..3b752bce 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,25 @@ package main import ( + "fmt" + "os" + acmd "github.com/acorn-io/cmd" "github.com/gptscript-ai/knowledge/pkg/cmd" ) func main() { + if err := os.Setenv("OPENAI_API_KEY", os.Getenv("GPTSCRIPT_GATEWAY_API_KEY")); err != nil { + panic(fmt.Errorf("failed to set OPENAI_API_KEY: %w", err)) + } + + gatewayURL := os.Getenv("GPTSCRIPT_GATEWAY_URL") + if gatewayURL == "" { + gatewayURL = "https://gateway-api.gptscript.ai" + } + if err := os.Setenv("OPENAI_BASE_URL", gatewayURL+"/llm"); err != nil { + panic(fmt.Errorf("failed to set OPENAI_BASE_URL: %w", err)) + } + acmd.Main(cmd.New()) } diff --git a/pkg/cmd/client.go b/pkg/cmd/client.go index d2dd645b..c2683b40 100644 --- a/pkg/cmd/client.go +++ b/pkg/cmd/client.go @@ -26,7 +26,7 @@ type Client struct { } type ClientFlowsConfig struct { - FlowsFile string `usage:"Path to a YAML/JSON file containing ingestion/retrieval flows" env:"KNOW_FLOWS_FILE" default:""` + FlowsFile string `usage:"Path to a YAML/JSON file containing ingestion/retrieval flows" env:"KNOW_FLOWS_FILE" default:"blueprint:default"` Flow string `usage:"Flow name" env:"KNOW_FLOW"` } diff --git a/tool.gpt b/tool.gpt index 5ac2a851..45ef4abf 100644 --- a/tool.gpt +++ b/tool.gpt @@ -16,10 +16,9 @@ If the answers it returns seem irrelevant, you can use other tools, but do not f Name: Knowledge Retrieval Description: Retrieve information from files uploaded by the user. Context: github.com/gptscript-ai/context/workspace -Credential: github.com/gptscript-ai/credential as sys.openai with OPENAI_API_KEY as env and "Please provide your OpenAI API key" as message and key as field +Credential: github.com/gptscript-ai/gateway-creds as github.com/gptscript-ai/gateway Param: know_retrieve_keywords: (OPTIONAL - only use if you think it will improve results) A comma-separated list (no spaces) of keywords used to pre-filter the document base before conducting the semantic similarity search. Prefix a keyword sign with a dash (-) to exclude documents containing that keyword. Param: query: The query to search for in the knowledge base. It will be used for semantic similarity search, so enhance it accordingly to yield good results. Param: debug: (OPTIONAL) Set to "true" to enable debug mode - only use if you are explicitly asked to do so. -#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool askdir --path "${GPTSCRIPT_WORKSPACE_DIR}" "${QUERY}" - +#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool retrieve --dataset ${GPTSCRIPT_THREAD_ID} "${QUERY}"