Skip to content

Commit

Permalink
Merge pull request #2149 from solliancenet/jdh-prompt-category
Browse files Browse the repository at this point in the history
Prompt category and create prompt option
  • Loading branch information
ciprianjichici authored Jan 22, 2025
2 parents 1242783 + bf76880 commit 272f638
Show file tree
Hide file tree
Showing 10 changed files with 789 additions and 620 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ public class PromptBase : ResourceBase
/// <inheritdoc/>
[JsonIgnore]
public override string? Type { get; set; }

/// <summary>
/// The category of the prompt.
/// </summary>
[JsonPropertyName("category")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public PromptCategory? Category { get; set; }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace FoundationaLLM.Common.Models.ResourceProviders.Prompt
{
/// <summary>
/// The category for the prompt class.
/// </summary>
public enum PromptCategory
{
/// <summary>
/// Agent prompt.
/// </summary>
Agent,

/// <summary>
/// Tool prompt.
/// </summary>
Tool
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected override async Task<object> ExecuteActionAsync(
{
PromptResourceTypeNames.Prompts => resourcePath.Action switch
{
ResourceProviderActions.CheckName => CheckResourceName<PromptBase>(
ResourceProviderActions.CheckName => await CheckResourceName<PromptBase>(
JsonSerializer.Deserialize<ResourceName>(serializedAction)!),
ResourceProviderActions.Purge => await PurgeResource<PromptBase>(resourcePath),
_ => throw new ResourceProviderException(
Expand Down
19 changes: 17 additions & 2 deletions src/ui/ManagementPortal/js/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,21 @@ export default {
/*
Prompts
*/
async checkPromptName(name: string, promptType: string): Promise<CheckNameResponse> {
const payload = {
name,
type: promptType,
};

return (await this.fetch(
`/instances/${this.instanceId}/providers/FoundationaLLM.Prompt/prompts/checkname?api-version=${this.apiVersion}`,
{
method: 'POST',
body: payload,
},
)) as CheckNameResponse;
},

async getPrompts(): Promise<ResourceProviderGetResult<Prompt>[] | null> {
try {
const data = await this.fetch(
Expand Down Expand Up @@ -588,9 +603,9 @@ export default {
}
},

async createOrUpdatePrompt(agentId: string, request: CreatePromptRequest): Promise<any> {
async createOrUpdatePrompt(promptName: string, request: CreatePromptRequest): Promise<any> {
return await this.fetch(
`/instances/${this.instanceId}/providers/FoundationaLLM.Prompt/prompts/${agentId}?api-version=${this.apiVersion}`,
`/instances/${this.instanceId}/providers/FoundationaLLM.Prompt/prompts/${promptName}?api-version=${this.apiVersion}`,
{
method: 'POST',
body: request,
Expand Down
2 changes: 2 additions & 0 deletions src/ui/ManagementPortal/js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export type Prompt = ResourceBase & {
description: string;
prefix: string;
suffix: string;
category: string;
};

export type AgentDataSource = ResourceBase & {
Expand Down Expand Up @@ -402,6 +403,7 @@ export type CreatePromptRequest = ResourceBase & {
type: 'basic' | 'multipart';
prefix: string;
suffix: string;
category: string;
};

export type CreateTextPartitioningProfileRequest = ResourceBase & {
Expand Down
17 changes: 9 additions & 8 deletions src/ui/ManagementPortal/pages/agents/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1659,14 +1659,15 @@ export default {
this.loading = true;
this.loadingStatusText = 'Saving agent...';
const promptRequest = {
type: 'multipart',
name: this.agentName,
cost_center: this.cost_center,
description: `System prompt for the ${this.agentName} agent`,
prefix: this.systemPrompt,
suffix: '',
};
const promptRequest = {
type: 'multipart',
name: this.agentName,
cost_center: this.cost_center,
description: `System prompt for the ${this.agentName} agent`,
prefix: this.systemPrompt,
suffix: '',
category: 'Agent',
};
const tokenTextPartitionRequest = {
text_splitter: 'TokenTextSplitter',
Expand Down
7 changes: 5 additions & 2 deletions src/ui/ManagementPortal/pages/data-sources/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,9 @@ export default {
this.validationMessage = response.message;
}
} catch (error) {
console.error('Error checking agent name: ', error);
console.error('Error checking data source name: ', error);
this.nameValidationStatus = 'invalid';
this.validationMessage = 'Error checking the agent name. Please try again.';
this.validationMessage = 'Error checking the data source name. Please try again.';
}
},
Expand Down Expand Up @@ -612,6 +612,9 @@ export default {
if (!this.dataSource.name) {
errors.push('Please give the data source a name.');
}
if (this.nameValidationStatus === 'invalid') {
errors.push(this.validationMessage);
}
if (!this.dataSource.type) {
errors.push('Please specify a data source type.');
Expand Down
Loading

0 comments on commit 272f638

Please sign in to comment.