improve: prompt for NLP result
This commit is contained in:
parent
86d4015ae5
commit
38b144a6f4
@ -135,6 +135,9 @@ export default function () {
|
|||||||
} else if (s.type === "text") {
|
} else if (s.type === "text") {
|
||||||
return (
|
return (
|
||||||
<PlainText key={i} selected={i == selected}>
|
<PlainText key={i} selected={i == selected}>
|
||||||
|
{s.prompt && (
|
||||||
|
<span className="text-zinc-700 dark:text-zinc-400">{s.prompt}</span>
|
||||||
|
)}
|
||||||
<p>{s.suggestion}</p>
|
<p>{s.suggestion}</p>
|
||||||
{devMode && (
|
{devMode && (
|
||||||
<span className="text-zinc-700 dark:text-zinc-400 text-sm">
|
<span className="text-zinc-700 dark:text-zinc-400 text-sm">
|
||||||
|
6
global.d.ts
vendored
6
global.d.ts
vendored
@ -23,5 +23,9 @@ type suggestionItem = {
|
|||||||
suggestion: string,
|
suggestion: string,
|
||||||
type: string,
|
type: string,
|
||||||
relativeRelevance?: number,
|
relativeRelevance?: number,
|
||||||
relevance: number
|
relevance: number,
|
||||||
|
prompt?: string | React.ReactElement,
|
||||||
|
intention?: string | null,
|
||||||
|
probability?: number,
|
||||||
|
confidence?: number,
|
||||||
}
|
}
|
@ -7,6 +7,7 @@ export class NLPResult {
|
|||||||
public relevanceBase: number = 2000,
|
public relevanceBase: number = 2000,
|
||||||
public confidenceWeight: number = 0.2,
|
public confidenceWeight: number = 0.2,
|
||||||
public type: string = "text",
|
public type: string = "text",
|
||||||
|
public prompt?: string | React.ReactElement
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import removeStopwords from "../nlp/stopwords";
|
import removeStopwords from "../nlp/stopwords";
|
||||||
import { NLPResult } from "./NLPResult";
|
import { NLPResult } from "./NLPResult";
|
||||||
|
import {Kbd} from "@nextui-org/react";
|
||||||
|
|
||||||
interface KeywordsDict {
|
interface KeywordsDict {
|
||||||
[key: string]: number;
|
[key: string]: number;
|
||||||
@ -44,7 +45,7 @@ export function base64NLP(str: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let processedQuery = "";
|
let processedQuery = str;
|
||||||
if (result.intention==="base64.encode"){
|
if (result.intention==="base64.encode"){
|
||||||
processedQuery = removeStopwords(str, Object.keys(keywords).concat(Object.keys(intentions)), true).trim();
|
processedQuery = removeStopwords(str, Object.keys(keywords).concat(Object.keys(intentions)), true).trim();
|
||||||
} else if (result.intention==="base64.decode") {
|
} else if (result.intention==="base64.decode") {
|
||||||
@ -58,6 +59,7 @@ export function base64NLP(str: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (validBase64(processedQuery) && result.intention !== "base64.encode") {
|
else if (validBase64(processedQuery) && result.intention !== "base64.encode") {
|
||||||
|
console.log("!!");
|
||||||
result.intention = "base64.decode";
|
result.intention = "base64.decode";
|
||||||
result.confidence += Math.max(1 / Math.log10(1 / processedQuery.length) + 1, 0);
|
result.confidence += Math.max(1 / Math.log10(1 / processedQuery.length) + 1, 0);
|
||||||
result.probability += Math.max(1 / Math.log10(1 / processedQuery.length) + 1, 0);
|
result.probability += Math.max(1 / Math.log10(1 / processedQuery.length) + 1, 0);
|
||||||
@ -66,10 +68,12 @@ export function base64NLP(str: string) {
|
|||||||
switch (result.intention) {
|
switch (result.intention) {
|
||||||
case "base64.encode":
|
case "base64.encode":
|
||||||
result.suggestion = btoa(processedQuery);
|
result.suggestion = btoa(processedQuery);
|
||||||
|
result.prompt = <span>Base64 Encode (Hit <Kbd keys={["enter"]}></Kbd> to copy):</span>;
|
||||||
break;
|
break;
|
||||||
case "base64.decode":
|
case "base64.decode":
|
||||||
if (result.confidence > 0.1)
|
if (result.confidence > 0.1)
|
||||||
result.suggestion = atob(processedQuery);
|
result.suggestion = atob(processedQuery);
|
||||||
|
result.prompt = <span>Base64 Decode (Hit <Kbd keys={["enter"]}></Kbd> to copy):</span>;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
Loading…
Reference in New Issue
Block a user