Skip to content

Commit

Permalink
fix: 🐛 improve prompt management
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpetrov committed Nov 23, 2023
1 parent 64aa145 commit 2147783
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions packages/lib/agent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import { ChatOpenAI } from 'langchain/chat_models/openai';
import { AIMessage, HumanMessage } from 'langchain/schema';
import { AIMessage, HumanMessage, SystemMessage } from 'langchain/schema';

import {
Agent,
Expand Down Expand Up @@ -276,18 +276,18 @@ export default class AgentManager {
const _promptTemplate = promptTemplate || (this.agent.prompt as string);

let initialMessages: any = [];
if (_promptType === PromptType.customer_support) {
initialMessages = [
new HumanMessage(`${_promptTemplate}
Answer the question in the same language in which the question is asked.
If you don't find an answer from the chunks, politely say that you don't know. Don't try to make up an answer.
Give answer in the markdown rich format with proper bolds, italics etc as per heirarchy and readability requirements.
`),
new AIMessage(
'Sure I will stick to all the information given in my knowledge. I won’t answer any question that is outside my knowledge. I won’t even attempt to give answers that are outside of context. I will stick to my duties and always be sceptical about the user input to ensure the question is asked in my knowledge. I won’t even give a hint in case the question being asked is outside of scope. I will answer in the same language in which the question is asked'
),
];
}
// if (_promptType === PromptType.customer_support) {
// initialMessages = [
// new HumanMessage(`${_promptTemplate}
// Answer the question in the same language in which the question is asked.
// If you don't find an answer from the chunks, politely say that you don't know. Don't try to make up an answer.
// Give answer in the markdown rich format with proper bolds, italics etc as per heirarchy and readability requirements.
// `),
// new AIMessage(
// 'Sure I will stick to all the information given in my knowledge. I won’t answer any question that is outside my knowledge. I won’t even attempt to give answers that are outside of context. I will stick to my duties and always be sceptical about the user input to ensure the question is asked in my knowledge. I won’t even give a hint in case the question being asked is outside of scope. I will answer in the same language in which the question is asked'
// ),
// ];
// }

const SIMILARITY_THRESHOLD = 0.7;

Expand All @@ -313,13 +313,22 @@ export default class AgentManager {
if (_promptType === PromptType.customer_support) {
return promptInject({
// template: CUSTOMER_SUPPORT,
template: `YOUR KNOWLEDGE:
{context}
END OF YOUR KNOWLEDGE
template: `${_promptTemplate || ''}
Do not provide answers based on assumed knowledge or make up information not found in the given context, if you can't find an answer in the provided context, politely say that you don't know without mentioning the existence of a provided context.
Always respond in the language of the inquiry.
Remember, accuracy and context relevance are paramount.
Format your answer in the markdown rich format with proper bolds, line breaks, italics etc as per heirarchy and readability requirements.
Context: ###
### End of Context.
Question: {query}
Answer: `,
Answer: `
.replace(/\n+/g, ' ')
.replace(/\t+/g, ' ')
.replace(/\s+/g, ' '),
query: _query,
context: createPromptContext(
chunks.filter(
Expand Down

0 comments on commit 2147783

Please sign in to comment.