Skip to content

Instantly share code, notes, and snippets.

@deletosh
Created July 10, 2023 18:42
Show Gist options
  • Save deletosh/23ad0632d8282c32655aed1f79f970fa to your computer and use it in GitHub Desktop.
Save deletosh/23ad0632d8282c32655aed1f79f970fa to your computer and use it in GitHub Desktop.
How to use LangChain with MultiLLMs
import {OpenAI} from "langchain/llms/openai";
import {PromptTemplate} from "langchain/prompts";
import {LLMChain} from "langchain";
import {GoogleVertexAI} from "langchain/dist/llms/googlevertexai";
const model = new OpenAI({
openAIApiKey: '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',
modelName: 'text-davinci-003'
});
const modelVertextAI = new GoogleVertexAI({
// openAIApiKey: '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',
// modelName: 'text-davinci-003'
});
const jobSummaryTemplate =
`
Summarize the key points in this job posting as JSON.
Job posting:
{job}
`; //skills
const resumeFixTemplate: string = `
You an expert resume couch that gives clear advice on improvement for tech roles.
List all the possible improvement to write a resume for a {role} that has this base requirements:
{jobReq}
`;
const getJobSummaryPrompt = new PromptTemplate({
template: jobSummaryTemplate,
inputVariables: ["job"],
});
const resumeFixPrompt = new PromptTemplate({
template: resumeFixTemplate,
inputVariables: ["role", "jobReq"],
});
// const promptFormatted = await prompt.format(
// {
// job: document.querySelector('#job-posting') //coming from the user somewhere
// });
const chainOne = new LLMChain({
llm: model,
prompt: getJobSummaryPrompt
})
const {skills} = await chainOne.call({
job: document.querySelector('#job-posting')
})
const chainTwo = new LLMChain({
llm: model,
prompt: resumeFixPrompt
})
const suggestion = await chainTwo.call({
role: document.querySelector('#job-role'),
jobReq: skills
})
// { response['skill']}
// output to use and format nicely....
console.log(suggestion)
// console.log(response)
// we actually now send the prompt to the API
// const responseFromGPT = await model.call(promptFormatted)
// the GPT response
// console.log(responseFromGPT)
// const res = await model.call(
// `
// Summarize the key points in this job posting as JSON.
//
// Job posting:
// Assists the Government in developing requirements engineering, solutions engineering, scheduling, reliability, resiliency, services development, integration, test and evaluation, maintainability and analysis across NSG, ASG and Federal Agencies.
// Develops system and programming specifications.
// Designs data processing solutions based on business need and technical considerations. Researches and resolves application production problems. Monitors application performance and performs run time improvement functions.
// Prepares system documentation.
// Performs complex engineering analysis and design tasks. Prepares specifications and designs, and implements solutions.
// Assists in design subsystems; assists in developing standards. May work as part of a project team.
// Evaluates IT system problems of workflow, organization, and planning.
// Assists in the design, development, analysis, installation, maintenance, operation and servicing of computer operating/hardware systems within a cybersecurity environment; provides customer support · Works under direct supervision; does related work as required.
// `
// )
// console.log(res)
// openAiModel.call('deddededeeded')
const jobFormEl = document.querySelector('form')
// const jobPostingInputEl = document.querySelector('#job-posting')
// const jobExpInputEl = document.querySelector('#job-exp')
// jobFormEl.addEventListener('submit', (e) => {
// e.preventDefault()
//
// const formData = new FormData(e.target);
//
// const jobPostingInput = formData.get('job-posting');
// const jobExpInput = formData.get('job-exp');
//
// console.log(jobPostingInput)
//
// })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment