add local nim changes

This commit is contained in:
raspawar
2025-01-02 13:38:19 +05:30
parent 7c7d3f26f7
commit 3196e54f03
4 changed files with 29 additions and 7 deletions

View File

@@ -4,10 +4,11 @@
This is a simple example using the CrewAI framework with an NVIDIA endpoint and langchain-nvidia-ai-endpoints integration.
## Running the Script
This example uses the Azure OpenAI API to call a model.
This example show cases the NVIDIA NIM endpoint integration with CrewAI.
- **Configure Environment**: Set NVIDIA_API_KEY to appropriate api key.
Set MODEL to select appropriate model
Set NVIDIA_API_URL to select the endpoint(Catalogue/local endpoint)
- **Install Dependencies**: Run `make install`.
- **Execute the Script**: Run `python main.py` to see a list of recommended changes to this document.

View File

@@ -116,7 +116,8 @@ class nvllm(LLM):
model = os.environ.get("MODEL", "meta/llama-3.1-8b-instruct")
llm = ChatNVIDIA(model=model)
api_base = os.environ.get("NVIDIA_API_URL", "https://integrate.api.nvidia.com/v1")
llm = ChatNVIDIA(model=model, base_url=api_base)
default_llm = nvllm(model_str="nvidia_nim/" + model, llm=llm)
os.environ["NVIDIA_NIM_API_KEY"] = os.environ.get("NVIDIA_API_KEY")

View File

@@ -51,7 +51,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -69,6 +69,18 @@
" os.environ[\"NVIDIA_API_KEY\"] = nvapi_key"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# set API Endoipoint\n",
"# to call local model set NVIDIA_API_URL to local NIM endpoint\n",
"os.environ[\"NVIDIA_API_URL\"] = \"http://localhost:8000/v1\" # for local NIM container\n",
"# os.environ[\"NVIDIA_API_URL\"] = \"https://integrate.api.nvidia.com/v1\""
]
},
{
"cell_type": "markdown",
"metadata": {},
@@ -78,12 +90,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#set model\n",
"os.environ[\"MODEL\"] = \"meta/llama-3.1-8b-instruct\""
"os.environ[\"MODEL\"] = \"meta/llama-2-7b-chat\""
]
},
{
@@ -95,7 +107,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -110,6 +122,13 @@
"source": [
"run()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {

View File

@@ -16,7 +16,8 @@ from langchain_nvidia_ai_endpoints import ChatNVIDIA
load_dotenv()
model = os.getenv("MODEL", "meta/llama-3.1-8b-instruct")
llm = ChatNVIDIA(model=model)
api_base = os.environ.get("NVIDIA_API_URL", "https://integrate.api.nvidia.com/v1")
llm = ChatNVIDIA(model=model, base_url=api_base)
default_llm = nvllm(model_str="nvidia_nim/" + model, llm=llm)
os.environ["NVIDIA_API_KEY"] = os.getenv("NVIDIA_API_KEY")