0

I am teaching myself LLM programming by developing a RAG application. I am running Llama 3.2 on my laptop using Ollama, and using a mix of SQLite and langchain.

I can pass a context to the llm along with my question so the model uses the context for generating an answer. The code is like so

const model = 'llama3.2:latest';
const temperature = 0;
const llm = new ChatOllama({ model, temperature });
const messages = await promptTemplate.invoke({ question, context });
const answer = await llm.invoke(messages);

But, nowhere in Ollama's api docs do I see the ability to pass a context to the model. The only "context" that the docs refer to is context (deprecated): the context parameter returned from a previous request to /generate, this can be used to keep a short conversational memory. This seems very different from the way I understand "context" as I noted above.

If I were to query the model via Ollama's curl api, how would I structure my query to get a contextual response from the model?

4
  • Probably, something like const prompt = "You are a helpful assistant.\n\nHere is some background information:\n" + context + "\n\nQuestion:\n" + question + "\n\nAnswer:\n"; and then const promptTemplate = ChatPromptTemplate.fromMessages([ ['system', 'You are a helpful assistant.'], ['human', 'Here is some background information:\n' + context + '\n\nQuestion:\n' + question], ]); Commented Apr 18 at 17:23
  • thanks, but perhaps I wasn't clear. I am looking for the syntax for directly querying Ollama via its curl api, not via langchain. But, nowhere in the api docs do I see examples of how to pass a context. I can do that via langchain as I showed above in my code, but I want to understand how langchain communicates with the model Commented Apr 18 at 17:29
  • I guess all you want is to use the chat endpoint (not generate), and include previous responses as the context. Commented Apr 18 at 17:40
  • well, when using my langchain-based program, I include the text of a scientific paper as the context, and I ask the llm a question that could be answered based on that provided context. This seems to work well via my program. But, I can't figure out how to do it directly via the api. Perhaps I need to do what you suggest -- provide the context as "previous responses" so the model uses that to base its answer. I would appreciate confirmation of this assumption Commented Apr 18 at 17:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.