Skip to content

Commit b5330d4

Browse files
Fixes using local language model in OpenApiSpecGeneratorPlugin. Closes #810 (#813)
1 parent 8c37bbe commit b5330d4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

dev-proxy-plugins/RequestLogs/OpenApiSpecGeneratorPlugin.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,20 @@ private string GetLastNonTokenSegment(string[] segments)
451451
private async Task<string> GetOperationId(string method, string serverUrl, string parametrizedPath)
452452
{
453453
var prompt = $"For the specified request, generate an operation ID, compatible with an OpenAPI spec. Respond with just the ID in plain-text format. For example, for request such as `GET https://api.contoso.com/books/{{books-id}}` you return `getBookById`. For a request like `GET https://api.contoso.com/books/{{books-id}}/authors` you return `getAuthorsForBookById`. Request: {method.ToUpper()} {serverUrl}{parametrizedPath}";
454-
var id = await Context.LanguageModelClient.GenerateCompletion(prompt);
454+
ILanguageModelCompletionResponse? id = null;
455+
if (await Context.LanguageModelClient.IsEnabled()) {
456+
id = await Context.LanguageModelClient.GenerateCompletion(prompt);
457+
}
455458
return id?.Response ?? $"{method}{parametrizedPath.Replace('/', '.')}";
456459
}
457460

458461
private async Task<string> GetOperationDescription(string method, string serverUrl, string parametrizedPath)
459462
{
460463
var prompt = $"You're an expert in OpenAPI. You help developers build great OpenAPI specs for use with LLMs. For the specified request, generate a one-sentence description. Respond with just the description. For example, for a request such as `GET https://api.contoso.com/books/{{books-id}}` you return `Get a book by ID`. Request: {method.ToUpper()} {serverUrl}{parametrizedPath}";
461-
var description = await Context.LanguageModelClient.GenerateCompletion(prompt);
464+
ILanguageModelCompletionResponse? description = null;
465+
if (await Context.LanguageModelClient.IsEnabled()) {
466+
description = await Context.LanguageModelClient.GenerateCompletion(prompt);
467+
}
462468
return description?.Response ?? $"{method} {parametrizedPath}";
463469
}
464470

0 commit comments

Comments
 (0)