|
1 | | -// This file will be run on the content page, and should include all the logic for inserting text into form items. |
2 | | -const usernameField = document.querySelector('input[name="username"]'); |
3 | | -const passwordField = document.querySelector('input[name="password"]'); |
| 1 | +import { AIMessage, ChatMessage, HumanMessage, SystemMessage } from "langchain/schema"; |
| 2 | +import { chatModel } from "./llm"; |
| 3 | +const user = { |
| 4 | + name: "samir s beall", |
| 5 | + |
| 6 | + address: "1999 Burdett Ave, Troy, NY 12180", |
| 7 | + phone_number: "(123) 456-78910", |
| 8 | +}; |
4 | 9 |
|
5 | | -if (usernameField) (usernameField as HTMLInputElement).value = "yourUsername"; |
6 | | -if (passwordField) (passwordField as HTMLInputElement).value = "yourPassword"; |
| 10 | +async function main (){ |
| 11 | + |
| 12 | + let template_text = "You are a helpful assistant that uses the given information to answer simple fields for a form. \ |
| 13 | + When prompted with a message, simply respond with the relevant information concisely. Here is all the information formatted in a json format that you can respond with: "; |
| 14 | + |
| 15 | + template_text += JSON.stringify(user) |
| 16 | + |
| 17 | + console.log(template_text); |
| 18 | + |
| 19 | + let messages = [new SystemMessage({ content: template_text })]; |
| 20 | + |
| 21 | + messages.push(new HumanMessage({content: "First Name"})); |
| 22 | + messages.push(new AIMessage({content: "Samir"})); |
| 23 | + |
| 24 | + const inputFields = document.querySelectorAll('input'); |
| 25 | + const questionsAndFields: { question: string, field: HTMLInputElement }[] = []; |
| 26 | + |
| 27 | + inputFields.forEach((inputField: HTMLInputElement) => { |
| 28 | + const label = document.querySelector(`label[for="${inputField.id}"]`); |
| 29 | + if (label) { |
| 30 | + questionsAndFields.push({ |
| 31 | + question: label.textContent || '', |
| 32 | + field: inputField |
| 33 | + }); |
| 34 | + } |
| 35 | + }); |
| 36 | + |
| 37 | + console.log(questionsAndFields); |
| 38 | + |
| 39 | + for (const qf of questionsAndFields){ |
| 40 | + |
| 41 | + console.log("querying chat") |
| 42 | + messages.push(new HumanMessage({content: qf.question})) |
| 43 | + |
| 44 | + let chatModelResult = await chatModel.predictMessages(messages); |
| 45 | + messages.push(chatModelResult); |
| 46 | + |
| 47 | + console.log("chat result: ") |
| 48 | + console.log(chatModelResult); |
| 49 | + |
| 50 | + |
| 51 | + qf.field.value = chatModelResult.content; |
| 52 | + } |
| 53 | + |
| 54 | + console.log(messages); |
| 55 | +} |
| 56 | + |
| 57 | +main(); |
7 | 58 |
|
8 | 59 | export {} |
0 commit comments