Skip to content

Conversation

omaryashraf5
Copy link

@omaryashraf5 omaryashraf5 commented Aug 20, 2025

What does this PR do?

It contains a python script for running llama stack with langchain locally in addition to a README file that explains how to run the script.
The script shows how to build content summarizer with llama stack and langChain.

Test Plan

Tested these scripts on the dev server.

An AI tool was used to optimize code, and create or improve function descriptions and comments in this pull request.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 20, 2025
@omaryashraf5 omaryashraf5 changed the title Added llama stack-langChain integration example scripts feat: Added llama stack-langChain integration example scripts Aug 20, 2025
Copy link
Collaborator

@mattf mattf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use langchain-llama-stack or langchain-openai, avoid making your own.

@@ -0,0 +1,290 @@
import os
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please use langchain small case. why camelCase it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repository contains two different implementations of document processing using LangChain and Llama Stack:

1. **`langchain_llamastack.py`** - Interactive CLI version
2. **`langchain_llamastack_ray.py`** - Ray Serve API version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you tell the motivation behind providing this? genuinely curious as to what folks are looking for and gain with the Ray example.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @ashwinb for your comment. We looked at serving layer solutions and how langchain applications get served and we wanted to show an example with a serving layer solution like RayServe which is commonly used by langchain developers. I could remove the rayserve script (part 2) because making the source code compatible with ray should be straight forward.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashwinb removed the ray script from this PR.


---

## 🌐 Option 2: Ray Serve API Version (`langchain_llamastack_ray.py`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?
Option 1 seems to be good for Langchain prompt template and Llamastack integration

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slekkala1 Thank you for your comment. Answered your question above.

Updated the README and the name of the python script to langchain-llama-stack
Added fixes to the README file.
removed some dead code
Changing the langchain dir name
Changed the langChain dir name to langchain
@omaryashraf5 omaryashraf5 changed the title feat: Added llama stack-langChain integration example scripts feat: Added llama stack-langchain integration example scripts Aug 22, 2025
@@ -0,0 +1,288 @@
import os
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm this is not a notebook I guess

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashwinb Its a script but it can be converted to a Jupyter notebook.

Copy link
Collaborator

@mattf mattf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this still creates its own LLM and uses a deprecated api. please collaborate with @slekkala1

@omaryashraf5 omaryashraf5 marked this pull request as draft August 27, 2025 00:21
@omaryashraf5
Copy link
Author

this still creates its own LLM and uses a deprecated api. please collaborate with @slekkala1

@mattf now using langchain-openai

@omaryashraf5 omaryashraf5 marked this pull request as ready for review August 28, 2025 21:38
@mattf
Copy link
Collaborator

mattf commented Aug 28, 2025

this still creates its own LLM and uses a deprecated api. please collaborate with @slekkala1

@mattf now using langchain-openai

it's not. need to push an update?

also, users aren't likely to have /home/omara, though maybe we should 😄

@omaryashraf5
Copy link
Author

this still creates its own LLM and uses a deprecated api. please collaborate with @slekkala1

@mattf now using langchain-openai

it's not. need to push an update?

also, users aren't likely to have /home/omara, though maybe we should 😄

@mattf the change wasn't pushed for conflicts. Let me change that asap.

Copy link
Collaborator

@mattf mattf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please run through the example to make sure it still works

source llama-env-py312/bin/activate

# Run the interactive CLI
cd /home/omara/langchain_llamastack
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

users aren't likely to have /home/omara, though maybe we should 😄

- Llama Stack server running on `http://localhost:8321/`
- Ollama or compatible model server

### Required Python Packages
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip this, it's duplicated in the setup

Before running either version, ensure your Llama Stack server is running:
```bash
# Start Llama Stack server (example)
llama stack run your-config --port 8321
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the config need to include, at least inference=...?

it looks like specific models need to be setup too

Copy link
Author

@omaryashraf5 omaryashraf5 Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattf yes, at least inference but there are instructions on how to start a llama stack server instance. We could add a link to these instructions.

### How to Run
```bash
# Activate environment
source llama-env-py312/bin/activate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already done

source llama-env-py312/bin/activate

# Run the interactive CLI
cd /langchain_llamastack
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did this come from?


# Run the interactive CLI
cd /langchain_llamastack
python langchain-llama-stack.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fails, missing dep

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was missing langchain_openai

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattf After adding langchain_openai, the script ran successfully.

@reluctantfuturist reluctantfuturist mentioned this pull request Aug 22, 2025
39 tasks
@@ -212,7 +212,7 @@ def main():
)
os.environ["OPENAI_API_KEY"] = "dummy"
os.environ["OPENAI_BASE_URL"] = "http://0.0.0.0:8321/v1/openai/v1"
llm = ChatOpenAI(model="ollama/llama3:70b-instruct")
llm = ChatOpenAI(model="ollama/llama3:70b-instruct", base_url="http://localhost:8321/v1/openai/v1")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why pass base_url and set the env var?

imho, skip the environ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants