Replies: 2 comments 5 replies
-
To achieve concurrency with LangChain and Ollama, you should leverage the asynchronous capabilities of the Here is an updated version of your code that uses Updated Example Codeimport asyncio
from langchain_community.llms import Ollama
from langchain_core.messages import HumanMessage
SYSTEM_PROMPT = """You're a call center analyst, tasked to analyze the call transcripts, fix grammatical errors and typos
and provide an in-depth summary consisting of 6 lines with fixed grammar."""
llm = Ollama(
base_url=BASE_URL,
model=MODEL,
system=SYSTEM_PROMPT,
temperature=0.0,
)
# Define an asynchronous function to process each row
async def process_row(row):
transcript = row["TranscriptContent"]
response = await llm._agenerate([HumanMessage(content=f""" You're a call analyst. Summarize the following call transcript into 6 concise sentences paragraph: Call Transcript: {transcript}""")])
return response.generations[0][0].text
# Define the main function to process all rows concurrently
async def main(df):
tasks = [process_row(row) for _, row in df.iterrows()]
summaries = await asyncio.gather(*tasks)
return summaries
# Run the main function
summaries = asyncio.run(main(df))
# Print the summaries
for summary in summaries:
print(summary) This approach uses
|
Beta Was this translation helpful? Give feedback.
-
@ArslanKAS Have you finish this problem?
|
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
Hi everyone,
After the release of OLLAMA_NUM_PARALLEL and OLLAMA_MAX_LOADED_MODELS I tried it out purely using Ollama in the terminal and I was able to get concurrent results. But when I used LangChain then I was unable to get any concurrency at all.
I searched through both Ollama and LangChain repos and disucssions but couldn't find any starter code for it. Please if someone has already implemented it, guide me.
By the way I've installed Ollama on a AWS EC2 Instance and I use it's BASE URL in my SageMaker Jupyter Notebook using LangChain. That's how I'm able to use Ollama. All that's missing is now the Concurrency (Parallelism).
Thank you
System Info
System Information
Package Information
Beta Was this translation helpful? Give feedback.
All reactions