This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
When you build apps connected to Azure OpenAI, often, only a portion of the app interacts with the Azure OpenAI API. When you work on the portions of the app that don't require real replies from Azure OpenAI API, you can simulate the responses using Dev Proxy. Using simulated responses allows you to avoid incurring unnecessary costs. TheOpenAIMockResponsePlugin
uses a local language model running on your machine to simulate responses from Azure OpenAI API.
To simulate Azure OpenAI API responses using Dev Proxy, you need asupported language model client installed on your machine.
By default, Dev Proxy uses the llama3.2 language model running on Ollama. To use a different client or model, update thelanguage model settings in the Dev Proxy configuration file.
Tip
Steps described in this tutorial are available in a ready-to-use Dev Proxy preset. To use the preset, in command line, rundevproxy config get simulate-azure-openai
, and follow the instructions.
To simulate Azure OpenAI API responses using Dev Proxy, you need to enable theOpenAIMockResponsePlugin
in thedevproxyrc.json
file.
{ "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.2/rc.schema.json", "plugins": [ { "name": "OpenAIMockResponsePlugin", "enabled": true, "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll" } ]}
Next, configure Dev Proxy to intercept requests to Azure OpenAI API. For simplicity, use wildcards to intercept requests to all deployments.
{ // [...] trimmed for brevity "urlsToWatch": [ "https://*.openai.azure.com/openai/deployments/*/completions*" ]}
Finally, configure Dev Proxy to use a local language model.
{ // [...] trimmed for brevity "languageModel": { "enabled": true }}
The complete configuration file looks like this.
{ "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.2/rc.schema.json", "plugins": [ { "name": "OpenAIMockResponsePlugin", "enabled": true, "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll" } ], "urlsToWatch": [ "https://*.openai.azure.com/openai/deployments/*/completions*" ], "languageModel": { "enabled": true }}
Assuming the default configuration, start Ollama with the llama3.2 language model. In the command line, runollama run llama3.2
.
Next, start Dev Proxy. If you use the preset, rundevproxy -c "~appFolder/config/simulate-azure-openai/simulate-azure-openai.json
. If you use a custom configuration file nameddevproxyrc.json
, stored in the current working directory, rundevproxy
. Dev Proxy checks that it can access the language model on Ollama and confirms that it's ready to simulate Azure OpenAI API responses.
info OpenAIMockResponsePlugin: Checking language model availability... info Listening on 127.0.0.1:8000...Hotkeys: issue (w)eb request, (r)ecord, (s)top recording, (c)lear screenPress CTRL+C to stop Dev Proxy
Run your application and make requests to the Azure OpenAI API. Dev Proxy intercepts the requests and simulates responses using the local language model.
Learn more about the OpenAIMockResponsePlugin.
See also the related Dev Proxy samples:
Was this page helpful?
Was this page helpful?