|
| 1 | +# Contributing Guide |
| 2 | + |
| 3 | +> NOTE: these instructions are for fixing or adding features to the `azopenai` module. To use the module refer to the readme for this package: [readme.md](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/ai/azopenai/README.md). |
| 4 | +
|
| 5 | +This is a contributing guide for the `azopenai` package. For general contributing guidelines refer to [CONTRIBUTING.md](https://github.com/Azure/azure-sdk-for-go/blob/main/CONTRIBUTING.md). |
| 6 | + |
| 7 | +The `azopenai` package can be used with either Azure OpenAI or OpenAI's public service. New features are added using our code generation process, specified using TypeSpec [TypeSpec](https://github.com/Microsoft/typespec), which details all the models and protocol methods for using OpenAI. |
| 8 | + |
| 9 | +### Prerequisites |
| 10 | + |
| 11 | +For code fixes that do not require code generation: |
| 12 | +- Go 1.18 (or greater) |
| 13 | + |
| 14 | +For code generation: |
| 15 | +- [NodeJS (use the latest LTS)](https://nodejs.org) |
| 16 | +- [TypeSpec compiler](https://github.com/Microsoft/typespec#getting-started). |
| 17 | +- [autorest](https://github.com/Azure/autorest/tree/main/packages/apps/autorest) |
| 18 | +- [PowerShell Core](https://github.com/PowerShell/PowerShell#get-powershell) |
| 19 | +- [goimports](https://pkg.go.dev/golang.org/x/tools/cmd/goimports) |
| 20 | + |
| 21 | +# Building |
| 22 | + |
| 23 | +## Generating from TypeSpec |
| 24 | + |
| 25 | +The `Client` is primarily generated from TypeSpec, with some handwritten code where we've changed the interface to match Azure naming conventions (for instance, we refer to Models as Deployments). Files that do not have `custom` (ex: `client.go`, `models.go`, `models_serde.go`, etc..) are generated. |
| 26 | + |
| 27 | +Files that have `custom` in the name are handwritten (ex: `custom_client_audio.go`), while files that do not (ex: `client.go`, `models.go`, `models_serde.go`, etc..) are generated. |
| 28 | + |
| 29 | +### Regeneration |
| 30 | + |
| 31 | +The `testdata/tsp-location.yaml` specifies the specific revision (and repo) that we use to generate the client. This also makes it possible, if needed, to generate from branch commmits in [`Azure/azure-rest-api-specs`](https://github.com/Azure/azure-rest-api-specs). |
| 32 | + |
| 33 | +**tsp.location.yaml**: |
| 34 | +```yaml |
| 35 | +# ie: https://github.com/Azure/azure-rest-api-specs/tree/1e243e2b0d0d006599dcb64f82fd92aecc1247be/specification/cognitiveservices/OpenAI.Inference |
| 36 | +directory: specification/cognitiveservices/OpenAI.Inference |
| 37 | +commit: 1e243e2b0d0d006599dcb64f82fd92aecc1247be |
| 38 | +repo: Azure/azure-rest-api-specs |
| 39 | +``` |
| 40 | +The generation process is all done as `go generate` commands in `build.go`. To regenerate the client run: |
| 41 | + |
| 42 | +``` |
| 43 | +go generate ./... |
| 44 | +``` |
| 45 | +
|
| 46 | +Commit the generated changes as part of your pull request. |
| 47 | +
|
| 48 | +If the changes don't look quite right you can adjust the generated code using the `autorest.md` file. |
| 49 | +
|
| 50 | +# Testing |
| 51 | +
|
| 52 | +There are three kinds of tests for this package: unit tests, recorded tests and live tests. |
| 53 | +
|
| 54 | +## Unit and recorded tests |
| 55 | +
|
| 56 | +Unit tests and recorded tests do not require access to OpenAI to run and will run with any PR as a check-in gate. |
| 57 | +
|
| 58 | +Recorded tests require the Azure SDK test proxy is running. See the instructions for [installing the test-proxy](https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md#installation). |
| 59 | +
|
| 60 | +In one terminal window, start the test-proxy: |
| 61 | +
|
| 62 | +```bash |
| 63 | +cd <root of the azopenai module> |
| 64 | +test-proxy |
| 65 | +``` |
| 66 | + |
| 67 | +In another terminal window: |
| 68 | + |
| 69 | + |
| 70 | +To playback (ie: use recordings): |
| 71 | +```bash |
| 72 | +cd <root of the azopenai module> |
| 73 | + |
| 74 | +export AZURE_RECORD_MODE=playback |
| 75 | +go test -count 1 -v ./... |
| 76 | +``` |
| 77 | + |
| 78 | +To re-record: |
| 79 | +```bash |
| 80 | +cd <root of the azopenai module> |
| 81 | + |
| 82 | +export AZURE_RECORD_MODE=record |
| 83 | +go test -count 1 -v ./... |
| 84 | + |
| 85 | +# push the recording changes to the repo |
| 86 | +test-proxy push -a assets.json |
| 87 | + |
| 88 | +# commit our assets.json file now that it points |
| 89 | +# to the new recordings. |
| 90 | +git add assets.json |
| 91 | +git commit -m "updated recordings" |
| 92 | +git push |
| 93 | +``` |
| 94 | + |
| 95 | +## Live tests |
| 96 | + |
| 97 | +### Local development |
| 98 | + |
| 99 | +Copy the `sample.env` file to `.env`, and fill out all the values. Each value is documented to give you a general idea of what's needed, but ultimately you'll need to work with the Azure OpenAI SDK team to figure out which services are used for which features. |
| 100 | + |
| 101 | +Once filled out, the tests will automatically load environment variables from the `.env`: |
| 102 | + |
| 103 | +```bash |
| 104 | +export AZURE_RECORD_MODE=live |
| 105 | +go test -count 1 -v ./... |
| 106 | +``` |
| 107 | + |
| 108 | +### Pull requests |
| 109 | + |
| 110 | +Post a comment to your PR with this text: |
| 111 | + |
| 112 | +``` |
| 113 | +/azp run go - azopenai |
| 114 | +``` |
| 115 | + |
| 116 | +The build bot will post a comment indicating its started the pipeline and the checks will start showing up in the status for the PR as well. |
0 commit comments