mirror of
https://github.com/crewAIInc/crewAI-examples.git
synced 2026-04-23 03:00:08 -04:00
add local nim changes
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user