Skip to content

Commit a149858

Browse files
David BarkolDavid Barkol
authored andcommitted
api management snippets for openai plugin
1 parent a5baddd commit a149858

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--
2+
This returns a OpenAPI specification for an API.
3+
-->
4+
<policies>
5+
<inbound>
6+
<base />
7+
<send-request mode="new" response-variable-name="result" timeout="300" ignore-error="false">
8+
<set-url>@("https://management.azure.com/subscriptions/{{subscription-id}}/resourceGroups/{{resource-group-name}}/providers/Microsoft.ApiManagement/service/{{service-id}}/apis/" + context.Api.Id + "?export=true&format=openapi&api-version=2022-09-01-preview")</set-url>
9+
<set-method>GET</set-method>
10+
<authentication-managed-identity resource="https://management.azure.com/" />
11+
</send-request>
12+
<return-response>
13+
<set-status code="200" reason="OK" />
14+
<set-header name="Content-Type" exists-action="override">
15+
<value>application/yaml</value>
16+
</set-header>
17+
<set-body>@((string)(((IResponse)context.Variables["result"]).Body.As<JObject>()["value"]))</set-body>
18+
</return-response>
19+
</inbound>
20+
<backend>
21+
<base />
22+
</backend>
23+
<outbound>
24+
<base />
25+
</outbound>
26+
<on-error>
27+
<base />
28+
</on-error>
29+
</policies>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!--
2+
This supports the wellknown endpoint for a OpenAI plugin.
3+
-->
4+
<policies>
5+
<inbound>
6+
<base />
7+
<return-response>
8+
<set-status code="200" reason="OK" />
9+
<set-header name="Content-Type" exists-action="override">
10+
<value>application/json</value>
11+
</set-header>
12+
<set-body>@{
13+
14+
var apiInfo = new JObject();
15+
16+
// Metadata
17+
apiInfo.Add("schema_version","v1");
18+
apiInfo.Add("name_for_human","Miyagi calculator");
19+
apiInfo.Add("name_for_model","calculator");
20+
apiInfo.Add("description_for_human","Perform arithmetic operations");
21+
apiInfo.Add("description_for_model", "Use the Calculator plugin to perform basic arithmetic operations");
22+
apiInfo.Add("contact_email", "frank@rizzo.com");
23+
apiInfo.Add("logo_url", "https://raw.githubusercontent.com/Azure-Samples/miyagi/main/assets/images/1.png");
24+
apiInfo.Add("legal_info_url", "http://example.com/legal");
25+
26+
// Auth
27+
var authType = new JObject();
28+
authType.Add("type", "none");
29+
apiInfo.Add("auth", authType);
30+
31+
// API
32+
var apiDetails = new JObject();
33+
apiDetails.Add("type", "openapi");
34+
apiDetails.Add("url", "https://{{apim-service-name}}.azure-api.net/openai.yaml");
35+
apiInfo.Add("api", apiDetails);
36+
37+
return apiInfo.ToString();
38+
39+
}</set-body>
40+
</return-response>
41+
</inbound>
42+
<backend>
43+
<base />
44+
</backend>
45+
<outbound>
46+
<base />
47+
</outbound>
48+
<on-error>
49+
<base />
50+
</on-error>
51+
</policies>

0 commit comments

Comments
 (0)