Skip to content

Commit f8397c4

Browse files
authored
Merge pull request #2 from trentmillar/feat/client_config
feature, openai clientconfig handles azure openai
2 parents 5c58685 + 2415925 commit f8397c4

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
# ide
2+
.vscode/
3+
.idea/
4+
15
example/memory
26
example/workspace

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,26 @@ GPT Engineer is made to be easy to adapt, extend, and make your agent learn how
2020

2121
## Usage
2222

23-
**Setup**:
23+
### Setup:
2424

25+
**OpenAI**
2526
- `go mod tidy`
2627
- `export OPENAI_API_KEY=[your api key]` with a key that has GPT4 access, if you don't have GPT4 access, then it will use GPT-3.5 as a fallback.
2728

28-
**Run**:
29+
**Azure**
30+
- `export OPENAI_BASE=[your Azure OpenAI endpoint]` should be _https://[deployment name].openai.azure.com/_
31+
32+
### Run:
2933
- Edit `example/main_prompt` to specify what you want to build
3034
- Run `go run .`, default language is English, if you want to use other language, and `-lang` argument like `go run . -lang=Chinese`
3135

32-
**Results**:
36+
**(optional) Azure**
37+
- use the argument `-model [your deployment name]`
38+
39+
### Results:
3340
- Check the generated files in `example/workspace`
3441

35-
### Limitations
42+
## Limitations
3643

3744
Implementing additional chain of thought prompting, e.g. [Reflexion](https://github.com/noahshinn024/reflexion), should be able to make it more reliable and not miss requested functionality in the main prompt.
3845

ai.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,23 @@ type AI struct {
2424
}
2525

2626
func NewAI(model string, temperature float64, lang string) *AI {
27-
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
27+
var clientConfig openai.ClientConfig
28+
apiKey := os.Getenv("OPENAI_API_KEY")
29+
apiBase := os.Getenv("OPENAI_API_BASE")
30+
if apiBase == "" {
31+
clientConfig = openai.DefaultConfig(apiKey)
32+
} else {
33+
clientConfig = openai.DefaultAzureConfig(apiKey, apiBase)
34+
}
35+
client := openai.NewClientWithConfig(clientConfig)
2836
ai := &AI{model: model, client: client, temperature: temperature, lang: lang}
29-
_, err := client.GetModel(context.Background(), "gpt-4")
37+
38+
// Azure uses deployments and is not exposed in the openai api so model is assumed to be okay
39+
if clientConfig.APIType == openai.APITypeAzure {
40+
return ai
41+
}
42+
43+
_, err := client.GetModel(context.Background(), model)
3044
if err != nil {
3145
fmt.Println("Model gpt-4 not available for provided api key reverting to gpt-3.5.turbo. Sign up for the gpt-4 wait list here: https://openai.com/waitlist/gpt-4-api")
3246
ai.model = "gpt-3.5-turbo"

0 commit comments

Comments
 (0)