From f09a61fda9fc2ef2507ed9deae7caa1e57ca16e3 Mon Sep 17 00:00:00 2001 From: Daishan Peng Date: Thu, 23 Jan 2025 15:45:03 -0700 Subject: [PATCH 1/6] Chore: Add openai o1 support Signed-off-by: Daishan Peng --- openai-model-provider/go.mod | 2 ++ openai-model-provider/go.sum | 2 ++ 2 files changed, 4 insertions(+) diff --git a/openai-model-provider/go.mod b/openai-model-provider/go.mod index d477dca4..4435c182 100644 --- a/openai-model-provider/go.mod +++ b/openai-model-provider/go.mod @@ -1,3 +1,5 @@ module github.com/obot-platform/tools/openai-model-provider go 1.23.4 + +require github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 diff --git a/openai-model-provider/go.sum b/openai-model-provider/go.sum index e69de29b..35cd45d7 100644 --- a/openai-model-provider/go.sum +++ b/openai-model-provider/go.sum @@ -0,0 +1,2 @@ +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 h1:rfriXe+FFqZ5fZ+wGzLUivrq7Fyj2xfRdZjDsHf6Ps0= +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo= From 91dc14de0182e47a1d436ba23bad36d60651c7dd Mon Sep 17 00:00:00 2001 From: Daishan Peng Date: Thu, 23 Jan 2025 16:00:33 -0700 Subject: [PATCH 2/6] Update go.mod tidy Signed-off-by: Daishan Peng --- deepseek-model-provider/go.mod | 2 ++ deepseek-model-provider/go.sum | 2 ++ excel/go.mod | 2 +- groq-model-provider/go.mod | 2 ++ groq-model-provider/go.sum | 2 ++ ollama-model-provider/go.mod | 2 ++ ollama-model-provider/go.sum | 2 ++ outlook/calendar/go.mod | 13 ------------- outlook/calendar/go.sum | 30 ------------------------------ vllm-model-provider/go.mod | 2 +- vllm-model-provider/go.sum | 4 ++-- xai-model-provider/go.mod | 2 ++ xai-model-provider/go.sum | 2 ++ 13 files changed, 20 insertions(+), 47 deletions(-) create mode 100644 ollama-model-provider/go.sum diff --git a/deepseek-model-provider/go.mod b/deepseek-model-provider/go.mod index 83c5f1a9..cc02eb30 100644 --- a/deepseek-model-provider/go.mod +++ b/deepseek-model-provider/go.mod @@ -5,3 +5,5 @@ go 1.23.4 replace github.com/obot-platform/tools/openai-model-provider => ../openai-model-provider require github.com/obot-platform/tools/openai-model-provider v0.0.0 + +require github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 // indirect diff --git a/deepseek-model-provider/go.sum b/deepseek-model-provider/go.sum index e69de29b..35cd45d7 100644 --- a/deepseek-model-provider/go.sum +++ b/deepseek-model-provider/go.sum @@ -0,0 +1,2 @@ +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 h1:rfriXe+FFqZ5fZ+wGzLUivrq7Fyj2xfRdZjDsHf6Ps0= +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo= diff --git a/excel/go.mod b/excel/go.mod index fd5da95d..5f252e4c 100644 --- a/excel/go.mod +++ b/excel/go.mod @@ -4,6 +4,7 @@ go 1.23.1 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 + github.com/getkin/kin-openapi v0.124.0 github.com/gptscript-ai/go-gptscript v0.9.5 github.com/microsoft/kiota-abstractions-go v1.7.0 github.com/microsoftgraph/msgraph-sdk-go v1.51.0 @@ -13,7 +14,6 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect github.com/cjlapao/common-go v0.0.41 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/getkin/kin-openapi v0.124.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v0.20.2 // indirect diff --git a/groq-model-provider/go.mod b/groq-model-provider/go.mod index 39b62b72..ee8b73ac 100644 --- a/groq-model-provider/go.mod +++ b/groq-model-provider/go.mod @@ -5,3 +5,5 @@ go 1.23.4 replace github.com/obot-platform/tools/openai-model-provider => ../openai-model-provider require github.com/obot-platform/tools/openai-model-provider v0.0.0 + +require github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 // indirect diff --git a/groq-model-provider/go.sum b/groq-model-provider/go.sum index e69de29b..35cd45d7 100644 --- a/groq-model-provider/go.sum +++ b/groq-model-provider/go.sum @@ -0,0 +1,2 @@ +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 h1:rfriXe+FFqZ5fZ+wGzLUivrq7Fyj2xfRdZjDsHf6Ps0= +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo= diff --git a/ollama-model-provider/go.mod b/ollama-model-provider/go.mod index 39d5ddb0..3c8ee6af 100644 --- a/ollama-model-provider/go.mod +++ b/ollama-model-provider/go.mod @@ -5,3 +5,5 @@ go 1.23.4 replace github.com/obot-platform/tools/openai-model-provider => ../openai-model-provider require github.com/obot-platform/tools/openai-model-provider v0.0.0 + +require github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 // indirect diff --git a/ollama-model-provider/go.sum b/ollama-model-provider/go.sum new file mode 100644 index 00000000..35cd45d7 --- /dev/null +++ b/ollama-model-provider/go.sum @@ -0,0 +1,2 @@ +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 h1:rfriXe+FFqZ5fZ+wGzLUivrq7Fyj2xfRdZjDsHf6Ps0= +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo= diff --git a/outlook/calendar/go.mod b/outlook/calendar/go.mod index f8f3aec3..2a124034 100644 --- a/outlook/calendar/go.mod +++ b/outlook/calendar/go.mod @@ -18,21 +18,15 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect github.com/cjlapao/common-go v0.0.41 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dustin/go-humanize v1.0.1 // indirect github.com/getkin/kin-openapi v0.128.0 // indirect - github.com/glebarez/go-sqlite v1.21.2 // indirect - github.com/glebarez/sqlite v1.11.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/swag v0.23.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/invopop/yaml v0.3.1 // indirect - github.com/jinzhu/inflection v1.0.0 // indirect - github.com/jinzhu/now v1.1.5 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect github.com/microsoft/kiota-authentication-azure-go v1.1.0 // indirect github.com/microsoft/kiota-http-go v1.4.5 // indirect @@ -45,19 +39,12 @@ require ( github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect github.com/std-uritemplate/std-uritemplate/go v1.0.6 // indirect go.opentelemetry.io/otel v1.31.0 // indirect go.opentelemetry.io/otel/metric v1.31.0 // indirect go.opentelemetry.io/otel/trace v1.31.0 // indirect golang.org/x/net v0.30.0 // indirect - golang.org/x/sys v0.26.0 // indirect golang.org/x/text v0.19.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - gorm.io/gorm v1.25.7 // indirect - modernc.org/libc v1.22.5 // indirect - modernc.org/mathutil v1.5.0 // indirect - modernc.org/memory v1.5.0 // indirect - modernc.org/sqlite v1.23.1 // indirect ) diff --git a/outlook/calendar/go.sum b/outlook/calendar/go.sum index e70c8c5a..38717b07 100644 --- a/outlook/calendar/go.sum +++ b/outlook/calendar/go.sum @@ -6,14 +6,8 @@ github.com/cjlapao/common-go v0.0.41 h1:j30UKZJWVWIllJ66x3EOslJvIk/VjkyenrhEcH64 github.com/cjlapao/common-go v0.0.41/go.mod h1:ao5wEp0hYMNehJiHoarSjc5dKK5wi4LvnwjXaC2SxUI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= -github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4= github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM= -github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo= -github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k= -github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw= -github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -27,8 +21,6 @@ github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ= -github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gptscript-ai/go-gptscript v0.9.6-0.20241106212914-ba040ce8f47b h1:adIh3EnMTlC19t2k1IJoOtF6me/hPxks2GxSSgB7oEw= @@ -37,10 +29,6 @@ github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso= github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA= github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 h1:iCHtR9CQyktQ5+f3dMVZfwD2KWJUgm7M0gdL9NGr8KA= github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056/go.mod h1:CVKlgaMiht+LXvHG173ujK6JUhZXKb2u/BQtjPDIvyk= -github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= -github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= -github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -49,8 +37,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/microsoft/kiota-abstractions-go v1.7.0 h1:/0OKSSEe94Z1qgpcGE7ZFI9P+4iAnsDQo9v9UOk+R8E= @@ -79,9 +65,6 @@ github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= -github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo= @@ -100,9 +83,6 @@ go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HY go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -110,13 +90,3 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A= -gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= -modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE= -modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY= -modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ= -modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= -modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds= -modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU= -modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM= -modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk= diff --git a/vllm-model-provider/go.mod b/vllm-model-provider/go.mod index 84f2fb0b..0632e4ac 100644 --- a/vllm-model-provider/go.mod +++ b/vllm-model-provider/go.mod @@ -5,6 +5,6 @@ go 1.23.4 replace github.com/obot-platform/tools/openai-model-provider => ../openai-model-provider require ( - github.com/gptscript-ai/chat-completion-client v0.0.0-20241127005108-02b41e1cd02e + github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 github.com/obot-platform/tools/openai-model-provider v0.0.0 ) diff --git a/vllm-model-provider/go.sum b/vllm-model-provider/go.sum index e6ef4500..35cd45d7 100644 --- a/vllm-model-provider/go.sum +++ b/vllm-model-provider/go.sum @@ -1,2 +1,2 @@ -github.com/gptscript-ai/chat-completion-client v0.0.0-20241127005108-02b41e1cd02e h1:Nj9709xPbjAPLOsdR/Ik4zaJfpU4O6AEP/R6o9h30CE= -github.com/gptscript-ai/chat-completion-client v0.0.0-20241127005108-02b41e1cd02e/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo= +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 h1:rfriXe+FFqZ5fZ+wGzLUivrq7Fyj2xfRdZjDsHf6Ps0= +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo= diff --git a/xai-model-provider/go.mod b/xai-model-provider/go.mod index 1645373a..1787bd0b 100644 --- a/xai-model-provider/go.mod +++ b/xai-model-provider/go.mod @@ -5,3 +5,5 @@ go 1.23.4 replace github.com/obot-platform/tools/openai-model-provider => ../openai-model-provider require github.com/obot-platform/tools/openai-model-provider v0.0.0 + +require github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 // indirect diff --git a/xai-model-provider/go.sum b/xai-model-provider/go.sum index e69de29b..35cd45d7 100644 --- a/xai-model-provider/go.sum +++ b/xai-model-provider/go.sum @@ -0,0 +1,2 @@ +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789 h1:rfriXe+FFqZ5fZ+wGzLUivrq7Fyj2xfRdZjDsHf6Ps0= +github.com/gptscript-ai/chat-completion-client v0.0.0-20250123123106-c86554320789/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo= From ad2433315117270d1b161a97f3fcbb2313f0f518 Mon Sep 17 00:00:00 2001 From: Daishan Peng Date: Fri, 24 Jan 2025 10:42:36 -0700 Subject: [PATCH 3/6] Add proxy change to return o1 response as SSE events --- openai-model-provider/proxy/proxy.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/openai-model-provider/proxy/proxy.go b/openai-model-provider/proxy/proxy.go index a1e4dc3b..25a971c0 100644 --- a/openai-model-provider/proxy/proxy.go +++ b/openai-model-provider/proxy/proxy.go @@ -9,6 +9,12 @@ import ( "strings" ) +var ( + openaiBaseHostName = "api.openai.com" + + chatCompletionsPath = "/v1/chat/completions" +) + type Config struct { url *url.URL @@ -66,6 +72,25 @@ func Run(cfg *Config) error { if err := cfg.ensureURL(); err != nil { return fmt.Errorf("failed to ensure URL: %w", err) } +<<<<<<< HEAD +======= + if cfg.UpstreamHost == "" { + cfg.UpstreamHost = openaiBaseHostName + cfg.UseTLS = true + } + + // Remove any scheme prefix from UpstreamHost if present + if strings.HasPrefix(cfg.UpstreamHost, "http://") { + cfg.UpstreamHost = strings.TrimPrefix(cfg.UpstreamHost, "http://") + cfg.UseTLS = false + } else if strings.HasPrefix(cfg.UpstreamHost, "https://") { + cfg.UpstreamHost = strings.TrimPrefix(cfg.UpstreamHost, "https://") + cfg.UseTLS = true + } + + // Remove any trailing slashes from UpstreamHost + cfg.UpstreamHost = strings.TrimRight(cfg.UpstreamHost, "/") +>>>>>>> 5a2759d (Add proxy change to return o1 response as SSE events) if cfg.RewriteModelsFn == nil { cfg.RewriteModelsFn = DefaultRewriteModelsResponse From 96e4ba3570ba6167762af67eb468f6e49fcbe34d Mon Sep 17 00:00:00 2001 From: Daishan Peng Date: Wed, 29 Jan 2025 09:28:51 -0700 Subject: [PATCH 4/6] Address donnie's comment Signed-off-by: Daishan Peng --- openai-model-provider/main.go | 9 ++ openai-model-provider/openaiproxy/proxy.go | 135 +++++++++++++++++++++ openai-model-provider/proxy/proxy.go | 35 ++---- openai-model-provider/proxy/validate.go | 2 +- 4 files changed, 153 insertions(+), 28 deletions(-) create mode 100644 openai-model-provider/openaiproxy/proxy.go diff --git a/openai-model-provider/main.go b/openai-model-provider/main.go index b5f2913d..78719045 100644 --- a/openai-model-provider/main.go +++ b/openai-model-provider/main.go @@ -2,8 +2,10 @@ package main import ( "fmt" + "net/http/httputil" "os" + "github.com/obot-platform/tools/openai-model-provider/openaiproxy" "github.com/obot-platform/tools/openai-model-provider/proxy" ) @@ -27,6 +29,13 @@ func main() { Name: "OpenAI", } + openaiProxy := openaiproxy.NewServer(cfg) + reverseProxy := &httputil.ReverseProxy{ + Director: openaiProxy.Openaiv1ProxyRedirect, + ModifyResponse: openaiProxy.ModifyResponse, + } + cfg.CustomPathHandleFuncs["/v1/"] = reverseProxy.ServeHTTP + if len(os.Args) > 1 && os.Args[1] == "validate" { if err := cfg.Validate("/tools/openai-model-provider/validate"); err != nil { os.Exit(1) diff --git a/openai-model-provider/openaiproxy/proxy.go b/openai-model-provider/openaiproxy/proxy.go new file mode 100644 index 00000000..63df1dac --- /dev/null +++ b/openai-model-provider/openaiproxy/proxy.go @@ -0,0 +1,135 @@ +package openaiproxy + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "net/http" + "strings" + + openai "github.com/gptscript-ai/chat-completion-client" + "github.com/obot-platform/tools/openai-model-provider/proxy" +) + +type Server struct { + cfg *proxy.Config +} + +func NewServer(cfg *proxy.Config) *Server { + return &Server{cfg: cfg} +} + +func (s *Server) Openaiv1ProxyRedirect(req *http.Request) { + req.URL.Scheme = s.cfg.Url.Scheme + req.URL.Host = s.cfg.Url.Host + req.URL.Path = s.cfg.Url.JoinPath(strings.TrimPrefix(req.URL.Path, "/v1")).Path // join baseURL with request path - /v1 must be part of baseURL if it's needed + req.Host = req.URL.Host + + req.Header.Set("Authorization", "Bearer "+s.cfg.APIKey) + + if req.Body == nil || s.cfg.Url.Host != proxy.OpenaiBaseHostName || req.URL.Path != proxy.ChatCompletionsPath { + return + } + + bodyBytes, err := io.ReadAll(req.Body) + if err != nil { + fmt.Println("failed to read request body, error: ", err.Error()) + return + } + + var reqBody openai.ChatCompletionRequest + if err := json.Unmarshal(bodyBytes, &reqBody); err == nil && isModelO1(reqBody.Model) { + if err := modifyRequestBodyForO1(req, &reqBody); err != nil { + fmt.Println("failed to modify request body for o1, error: ", err.Error()) + req.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) + } + } else { + req.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) + } +} + +func modifyRequestBodyForO1(req *http.Request, reqBody *openai.ChatCompletionRequest) error { + reqBody.Stream = false + reqBody.Temperature = nil + for i, msg := range reqBody.Messages { + if msg.Role == "system" { + reqBody.Messages[i].Role = "developer" + } + } + modifiedBodyBytes, err := json.Marshal(reqBody) + if err != nil { + return fmt.Errorf("failed to marshal request body after modification: %w", err) + } + req.Body = io.NopCloser(bytes.NewBuffer(modifiedBodyBytes)) + req.ContentLength = int64(len(modifiedBodyBytes)) + req.Header.Set("Accept", "application/json") + req.Header.Set("Accept-Encoding", "") + req.Header.Set("Content-Type", "application/json") + return nil +} + +func (s *Server) ModifyResponse(resp *http.Response) error { + if resp.StatusCode != http.StatusOK || resp.Request.URL.Path != proxy.ChatCompletionsPath || resp.Request.URL.Host != proxy.OpenaiBaseHostName { + return nil + } + + if resp.Header.Get("Content-Type") == "application/json" { + rawBody, err := io.ReadAll(resp.Body) + if err != nil { + resp.Body.Close() + return fmt.Errorf("failed to read response body: %w", err) + } + resp.Body.Close() + var respBody openai.ChatCompletionResponse + if err := json.Unmarshal(rawBody, &respBody); err == nil && isModelO1(respBody.Model) { + // Convert non-streaming response to a single SSE for o1 model + streamResponse := openai.ChatCompletionStreamResponse{ + ID: respBody.ID, + Object: respBody.Object, + Created: respBody.Created, + Model: respBody.Model, + Usage: respBody.Usage, + Choices: func() []openai.ChatCompletionStreamChoice { + var choices []openai.ChatCompletionStreamChoice + for _, choice := range respBody.Choices { + choices = append(choices, openai.ChatCompletionStreamChoice{ + Index: choice.Index, + Delta: openai.ChatCompletionStreamChoiceDelta{ + Content: choice.Message.Content, + Role: choice.Message.Role, + FunctionCall: choice.Message.FunctionCall, + ToolCalls: choice.Message.ToolCalls, + }, + FinishReason: choice.FinishReason, + }) + } + return choices + }(), + } + + sseData, err := json.Marshal(streamResponse) + if err != nil { + return fmt.Errorf("failed to marshal stream response: %w", err) + } + + sseFormattedData := fmt.Sprintf("data: %s\n\nevent: close\ndata: [DONE]\n\n", sseData) + + resp.Header.Set("Content-Type", "text/event-stream") + resp.Header.Set("Cache-Control", "no-cache") + resp.Header.Set("Connection", "keep-alive") + resp.Body = io.NopCloser(bytes.NewBufferString(sseFormattedData)) + } else { + resp.Body = io.NopCloser(bytes.NewBuffer(rawBody)) + } + } + + return nil +} + +func isModelO1(model string) bool { + if model == "o1" { + return true + } + return strings.HasPrefix(model, "o1-") && !strings.HasPrefix(model, "o1-mini") && !strings.HasPrefix(model, "o1-preview") +} diff --git a/openai-model-provider/proxy/proxy.go b/openai-model-provider/proxy/proxy.go index 25a971c0..2857b984 100644 --- a/openai-model-provider/proxy/proxy.go +++ b/openai-model-provider/proxy/proxy.go @@ -10,13 +10,13 @@ import ( ) var ( - openaiBaseHostName = "api.openai.com" + OpenaiBaseHostName = "api.openai.com" - chatCompletionsPath = "/v1/chat/completions" + ChatCompletionsPath = "/v1/chat/completions" ) type Config struct { - url *url.URL + Url *url.URL // ListenPort is the port the proxy server listens on ListenPort string @@ -45,7 +45,7 @@ type server struct { } func (cfg *Config) ensureURL() error { - if cfg.url != nil { + if cfg.Url != nil { return nil } @@ -64,7 +64,7 @@ func (cfg *Config) ensureURL() error { } } - cfg.url = u + cfg.Url = u return nil } @@ -72,25 +72,6 @@ func Run(cfg *Config) error { if err := cfg.ensureURL(); err != nil { return fmt.Errorf("failed to ensure URL: %w", err) } -<<<<<<< HEAD -======= - if cfg.UpstreamHost == "" { - cfg.UpstreamHost = openaiBaseHostName - cfg.UseTLS = true - } - - // Remove any scheme prefix from UpstreamHost if present - if strings.HasPrefix(cfg.UpstreamHost, "http://") { - cfg.UpstreamHost = strings.TrimPrefix(cfg.UpstreamHost, "http://") - cfg.UseTLS = false - } else if strings.HasPrefix(cfg.UpstreamHost, "https://") { - cfg.UpstreamHost = strings.TrimPrefix(cfg.UpstreamHost, "https://") - cfg.UseTLS = true - } - - // Remove any trailing slashes from UpstreamHost - cfg.UpstreamHost = strings.TrimRight(cfg.UpstreamHost, "/") ->>>>>>> 5a2759d (Add proxy change to return o1 response as SSE events) if cfg.RewriteModelsFn == nil { cfg.RewriteModelsFn = DefaultRewriteModelsResponse @@ -144,9 +125,9 @@ func (s *server) healthz(w http.ResponseWriter, _ *http.Request) { } func (s *server) proxyDirector(req *http.Request) { - req.URL.Scheme = s.cfg.url.Scheme - req.URL.Host = s.cfg.url.Host - req.URL.Path = s.cfg.url.JoinPath(strings.TrimPrefix(req.URL.Path, "/v1")).Path // join baseURL with request path - /v1 must be part of baseURL if it's needed + req.URL.Scheme = s.cfg.Url.Scheme + req.URL.Host = s.cfg.Url.Host + req.URL.Path = s.cfg.Url.JoinPath(strings.TrimPrefix(req.URL.Path, "/v1")).Path // join baseURL with request path - /v1 must be part of baseURL if it's needed req.Host = req.URL.Host req.Header.Set("Authorization", "Bearer "+s.cfg.APIKey) diff --git a/openai-model-provider/proxy/validate.go b/openai-model-provider/proxy/validate.go index 768a93a4..a21635bd 100644 --- a/openai-model-provider/proxy/validate.go +++ b/openai-model-provider/proxy/validate.go @@ -20,7 +20,7 @@ func (cfg *Config) Validate(toolPath string) error { return fmt.Errorf("failed to ensure URL: %w", err) } - url := cfg.url.JoinPath("/models") + url := cfg.Url.JoinPath("/models") req, err := http.NewRequest("GET", url.String(), nil) if err != nil { From 46eee43b2908ffa2ed8d0d2ab7a308f89b43b3bb Mon Sep 17 00:00:00 2001 From: Daishan Peng Date: Wed, 29 Jan 2025 10:42:58 -0700 Subject: [PATCH 5/6] Use custom path Signed-off-by: Daishan Peng --- openai-model-provider/main.go | 12 +++++++----- openai-model-provider/proxy/proxy.go | 20 +++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/openai-model-provider/main.go b/openai-model-provider/main.go index 78719045..55376969 100644 --- a/openai-model-provider/main.go +++ b/openai-model-provider/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "net/http" "net/http/httputil" "os" @@ -22,11 +23,12 @@ func main() { } cfg := &proxy.Config{ - APIKey: apiKey, - ListenPort: port, - BaseURL: "https://api.openai.com/v1", - RewriteModelsFn: proxy.DefaultRewriteModelsResponse, - Name: "OpenAI", + APIKey: apiKey, + ListenPort: port, + BaseURL: "https://api.openai.com/v1", + RewriteModelsFn: proxy.DefaultRewriteModelsResponse, + Name: "OpenAI", + CustomPathHandleFuncs: map[string]http.HandlerFunc{}, } openaiProxy := openaiproxy.NewServer(cfg) diff --git a/openai-model-provider/proxy/proxy.go b/openai-model-provider/proxy/proxy.go index 2857b984..61832d10 100644 --- a/openai-model-provider/proxy/proxy.go +++ b/openai-model-provider/proxy/proxy.go @@ -87,25 +87,31 @@ func Run(cfg *Config) error { mux := http.NewServeMux() - // Register custom path handlers first - for path, handler := range cfg.CustomPathHandleFuncs { - mux.HandleFunc(path, handler) - } - // Register default handlers only if they are not already registered if _, exists := cfg.CustomPathHandleFuncs["/{$}"]; !exists { mux.HandleFunc("/{$}", s.healthz) } - if _, exists := cfg.CustomPathHandleFuncs["/v1/models"]; !exists { + if handler, exists := cfg.CustomPathHandleFuncs["/v1/models"]; !exists { mux.Handle("/v1/models", &httputil.ReverseProxy{ Director: s.proxyDirector, ModifyResponse: cfg.RewriteModelsFn, }) + } else { + mux.HandleFunc("/v1/models", handler) } - if _, exists := cfg.CustomPathHandleFuncs["/v1/"]; !exists { + if handler, exists := cfg.CustomPathHandleFuncs["/v1/"]; !exists { mux.Handle("/v1/", &httputil.ReverseProxy{ Director: s.proxyDirector, }) + } else { + mux.HandleFunc("/v1/", handler) + } + + for path, handler := range cfg.CustomPathHandleFuncs { + if path == "/v1/models" || path == "/v1/" { + continue + } + mux.HandleFunc(path, handler) } httpServer := &http.Server{ From 27cf37ca3bf9401613506c734c43b689bc1d25c3 Mon Sep 17 00:00:00 2001 From: Daishan Peng Date: Thu, 30 Jan 2025 16:31:45 -0700 Subject: [PATCH 6/6] Address comment Signed-off-by: Daishan Peng --- openai-model-provider/openaiproxy/proxy.go | 8 ++++---- openai-model-provider/proxy/proxy.go | 12 ++++++------ openai-model-provider/proxy/validate.go | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/openai-model-provider/openaiproxy/proxy.go b/openai-model-provider/openaiproxy/proxy.go index 63df1dac..1a47fe90 100644 --- a/openai-model-provider/openaiproxy/proxy.go +++ b/openai-model-provider/openaiproxy/proxy.go @@ -21,14 +21,14 @@ func NewServer(cfg *proxy.Config) *Server { } func (s *Server) Openaiv1ProxyRedirect(req *http.Request) { - req.URL.Scheme = s.cfg.Url.Scheme - req.URL.Host = s.cfg.Url.Host - req.URL.Path = s.cfg.Url.JoinPath(strings.TrimPrefix(req.URL.Path, "/v1")).Path // join baseURL with request path - /v1 must be part of baseURL if it's needed + req.URL.Scheme = s.cfg.URL.Scheme + req.URL.Host = s.cfg.URL.Host + req.URL.Path = s.cfg.URL.JoinPath(strings.TrimPrefix(req.URL.Path, "/v1")).Path // join baseURL with request path - /v1 must be part of baseURL if it's needed req.Host = req.URL.Host req.Header.Set("Authorization", "Bearer "+s.cfg.APIKey) - if req.Body == nil || s.cfg.Url.Host != proxy.OpenaiBaseHostName || req.URL.Path != proxy.ChatCompletionsPath { + if req.Body == nil || s.cfg.URL.Host != proxy.OpenaiBaseHostName || req.URL.Path != proxy.ChatCompletionsPath { return } diff --git a/openai-model-provider/proxy/proxy.go b/openai-model-provider/proxy/proxy.go index 61832d10..18a42ba0 100644 --- a/openai-model-provider/proxy/proxy.go +++ b/openai-model-provider/proxy/proxy.go @@ -16,7 +16,7 @@ var ( ) type Config struct { - Url *url.URL + URL *url.URL // ListenPort is the port the proxy server listens on ListenPort string @@ -45,7 +45,7 @@ type server struct { } func (cfg *Config) ensureURL() error { - if cfg.Url != nil { + if cfg.URL != nil { return nil } @@ -64,7 +64,7 @@ func (cfg *Config) ensureURL() error { } } - cfg.Url = u + cfg.URL = u return nil } @@ -131,9 +131,9 @@ func (s *server) healthz(w http.ResponseWriter, _ *http.Request) { } func (s *server) proxyDirector(req *http.Request) { - req.URL.Scheme = s.cfg.Url.Scheme - req.URL.Host = s.cfg.Url.Host - req.URL.Path = s.cfg.Url.JoinPath(strings.TrimPrefix(req.URL.Path, "/v1")).Path // join baseURL with request path - /v1 must be part of baseURL if it's needed + req.URL.Scheme = s.cfg.URL.Scheme + req.URL.Host = s.cfg.URL.Host + req.URL.Path = s.cfg.URL.JoinPath(strings.TrimPrefix(req.URL.Path, "/v1")).Path // join baseURL with request path - /v1 must be part of baseURL if it's needed req.Host = req.URL.Host req.Header.Set("Authorization", "Bearer "+s.cfg.APIKey) diff --git a/openai-model-provider/proxy/validate.go b/openai-model-provider/proxy/validate.go index a21635bd..30e55f5d 100644 --- a/openai-model-provider/proxy/validate.go +++ b/openai-model-provider/proxy/validate.go @@ -20,7 +20,7 @@ func (cfg *Config) Validate(toolPath string) error { return fmt.Errorf("failed to ensure URL: %w", err) } - url := cfg.Url.JoinPath("/models") + url := cfg.URL.JoinPath("/models") req, err := http.NewRequest("GET", url.String(), nil) if err != nil {