Skip to content

Commit ea1691a

Browse files
authored
fix: generic azure model support (#119)
1 parent ecd4f4d commit ea1691a

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/docs/yarn.lock
88
/releases
99
/checksums.txt
10+
/.env*

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ calls. With GPTScript you can do just about anything, like [plan a vacation](./e
1010
[edit a file](./examples/add-go-mod-dep.gpt), [run some SQL](./examples/sqlite-download.gpt), or [build a mongodb/flask app](./examples/hacker-news-headlines.gpt).
1111

1212
| :memo: | We are currently exploring options for interacting with local models using GPTScript. |
13-
|-|:-|
13+
| ------ | :------------------------------------------------------------------------------------ |
1414

1515
```yaml
1616
# example.gpt
@@ -28,15 +28,18 @@ the result of that.
2828

2929
When done remove the database file and the downloaded content.
3030
```
31+
3132
```shell
3233
$ gptscript ./example.gpt
3334
```
35+
3436
```
3537
OUTPUT:
3638
3739
The artist with the most number of albums in the database is Iron Maiden, with a total
3840
of 21 albums.
3941
```
42+
4043
## Quick Start
4144

4245
### 1. Install the latest release
@@ -98,16 +101,21 @@ $env:OPENAI = 'your-api-key'
98101
```shell
99102
gptscript https://get.gptscript.ai/echo.gpt --input 'Hello, World!'
100103
```
104+
101105
```
102106
OUTPUT:
103107
104108
Hello, World!
105109
```
110+
106111
The model used by default is `gpt-4-turbo-preview` and you must have access to that model in your OpenAI account.
107112

113+
If using Azure OpenAI, make sure you configure the model to be one of the supported versions with the `--default-model` argument.
114+
108115
### 4. Extra Credit: Examples and Run Debugging UI
109116

110117
Clone examples and run debugging UI
118+
111119
```shell
112120
git clone https://github.com/gptscript-ai/gptscript
113121
cd gptscript/examples
@@ -118,13 +126,14 @@ gptscript --server
118126

119127
## How it works
120128

121-
***GPTScript is composed of tools.*** Each tool performs a series of actions similar to a function. Tools have available
129+
**_GPTScript is composed of tools._** Each tool performs a series of actions similar to a function. Tools have available
122130
to them other tools that can be invoked similar to a function call. While similar to a function, the tools are
123-
primarily implemented with a natural language prompt. ***The interaction of the tools is determined by the AI model***,
131+
primarily implemented with a natural language prompt. **_The interaction of the tools is determined by the AI model_**,
124132
the model determines if the tool needs to be invoked and what arguments to pass. Tools are intended to be implemented
125133
with a natural language prompt but can also be implemented with a command or HTTP call.
126134

127135
### Example
136+
128137
Below are two tool definitions, separated by `---`. The first tool does not require a name or description, but
129138
every tool after name and description are required. The first tool, has the parameter `tools: bob` meaning that the tool named `bob` is available to be called if needed.
130139

@@ -140,15 +149,19 @@ args: question: The question to ask Bob.
140149

141150
When asked how I am doing, respond with "Thanks for asking "${question}", I'm doing great fellow friendly AI tool!"
142151
```
152+
143153
Put the above content in a file named `bob.gpt` and run the following command:
154+
144155
```shell
145156
$ gptscript bob.gpt
146157
```
158+
147159
```
148160
OUTPUT:
149161
150162
Bob said, "Thanks for asking 'How are you doing?', I'm doing great fellow friendly AI tool!"
151163
```
164+
152165
Tools can be implemented by invoking a program instead of a natural language prompt. The below
153166
example is the same as the previous example but implements Bob using python.
154167

@@ -175,9 +188,11 @@ or external services.
175188
## GPT File Reference
176189

177190
### Extension
191+
178192
GPTScript files use the `.gpt` extension by convention.
179193

180194
### File Structure
195+
181196
A GPTScript file has one or more tools in the file. Each tool is separated by three dashes `---` alone on a line.
182197

183198
```yaml
@@ -210,6 +225,7 @@ Args: arg1: The description of arg1
210225

211226
Tool instructions go here.
212227
```
228+
213229
#### Tool Parameters
214230

215231
Tool parameters are key-value pairs defined at the beginning of a tool block, before any instructional text. They are specified in the format `key: value`. The parser recognizes the following keys (case-insensitive and spaces are ignored):

docs/docs/02-getting-started.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ Download and install the archive for your platform and architecture from the [re
3232
export OPENAI_API_KEY="your-api-key"
3333
```
3434

35+
Alternatively Azure OpenAI can be utilized
36+
37+
```shell
38+
export OPENAI_API_KEY="your-api-key"
39+
export OPENAI_BASE_URL="your-endpiont"
40+
export OPENAI_API_TYPE="AZURE"
41+
export OPENAI_AZURE_DEPLOYMENT="your-deployment-name"
42+
```
43+
3544
#### Windows
3645

3746
```powershell
@@ -47,11 +56,15 @@ OUTPUT:
4756

4857
Hello, World!
4958
```
59+
5060
The model used by default is `gpt-4-turbo-preview` and you must have access to that model in your OpenAI account.
5161

62+
If using Azure OpenAI, make sure you configure the model to be one of the supported versions with the `--default-model` argument.
63+
5264
### 4. Extra Credit: Examples and Run Debugging UI
5365

5466
Clone examples and run debugging UI
67+
5568
```shell
5669
git clone https://github.com/gptscript-ai/gptscript
5770
cd gptscript/examples

pkg/openai/client.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,17 @@ func complete(opts ...Options) (result Options, err error) {
8282
return result, err
8383
}
8484

85-
func AzureMapperFunction(model string) string {
85+
func GetAzureMapperFunction(defaultModel, azureModel string) func(string) string {
8686
if azureModel == "" {
87-
return model
87+
return func(model string) string {
88+
return model
89+
}
90+
}
91+
return func(model string) string {
92+
return map[string]string{
93+
defaultModel: azureModel,
94+
}[model]
8895
}
89-
return map[string]string{
90-
openai.GPT4TurboPreview: azureModel,
91-
}[model]
9296
}
9397

9498
func NewClient(opts ...Options) (*Client, error) {
@@ -100,7 +104,7 @@ func NewClient(opts ...Options) (*Client, error) {
100104
cfg := openai.DefaultConfig(opt.APIKey)
101105
if strings.Contains(string(opt.APIType), "AZURE") {
102106
cfg = openai.DefaultAzureConfig(key, url)
103-
cfg.AzureModelMapperFunc = AzureMapperFunction
107+
cfg.AzureModelMapperFunc = GetAzureMapperFunction(opt.DefaultModel, azureModel)
104108
}
105109

106110
cfg.BaseURL = types.FirstSet(opt.BaseURL, cfg.BaseURL)

0 commit comments

Comments
 (0)