Skip to content

Commit 032ae05

Browse files
author
ricwilson
committed
fix: Update GetOperationIdAsync and GetOperationDescriptionAsync methods to use prompt file parameter and improve method visibility
1 parent 7b5df25 commit 032ae05

File tree

2 files changed

+23
-32
lines changed

2 files changed

+23
-32
lines changed

DevProxy.Plugins/Generation/OpenApiSpecGeneratorPlugin.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,25 +235,30 @@ protected virtual Task ProcessOpenApiDocumentAsync(OpenApiDocument openApiDoc)
235235
return Task.CompletedTask;
236236
}
237237

238-
private async Task<string> GetOperationIdAsync(string method, string serverUrl, string parametrizedPath)
238+
protected virtual async Task<string> GetOperationIdAsync(string method, string serverUrl, string parametrizedPath, string promptyFile = "api_operation_id")
239239
{
240+
ArgumentException.ThrowIfNullOrEmpty(method);
241+
ArgumentException.ThrowIfNullOrEmpty(parametrizedPath);
242+
240243
ILanguageModelCompletionResponse? id = null;
241244
if (await languageModelClient.IsEnabledAsync())
242245
{
243-
id = await languageModelClient.GenerateChatCompletionAsync("api_operation_id", new()
246+
id = await languageModelClient.GenerateChatCompletionAsync(promptyFile, new()
244247
{
245248
{ "request", $"{method.ToUpperInvariant()} {serverUrl}{parametrizedPath}" }
246249
});
247250
}
248251
return id?.Response ?? $"{method}{parametrizedPath.Replace('/', '.')}";
249252
}
250253

251-
private async Task<string> GetOperationDescriptionAsync(string method, string serverUrl, string parametrizedPath)
254+
protected virtual async Task<string> GetOperationDescriptionAsync(string method, string serverUrl, string parametrizedPath, string promptyFile = "api_operation_description")
252255
{
256+
ArgumentException.ThrowIfNullOrEmpty(method);
257+
253258
ILanguageModelCompletionResponse? description = null;
254259
if (await languageModelClient.IsEnabledAsync())
255260
{
256-
description = await languageModelClient.GenerateChatCompletionAsync("api_operation_description", new()
261+
description = await languageModelClient.GenerateChatCompletionAsync(promptyFile, new()
257262
{
258263
{ "request", $"{method.ToUpperInvariant()} {serverUrl}{parametrizedPath}" }
259264
});

DevProxy.Plugins/Generation/PowerPlatformOpenApiSpecGeneratorPlugin.cs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -237,55 +237,41 @@ private void RemoveResponseHeadersIfDisabled(OpenApiPathItem pathItem)
237237
/// <param name="method">The HTTP method.</param>
238238
/// <param name="serverUrl">The server URL.</param>
239239
/// <param name="parametrizedPath">The parametrized path.</param>
240-
/// <returns>The generated operationId.</returns>
241-
private async Task<string> GetOperationIdAsync(string method, string serverUrl, string parametrizedPath)
240+
/// <param name="promptyFile">The prompt file to use for LLM generation.</param>
241+
/// <returns>The generated operation id.</returns>
242+
protected override Task<string> GetOperationIdAsync(string method, string serverUrl, string parametrizedPath, string promptyFile = "powerplatform_api_operation_id")
242243
{
243-
ILanguageModelCompletionResponse? id = null;
244-
if (await _languageModelClient.IsEnabledAsync())
245-
{
246-
id = await _languageModelClient.GenerateChatCompletionAsync("powerplatform_api_operation_id", new()
247-
{
248-
{ "request", $"{method.ToUpper(CultureInfo.InvariantCulture)} {serverUrl}{parametrizedPath}" }
249-
});
250-
}
251-
return id?.Response?.Trim() ?? $"{method}{parametrizedPath.Replace('/', '.')}";
244+
return base.GetOperationIdAsync(method, serverUrl, parametrizedPath, promptyFile);
252245
}
253246

254247
/// <summary>
255-
/// Generates a summary for an OpenAPI operation using LLM or fallback logic.
248+
/// Generates an operationId for an OpenAPI operation using LLM or fallback logic.
256249
/// </summary>
257250
/// <param name="method">The HTTP method.</param>
258251
/// <param name="serverUrl">The server URL.</param>
259252
/// <param name="parametrizedPath">The parametrized path.</param>
260-
/// <returns>The generated summary.</returns>
261-
private async Task<string> GetOperationSummaryAsync(string method, string serverUrl, string parametrizedPath)
253+
/// <param name="promptyFile">The prompt file to use for LLM generation.</param>
254+
/// <returns>The generated operation description.</returns>
255+
protected override Task<string> GetOperationDescriptionAsync(string method, string serverUrl, string parametrizedPath, string promptyFile = "powerplatform_api_operation_description")
262256
{
263-
ILanguageModelCompletionResponse? description = null;
264-
if (await _languageModelClient.IsEnabledAsync())
265-
{
266-
description = await _languageModelClient.GenerateChatCompletionAsync("powerplatform_api_operation_summary", new()
267-
{
268-
{ "request", @$"{method.ToUpper(CultureInfo.InvariantCulture)} {serverUrl}{parametrizedPath}" }
269-
});
270-
}
271-
return description?.Response?.Trim() ?? $"{method} {parametrizedPath}";
257+
return base.GetOperationDescriptionAsync(method, serverUrl, parametrizedPath, promptyFile);
272258
}
273259

274260
/// <summary>
275-
/// Generates a description for an OpenAPI operation using LLM or fallback logic.
261+
/// Generates a summary for an OpenAPI operation using LLM or fallback logic.
276262
/// </summary>
277263
/// <param name="method">The HTTP method.</param>
278264
/// <param name="serverUrl">The server URL.</param>
279265
/// <param name="parametrizedPath">The parametrized path.</param>
280-
/// <returns>The generated description.</returns>
281-
private async Task<string> GetOperationDescriptionAsync(string method, string serverUrl, string parametrizedPath)
266+
/// <returns>The generated summary.</returns>
267+
private async Task<string> GetOperationSummaryAsync(string method, string serverUrl, string parametrizedPath)
282268
{
283269
ILanguageModelCompletionResponse? description = null;
284270
if (await _languageModelClient.IsEnabledAsync())
285271
{
286-
description = await _languageModelClient.GenerateChatCompletionAsync("powerplatform_api_operation_description", new()
272+
description = await _languageModelClient.GenerateChatCompletionAsync("powerplatform_api_operation_summary", new()
287273
{
288-
{ "request", $"{method.ToUpper(CultureInfo.InvariantCulture)} {serverUrl}{parametrizedPath}" }
274+
{ "request", @$"{method.ToUpper(CultureInfo.InvariantCulture)} {serverUrl}{parametrizedPath}" }
289275
});
290276
}
291277
return description?.Response?.Trim() ?? $"{method} {parametrizedPath}";

0 commit comments

Comments
 (0)