Skip to content

Commit

Permalink
chore: drop internal prompt
Browse files Browse the repository at this point in the history
Also seed and stream_options.include_usage will be set in all requests
  • Loading branch information
ibuildthecloud committed Aug 5, 2024
1 parent 160a733 commit 0ee119a
Show file tree
Hide file tree
Showing 56 changed files with 95 additions and 145 deletions.
1 change: 0 additions & 1 deletion docs/docs/04-command-line-reference/gptscript_eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ gptscript eval [flags]
```
--chat Enable chat ($GPTSCRIPT_EVAL_CHAT)
-h, --help help for eval
--internal-prompt ($GPTSCRIPT_EVAL_INTERNAL_PROMPT)
--json Output JSON ($GPTSCRIPT_EVAL_JSON)
--max-tokens int Maximum number of tokens to output ($GPTSCRIPT_EVAL_MAX_TOKENS)
--model string The model to use ($GPTSCRIPT_EVAL_MODEL)
Expand Down
26 changes: 12 additions & 14 deletions pkg/cli/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ import (
)

type Eval struct {
Tools []string `usage:"Tools available to call"`
Chat bool `usage:"Enable chat"`
MaxTokens int `usage:"Maximum number of tokens to output"`
Model string `usage:"The model to use"`
JSON bool `usage:"Output JSON"`
Temperature string `usage:"Set the temperature, \"creativity\""`
InternalPrompt *bool `Usage:"Set to false to disable the internal prompt"`
Tools []string `usage:"Tools available to call"`
Chat bool `usage:"Enable chat"`
MaxTokens int `usage:"Maximum number of tokens to output"`
Model string `usage:"The model to use"`
JSON bool `usage:"Output JSON"`
Temperature string `usage:"Set the temperature, \"creativity\""`

gptscript *GPTScript
}
Expand All @@ -30,13 +29,12 @@ func (e *Eval) Run(cmd *cobra.Command, args []string) error {
tool := types.Tool{
ToolDef: types.ToolDef{
Parameters: types.Parameters{
Description: "inline script",
Tools: e.Tools,
MaxTokens: e.MaxTokens,
ModelName: e.Model,
JSONResponse: e.JSON,
InternalPrompt: e.InternalPrompt,
Chat: e.Chat,
Description: "inline script",
Tools: e.Tools,
MaxTokens: e.MaxTokens,
ModelName: e.Model,
JSONResponse: e.JSON,
Chat: e.Chat,
},
Instructions: strings.Join(args, " "),
},
Expand Down
59 changes: 59 additions & 0 deletions pkg/engine/cmd_test.go

Large diffs are not rendered by default.

17 changes: 6 additions & 11 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,12 @@ func (e *Engine) Start(ctx Context, input string) (ret *Return, _ error) {
}

completion := types.CompletionRequest{
Model: tool.Parameters.ModelName,
MaxTokens: tool.Parameters.MaxTokens,
JSONResponse: tool.Parameters.JSONResponse,
Cache: tool.Parameters.Cache,
Chat: tool.Parameters.Chat,
Temperature: tool.Parameters.Temperature,
InternalSystemPrompt: tool.Parameters.InternalPrompt,
}

if tool.Chat && completion.InternalSystemPrompt == nil {
completion.InternalSystemPrompt = new(bool)
Model: tool.Parameters.ModelName,
MaxTokens: tool.Parameters.MaxTokens,
JSONResponse: tool.Parameters.JSONResponse,
Cache: tool.Parameters.Cache,
Chat: tool.Parameters.Chat,
Temperature: tool.Parameters.Temperature,
}

var err error
Expand Down
3 changes: 1 addition & 2 deletions pkg/gptscript/gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func New(ctx context.Context, o ...Options) (*GPTScript, error) {

if opts.DefaultModelProvider == "" {
oaiClient, err := openai.NewClient(ctx, credStore, opts.OpenAI, openai.Options{
Cache: cacheClient,
SetSeed: true,
Cache: cacheClient,
})
if err != nil {
return nil, err
Expand Down
6 changes: 0 additions & 6 deletions pkg/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func TestHelloWorld(t *testing.T) {
"toolSet": {
"https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:": {
"modelName": "gpt-4o",
"internalPrompt": null,
"instructions": "Say hello world",
"id": "https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/bob.gpt:",
"localTools": {
Expand All @@ -93,7 +92,6 @@ func TestHelloWorld(t *testing.T) {
},
"https://raw.githubusercontent.com/ibuildthecloud/test/bafe5a62174e8a0ea162277dcfe3a2ddb7eea928/example/sub/tool.gpt:": {
"modelName": "gpt-4o",
"internalPrompt": null,
"tools": [
"../bob.gpt"
],
Expand Down Expand Up @@ -129,7 +127,6 @@ func TestHelloWorld(t *testing.T) {
"https://get.gptscript.ai/echo.gpt:": {
"description": "Returns back the input of the script",
"modelName": "gpt-4o",
"internalPrompt": null,
"arguments": {
"properties": {
"input": {
Expand Down Expand Up @@ -164,7 +161,6 @@ func TestDefault(t *testing.T) {
"testdata/tool/tool.gpt:tool": {
"name": "tool",
"modelName": "gpt-4o",
"internalPrompt": null,
"instructions": "a tool",
"id": "testdata/tool/tool.gpt:tool",
"localTools": {
Expand All @@ -188,7 +184,6 @@ func TestDefault(t *testing.T) {
"testdata/agent/agent.gpt:agent": {
"name": "agent",
"modelName": "gpt-4o",
"internalPrompt": null,
"instructions": "an agent",
"id": "testdata/agent/agent.gpt:agent",
"localTools": {
Expand All @@ -212,7 +207,6 @@ func TestDefault(t *testing.T) {
"testdata/bothtoolagent/agent.gpt:agent": {
"name": "agent",
"modelName": "gpt-4o",
"internalPrompt": null,
"instructions": "an agent",
"id": "testdata/bothtoolagent/agent.gpt:agent",
"localTools": {
Expand Down
20 changes: 5 additions & 15 deletions pkg/openai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type Client struct {
cache *cache.Client
invalidAuth bool
cacheKeyBase string
setSeed bool
credStore credentials.CredentialStore
}

Expand All @@ -54,7 +53,6 @@ type Options struct {
OrgID string `usage:"OpenAI organization ID" name:"openai-org-id" env:"OPENAI_ORG_ID"`
DefaultModel string `usage:"Default LLM model to use" default:"gpt-4o"`
ConfigFile string `usage:"Path to GPTScript config file" name:"config"`
SetSeed bool `usage:"-"`
CacheKey string `usage:"-"`
Cache *cache.Client
}
Expand All @@ -66,7 +64,6 @@ func Complete(opts ...Options) (result Options) {
result.OrgID = types.FirstSet(opt.OrgID, result.OrgID)
result.Cache = types.FirstSet(opt.Cache, result.Cache)
result.DefaultModel = types.FirstSet(opt.DefaultModel, result.DefaultModel)
result.SetSeed = types.FirstSet(opt.SetSeed, result.SetSeed)
result.CacheKey = types.FirstSet(opt.CacheKey, result.CacheKey)
}

Expand Down Expand Up @@ -125,7 +122,6 @@ func NewClient(ctx context.Context, credStore credentials.CredentialStore, opts
defaultModel: opt.DefaultModel,
cacheKeyBase: cacheKeyBase,
invalidAuth: opt.APIKey == "" && opt.BaseURL == "",
setSeed: opt.SetSeed,
credStore: credStore,
}, nil
}
Expand Down Expand Up @@ -227,16 +223,12 @@ func toToolCall(call types.CompletionToolCall) openai.ToolCall {
}
}

func toMessages(request types.CompletionRequest, compat bool) (result []openai.ChatCompletionMessage, err error) {
func toMessages(request types.CompletionRequest) (result []openai.ChatCompletionMessage, err error) {
var (
systemPrompts []string
msgs []types.CompletionMessage
)

if !compat && (request.InternalSystemPrompt == nil || *request.InternalSystemPrompt) {
systemPrompts = append(systemPrompts, system.InternalSystemPrompt)
}

for _, message := range request.Messages {
if message.Role == types.CompletionMessageRoleTypeSystem {
systemPrompts = append(systemPrompts, message.Content[0].Text)
Expand Down Expand Up @@ -304,7 +296,7 @@ func (c *Client) Call(ctx context.Context, messageRequest types.CompletionReques
messageRequest.Model = c.defaultModel
}

msgs, err := toMessages(messageRequest, !c.setSeed)
msgs, err := toMessages(messageRequest)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -365,11 +357,9 @@ func (c *Client) Call(ctx context.Context, messageRequest types.CompletionReques
}

var cacheResponse bool
if c.setSeed {
request.Seed = ptr(c.seed(request))
request.StreamOptions = &openai.StreamOptions{
IncludeUsage: true,
}
request.Seed = ptr(c.seed(request))
request.StreamOptions = &openai.StreamOptions{
IncludeUsage: true,
}
response, ok, err := c.fromCache(ctx, messageRequest, request)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ func isParam(line string, tool *types.Tool) (_ bool, err error) {
case "description":
tool.Parameters.Description = value
case "internalprompt":
v, err := toBool(value)
if err != nil {
return false, err
}
tool.Parameters.InternalPrompt = &v
// deprecated and ignored
case "chat":
v, err := toBool(value)
if err != nil {
Expand Down
18 changes: 0 additions & 18 deletions pkg/system/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package system

import (
"encoding/json"
"os"
"strings"

"github.com/getkin/kin-openapi/openapi3"
Expand All @@ -11,17 +10,6 @@ import (
// Suffix is default suffix of gptscript files
const Suffix = ".gpt"

// InternalSystemPrompt is added to all threads. Changing this is very dangerous as it has a
// terrible global effect and changes the behavior of all scripts.
var InternalSystemPrompt = `
You are task oriented system.
You receive input from a user, process the input from the given instructions, and then output the result.
Your objective is to provide consistent and correct results.
You do not need to explain the steps taken, only provide the result to the given instructions.
You are referred to as a tool.
You don't move to the next step until you have a result.
`

// DefaultPromptParameter is used as the key in a json map to indication that we really wanted
// to just send pure text but the interface required JSON (as that is the fundamental interface of tools in OpenAI)
var DefaultPromptParameter = "defaultPromptParameter"
Expand Down Expand Up @@ -50,12 +38,6 @@ var DefaultChatSchema = openapi3.Schema{
},
}

func init() {
if p := os.Getenv("GPTSCRIPT_INTERNAL_SYSTEM_PROMPT"); p != "" {
InternalSystemPrompt = p
}
}

// IsDefaultPrompt Checks if the content is a json blob that has the defaultPromptParameter in it. If so
// it will extract out the value and return it. If not it will return the original content as is and false.
func IsDefaultPrompt(content string) (string, bool) {
Expand Down
7 changes: 0 additions & 7 deletions pkg/tests/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func TestAsterick(t *testing.T) {
"testdata/TestAsterick/other.gpt:a": {
"name": "a",
"modelName": "gpt-4o",
"internalPrompt": null,
"instructions": "a",
"id": "testdata/TestAsterick/other.gpt:a",
"localTools": {
Expand All @@ -55,7 +54,6 @@ func TestAsterick(t *testing.T) {
"testdata/TestAsterick/other.gpt:afoo": {
"name": "afoo",
"modelName": "gpt-4o",
"internalPrompt": null,
"instructions": "afoo",
"id": "testdata/TestAsterick/other.gpt:afoo",
"localTools": {
Expand All @@ -73,7 +71,6 @@ func TestAsterick(t *testing.T) {
},
"testdata/TestAsterick/test.gpt:": {
"modelName": "gpt-4o",
"internalPrompt": null,
"tools": [
"a* from ./other.gpt"
],
Expand Down Expand Up @@ -396,7 +393,6 @@ func TestSubChat(t *testing.T) {
"state": {
"completion": {
"model": "gpt-4o",
"internalSystemPrompt": false,
"messages": [
{
"role": "system",
Expand Down Expand Up @@ -521,7 +517,6 @@ func TestSubChat(t *testing.T) {
"state": {
"completion": {
"model": "gpt-4o",
"internalSystemPrompt": false,
"messages": [
{
"role": "system",
Expand Down Expand Up @@ -598,7 +593,6 @@ func TestChat(t *testing.T) {
"input": "Hello",
"completion": {
"model": "gpt-4o",
"internalSystemPrompt": false,
"messages": [
{
"role": "system",
Expand Down Expand Up @@ -650,7 +644,6 @@ func TestChat(t *testing.T) {
"input": "Hello",
"completion": {
"model": "gpt-4o",
"internalSystemPrompt": false,
"messages": [
{
"role": "system",
Expand Down
1 change: 0 additions & 1 deletion pkg/tests/testdata/TestAgentOnly/call1.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"tools": [
{
"function": {
Expand Down
1 change: 0 additions & 1 deletion pkg/tests/testdata/TestAgentOnly/call2.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"tools": [
{
"function": {
Expand Down
2 changes: 0 additions & 2 deletions pkg/tests/testdata/TestAgentOnly/step1.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"input": "Input 1",
"completion": {
"model": "gpt-4o",
"internalSystemPrompt": false,
"tools": [
{
"function": {
Expand Down Expand Up @@ -92,7 +91,6 @@
"input": "Agent 2 input",
"completion": {
"model": "gpt-4o",
"internalSystemPrompt": false,
"tools": [
{
"function": {
Expand Down
1 change: 0 additions & 1 deletion pkg/tests/testdata/TestAgents/call1.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"tools": [
{
"function": {
Expand Down
1 change: 0 additions & 1 deletion pkg/tests/testdata/TestAgents/call2.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"tools": [
{
"function": {
Expand Down
1 change: 0 additions & 1 deletion pkg/tests/testdata/TestAgents/call3.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"tools": [
{
"function": {
Expand Down
1 change: 0 additions & 1 deletion pkg/tests/testdata/TestAgents/call4.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"messages": [
{
"role": "system",
Expand Down
Loading

0 comments on commit 0ee119a

Please sign in to comment.