Skip to content

Instantly share code, notes, and snippets.

@RameshRM
Last active August 26, 2024 03:45
Show Gist options
  • Save RameshRM/e05f07cdbdb78e595ccf0f931400f3d5 to your computer and use it in GitHub Desktop.
Save RameshRM/e05f07cdbdb78e595ccf0f931400f3d5 to your computer and use it in GitHub Desktop.
ollama-test.js
import "cheerio";
import { CheerioWebBaseLoader } from "@langchain/community/document_loaders/web/cheerio";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
import { MemoryVectorStore } from "langchain/vectorstores/memory";
import { OpenAIEmbeddings, ChatOpenAI } from "@langchain/openai";
import { pull } from "langchain/hub";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { StringOutputParser } from "@langchain/core/output_parsers";
import { Ollama, ChatOllama } from "@langchain/ollama" ;
import { createStuffDocumentsChain } from "langchain/chains/combine_documents";
(async function (){
const loader = new CheerioWebBaseLoader(
"https://lilianweng.github.io/posts/2023-06-23-agent/"
);
const docs = await loader.load();
const textSplitter = new RecursiveCharacterTextSplitter({
chunkSize: 1000,
chunkOverlap: 200,
});
const splits = await textSplitter.splitDocuments(docs);
const vectorStore = await MemoryVectorStore.fromDocuments(
splits,
new OpenAIEmbeddings()
);
// Retrieve and generate using the relevant snippets of the blog.
const retriever = vectorStore.asRetriever();
const prompt = await pull<ChatPromptTemplate>("rlm/rag-prompt");
const llm2 = new ChatOpenAI({ model: "gpt-3.5-turbo", temperature: 0 });
const llm = new Ollama({
model: "llama3.1", // Default value
temperature: 0,
maxRetries: 2,
baseUrl: 'http://localhost:11434',
format: "json",
});
const ragChain = await createStuffDocumentsChain({
llm,
prompt,
outputParser: new StringOutputParser(),
});
const retrievedDocs = await retriever.invoke("what is task decomposition");
console.log('test')
console.log(prompt.promptMessages.map((msg) => msg.prompt.template).join("\n"));
const result = await ragChain.invoke({
question: "What is task decomposition?",
context: retrievedDocs,
});
console.log(result);
}).call(this);
This is a code identification task and classify if the content contains Semantic or Syntactical references
for Telephone Number. Telephone number can be represented in multiple ways and the examples for Java methods are
provided in the Example section. For output, reference the Response section with JSON schema. Dont infer anything else.
If you find any class or method signature which might contain telephone number, report there is a match found, in the example below, `Contact` is a class defined and instantiated without accessing the phone number field, but report match found, it is possible the intention might be to use the phone number.
Example:
1. Java class setting Contact information
public class Contact {
private String addressLine1;
private String addressLine2;
private String homePhone;
private String mobile;
private String cellular;
}
2. void contact_num(String contact);
3. void setHome_ph(String input);
4. this.contact_num = inputString;
5. String getMobile();
6. void formatInput(String mobileNum);
7. void formatInput(String telNum);
Response:
{"fieldsDetected": [], "matchFound": boolean, "reason": String}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment