Skip to content

Commit

Permalink
fix(chat): generate and return chat topic
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Oct 20, 2023
1 parent 4efe28c commit 47755fb
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
id: release
with:
release-type: node
package-name: ${{env.NPM_MODULE_NAME}}
package-name: ${{vars.NPM_MODULE_NAME}}
pull-request-title-pattern: 'chore${scope}: release ${version} [skip-ci]'
# The logic below handles the npm publication:
- uses: actions/checkout@v3
Expand All @@ -26,7 +26,7 @@ jobs:
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}
- run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion examples/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { questionQuery } = require('../lib/embeddings-query');
const util = require('util');

async function main() {
const question = 'Kui suur on mu eelmise kuu Amazoni arve?';
const question = 'How much did my last purchase on Amazon cost?';

const info = await questionQuery(question, process.env.OPENAI_API_KEY, {
//gptModel: 'gpt-3.5-turbo',
Expand Down
27 changes: 17 additions & 10 deletions lib/embeddings-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ const SCHEMA_PROMPT = `
**Output Guidelines:**
1. Your objective is to sift through the email context and pinpoint the answer that best addresses the given query.
2. If no email matches the query criteria, or if the match is ambiguous, refrain from providing an answer.
3. Limit your sources strictly to the provided email context. External references are not to be utilized.
4. Format your response as follows:
1. Answer the user's question using only the provided context information.
2. Your objective is to sift through the email context and pinpoint the answer that best addresses the given query.
3. If no email matches the query criteria, or if the match is ambiguous, refrain from providing an answer.
4. Limit your sources strictly to the provided email context. External references are not to be utilized.
5. Format your response as follows:
- Start with \`Answer:\` followed by the relevant information.
- On a new line, begin with \`Message-ID:\` and cite the unique Message-ID(s) of the emails you sourced your answer from.
5. Ensure that the Message-ID is never embedded within the main body of your response.
6. Avoid including any additional commentary or annotations.
6. Ensure that the Message-ID is never embedded within the main body of your response.
7. Avoid including any additional commentary or annotations.
**Context**:
Expand All @@ -77,6 +78,10 @@ You are analyzing user questions regarding email retrieval from a database. From
- Identify the starting point for the query ('start_time').
- Identify when to stop the query ('end_time').
3. **Topic for the Hypothetical Answer**:
- Try to answer the question without knowing the actual context and generate a topic for the answer.
- For missing context assume any generic or likely value
**Context**:
- The current time is '${new Date().toUTCString()}'.
Expand All @@ -90,21 +95,23 @@ You are analyzing user questions regarding email retrieval from a database. From
- For unspecified time zones, timestamps should follow the 'YYYY-MM-DD hh:mm:ss' format.
- If only the date is known, use the 'YYYY-MM-DD' format.
- Assume the week starts on Monday.
- Identify the topic for the question.
- Your response should be structured in JSON, strictly adhering to the schema:
\`\`\`
{
"ordering": "",
"start_time": "",
"end_time": ""
"end_time": "",
"topic": ""
}
\`\`\`
- Example Queries and Responses:
- **Query**: "When is the next conference event?"
**Response**: \`{"ordering":"newer_first"}\`
**Response**: \`{"ordering":"newer_first", "topic": "Conference event happening next week"}\`
- **Query**: "What did James write to me about last Friday?" (assuming that current time is "2023-10-02")
**Response**: \`{"ordering":"best_match", "start_time": "2023-09-29", "end_time": "2023-09-30"}\`
**Response**: \`{"ordering":"best_match", "start_time": "2023-09-29", "end_time": "2023-09-30", "topic": "A message from James about an event in 2023-09-30"}\`
- **Query**: "When did I receive my first Amazon invoice?"
**Response**: \`{"ordering":"older_first"}\`
**Response**: \`{"ordering":"older_first", "topic": "Amazon invoice sent last week"}\`
**User's Query**:
Process the user question:
Expand Down
98 changes: 49 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Email AI tools",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"update": "rm -rf node_modules package-lock.json && ncu -u && npm install"
},
"repository": {
"type": "git",
Expand All @@ -23,13 +24,13 @@
"mailparser": "3.6.5"
},
"dependencies": {
"@postalsys/email-text-tools": "2.1.1",
"@postalsys/email-text-tools": "2.1.2",
"gpt3-tokenizer": "1.1.5",
"libmime": "5.2.1",
"linkify-it": "4.0.1",
"nodemailer": "6.9.5",
"nodemailer": "6.9.6",
"punycode": "2.3.0",
"tlds": "1.242.0",
"undici": "5.25.3"
"tlds": "1.243.0",
"undici": "5.26.4"
}
}

0 comments on commit 47755fb

Please sign in to comment.