Skip to content

Commit

Permalink
fix: show input box though the input text is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-jianliang committed Apr 24, 2024
1 parent ee5ee07 commit eb6e443
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export function getPrompt(agent: Agent, inputType: string): string {
}

export function getSystemPrompt(agent: Agent, inputType: string): string | undefined {
if (inputType === 'default') {
return 'You are a AI assistant.';
}
switch (agent.schemaVersion) {
case 1:
return (agent as AgentV1).systemPrompt;
Expand All @@ -51,6 +54,9 @@ export function getContextTypes(agent: Agent): string[] {

export function getEngineType(agent: Agent, inputType: string): EngineType {
console.log('getEngineType', agent, inputType);
if (inputType === 'default') {
return EngineType.ChatGPT;
}
switch (agent.schemaVersion) {
case 1:
return (agent as AgentV1).engine;
Expand All @@ -62,6 +68,9 @@ export function getEngineType(agent: Agent, inputType: string): EngineType {
}

export function getEngineModel(agent: Agent, inputType: string): string {
if (inputType === 'default') {
return 'gpt-3.5-turbo';
}
switch (agent.schemaVersion) {
case 1:
return (agent as AgentV1).models[0];
Expand Down
10 changes: 4 additions & 6 deletions src/pages/content/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function App(props: Props) {
}
console.log('use agent', agent, 'info', info);

let prompt: string;
let prompt: string = '';
if (info.selectionText) {
prompt = getPrompt(agent, 'selection').replace('${selection}', info.selectionText);
const textSystemPrompt = getSystemPrompt(agent, 'selection');
Expand All @@ -41,7 +41,8 @@ export default function App(props: Props) {
setInputType('image');
setSystemPrompt(imageSystemPrompt);
} else {
return;
setInputType('default');
setSystemPrompt(getSystemPrompt(agent, 'default'));
}

if (prompt.length > 0) {
Expand All @@ -54,11 +55,8 @@ export default function App(props: Props) {
console.log('set input', prompt);
setInput(prompt);
}

createNewSession(prompt, agent).then(id => setSessionId(id));
} else {
alert('Prompt is empty');
}
createNewSession(prompt, agent).then(id => setSessionId(id));

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [agent, info]);
Expand Down

0 comments on commit eb6e443

Please sign in to comment.