Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageVersion Include="Aspire.Azure.AI.OpenAI" Version="9.3.1-preview.1.25305.6" />
<PackageVersion Include="Aspire.Azure.Search.Documents" Version="13.3.0" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="13.3.0" />
<PackageVersion Include="Aspire.Hosting.Azure.CognitiveServices" Version="13.3.0" />
<PackageVersion Include="Aspire.Hosting.Azure.CognitiveServices" Version="13.4.6" />
<PackageVersion Include="Aspire.Hosting.NodeJs" Version="9.5.2" />
<PackageVersion Include="CommunityToolkit.Aspire.Hosting.Dapr" Version="9.9.0" />
<PackageVersion Include="CommunityToolkit.Aspire.Hosting.NodeJS.Extensions" Version="9.9.0" />
Expand Down Expand Up @@ -106,8 +106,8 @@
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.15.1" />
<PackageVersion Include="PdfPig" Version="0.1.13" />
<PackageVersion Include="Pinecone.Client" Version="3.1.0" />
<PackageVersion Include="Prompty.Core" Version="0.2.3-beta" />
<PackageVersion Include="Scriban" Version="7.2.0" />
<PackageVersion Include="Prompty.Core" Version="2.0.0-beta.3" />
<PackageVersion Include="SQLitePCLRaw.lib.e_sqlite3" Version="3.53.3" /> <!-- Transitive dependency of Microsoft.Data.Sqlite pinned to newer version due to vulnerability in <= 2.1.11 (GHSA-2m69-gcr7-jv3q) -->
<PackageVersion Include="PuppeteerSharp" Version="20.2.5" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="10.0.2" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.16.0" />
Expand Down
86 changes: 34 additions & 52 deletions dotnet/src/Functions/Functions.Prompty.UnitTests/PromptyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public void ChatPromptyShouldSupportCreatingOpenAIExecutionSettingsWithJsonObjec
Assert.Equal(0, executionSettings.Temperature);
Assert.Equal(1.0, executionSettings.TopP);
Assert.Null(executionSettings.StopSequences);
Assert.Equal("{\"type\":\"json_object\"}", executionSettings.ResponseFormat?.ToString());
Assert.Null(executionSettings.TokenSelectionBiases);
Assert.Equal(3000, executionSettings.MaxTokens);
Assert.Null(executionSettings.Seed);
Expand Down Expand Up @@ -226,25 +225,41 @@ public void ItFailsToParseAnEmptyHeader()
---
Abc
""")]
[InlineData("""
---a
name: SomePrompt
---
Abc
""")]
[InlineData("""
---
name: SomePrompt
---b
Abc
""")]
public void ItRequiresStringSeparatorPlacement(string prompt)
public void ItToleratesLenientFrontmatterSeparatorPlacement(string prompt)
{
// Arrange
Kernel kernel = new();

// Act / Assert
Assert.Throws<ArgumentException>(() => kernel.CreateFunctionFromPrompty(prompt));
// Act - Prompty 2.0 tolerates surrounding whitespace and trailing characters on the
// frontmatter separators, so these templates are parsed rather than rejected. This is
// not a security-relevant relaxation, so no stricter validation is imposed on top.
var kernelFunction = kernel.CreateFunctionFromPrompty(prompt);

// Assert
Assert.NotNull(kernelFunction);
Assert.Equal("SomePrompt", kernelFunction.Name);
}

[Fact]
public void ItThrowsForMalformedFrontmatterYaml()
{
// Arrange
Kernel kernel = new();

// Act / Assert - a non-separator opening line ("---a") leaves invalid YAML in the
// frontmatter, which surfaces as an ArgumentException.
Assert.Throws<ArgumentException>(() => kernel.CreateFunctionFromPrompty("""
---a
name: SomePrompt
---
Abc
"""));
}

[Fact]
Expand Down Expand Up @@ -342,7 +357,8 @@ public void ItCreatesInputVariablesOnlyWhenNoneAreExplicitlySet()
---
name: MyPrompt
inputs:
question:
- name: question
kind: string
description: What is the color of the sky?
---
{{a}} {{b}} {{c}}
Expand All @@ -366,20 +382,14 @@ public void ItShouldLoadExecutionSettings()
name: SomePrompt
description: This is the description.
model:
api: chat
connection:
type: azure_openai_beta
apiType: chat
options:
logprobs: true
top_logprobs: 2
top_p: 1.0
user: Bob
stop_sequences:
temperature: 0.5
topP: 1.0
maxOutputTokens: 1000
stopSequences:
- END
- COMPLETE
token_selection_biases:
1: 2
3: 4
---
Abc---def
""";
Expand All @@ -393,12 +403,10 @@ public void ItShouldLoadExecutionSettings()
Assert.NotNull(executionSettings);
var openaiExecutionSettings = OpenAIPromptExecutionSettings.FromExecutionSettings(executionSettings);
Assert.NotNull(openaiExecutionSettings);
Assert.True(openaiExecutionSettings.Logprobs);
Assert.Equal(2, openaiExecutionSettings.TopLogprobs);
Assert.Equal(0.5, openaiExecutionSettings.Temperature);
Assert.Equal(1.0, openaiExecutionSettings.TopP);
Assert.Equal("Bob", openaiExecutionSettings.User);
Assert.Equal(1000, openaiExecutionSettings.MaxTokens);
Assert.Equal(["END", "COMPLETE"], openaiExecutionSettings.StopSequences);
Assert.Equal(new Dictionary<int, int>() { { 1, 2 }, { 3, 4 } }, openaiExecutionSettings.TokenSelectionBiases);
}

[Fact]
Expand Down Expand Up @@ -442,32 +450,6 @@ public void ItShouldCreateFunctionFromPromptYamlContainingRelativeFileReferences
Assert.Equal("gpt-35-turbo", defaultExecutionSetting.ModelId);
}

[Fact]
public void JsonSchemaTest()
{
// Arrange
Kernel kernel = new();
var chatPromptyPath = Path.Combine("TestData", "chat.prompty");
var promptyTemplate = File.ReadAllText(chatPromptyPath);

// Act
var kernelFunction = kernel.CreateFunctionFromPrompty(promptyTemplate);

// Assert
var firstName = kernelFunction.Metadata.Parameters.First(p => p.Name == "firstName");
Assert.NotNull(firstName);
Assert.NotNull(firstName.Schema);
Assert.Equal("{\"type\":\"string\"}", firstName.Schema.ToString());
var answer = kernelFunction.Metadata.Parameters.First(p => p.Name == "answer");
Assert.NotNull(answer);
Assert.NotNull(answer.Schema);
Assert.Equal("{\"type\":\"object\",\"properties\":{\"answer\":{\"type\":\"string\"},\"citations\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"format\":\"uri\"}}},\"required\":[\"answer\",\"citations\"],\"additionalProperties\":false}", answer.Schema.ToString());
var other = kernelFunction.Metadata.Parameters.First(p => p.Name == "other");
Assert.NotNull(other);
Assert.NotNull(other.Schema);
Assert.Equal("{\"type\":\"object\",\"properties\":{\"answer\":{\"type\":\"string\"},\"citations\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"format\":\"uri\"}}},\"required\":[\"answer\",\"citations\"],\"additionalProperties\":\"false\"}", other.Schema.ToString());
}

private sealed class EchoTextGenerationService : ITextGenerationService
{
public IReadOnlyDictionary<string, object?> Attributes { get; } = new Dictionary<string, object?>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,91 +8,31 @@ metadata:
- basic
model:
id: gpt-35-turbo
api: chat
connection:
type: azure_openai
api_version: 2023-07-01-preview
options:
tools_choice: auto
tools:
- id: test
type: function
description: test function
options:
parameters:
- name: location
type: string
required: true
description: The city and state or city and country, e.g. San Francisco, CA or Tokyo, Japan
apiType: chat
inputs:
firstName:
type: string
- name: firstName
kind: string
default: User
sample: April
description: The first name of the customer
json_schema:
type: string
lastName:
type: string
sample: Kwong
- name: lastName
kind: string
required: true
strict: false
description: The last name of the customer
json_schema:
type: string
question:
type: string
description: The question to answer
- name: question
kind: string
required: true
json_schema:
type: string
answer:
type: object
description: Some count
description: The question to answer
- name: answer
kind: object
required: true
description: The answer with citations
json_schema: |
{
"type": "object",
"properties": {
"answer": {
"type": "string"
},
"citations": {
"type": "array",
"items": {
"type": "string",
"format": "uri"
}
}
},
"required": [
"answer",
"citations"
],
"additionalProperties": false
}
other:
type: object
- name: other
kind: object
required: true
description: Property with JSON schema
json_schema:
type: object
properties:
answer:
type: string
citations:
type: array
items:
type: string
format: uri
required:
- answer
- citations
additionalProperties: false
description: Property with additional context
outputs:
work:
type: object
- name: work
kind: object
description: The thing to output
---
system:
Expand Down Expand Up @@ -146,4 +86,4 @@ would go well with the items found above. Be brief and concise and use appropria
{% for item in history %}
{{item.role}}:
{{item.content}}
{% endfor %}
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ metadata:
- markwallace
tags:
- basic
model:
model:
id: gpt-4o
api: chat
connection:
type: azure_openai
azure_deployment: gpt-4o
apiType: chat
options:
temperature: 0.0
max_tokens: 3000
top_p: 1.0
response_format:
type: json_object
maxOutputTokens: 3000
topP: 1.0
---
system:
You are a classifier agent that should know classify a problem into Easy/Medium/Hard based on the problem description.
Expand All @@ -27,4 +22,4 @@ your response should be in a json format with the following structure:
}

user:
{{question}}
{{question}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
name: prompty_with_no_execution_setting
description: prompty without execution setting
metadata:
Expand All @@ -7,6 +7,8 @@ metadata:
tags:
- basic
inputs:
prompt: dummy
- name: prompt
kind: string
default: dummy
---
{{prompt}}
{{prompt}}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{
"api": "chat",
"apiType": "chat",
"id": "gpt-35-turbo",
"connection": {
"type": "azure_openai",
"api_version": "2023-07-01-preview"
},
"options": {
"temperature": 0.5
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
name: TestRelativeFileReference
description: A test prompt for relative file references
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- THIS PROPERTY GROUP MUST COME FIRST -->
<AssemblyName>Microsoft.SemanticKernel.Prompty</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<TargetFrameworks>net10.0;net8.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net10.0</TargetFrameworks>
<VersionSuffix>beta</VersionSuffix>
<NoWarn>$(NoWarn);CA1812</NoWarn>
</PropertyGroup>
Expand All @@ -19,8 +19,6 @@
<ProjectReference Include="..\..\Extensions\PromptTemplates.Liquid\PromptTemplates.Liquid.csproj" />
<ProjectReference Include="..\..\SemanticKernel.Core\SemanticKernel.Core.csproj" />
<PackageReference Include="Prompty.Core" />
<!-- Adding Scriban directly to use latest version number to avoid a vulnerability issue. Can be removed later once Prompty.Core references an updated version -->
<PackageReference Include="Scriban" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" />
</ItemGroup>
Expand Down
Loading