Closed unexpand closed 8 months ago
chat
is intended to be used with ollama's model templates with messages representing one side of a chat exchange. To better illustrate this here's an example equivalent to your code:
messages = [
{
"role": "system",
"content": "Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer."
},
{
"role": "user",
"content": prompt,
},
]
async for part in AsyncClient().chat(model='mistral', messages=messages, stream=True):
print(part['message']['content'], end='', flush=True)
The input messages
can be construct anyway you want however the only valid roles are system
, user
, and assistant
.
What I am trying to attempt is something like langchain RetrievalQA, making chat request with some context. I got the documents from pgvector postgres using search and I want to use prompt like "Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer." and pass the documents as context so mistral llm can use the context to respond.
my code currently looks like this and it works, but I am not sure if this is a valid approach.