From dddb93b85ca7b0c33eeadaa1d74011177255bdeb Mon Sep 17 00:00:00 2001 From: Paulina Kalicka <71526180+paulinek13@users.noreply.github.com> Date: Sat, 5 Apr 2025 14:28:56 +0200 Subject: [PATCH 1/5] add new section titled "LM Studio Support" --- doc/code/targets/1_openai_chat_target.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/code/targets/1_openai_chat_target.py b/doc/code/targets/1_openai_chat_target.py index 66fa443d10..e1dba8ef03 100644 --- a/doc/code/targets/1_openai_chat_target.py +++ b/doc/code/targets/1_openai_chat_target.py @@ -54,3 +54,16 @@ # - auth: The API key for authentication (`OPENAI_CHAT_KEY` environment variable). # - model_name: The model to use (`OPENAI_CHAT_MODEL` environment variable). For OpenAI, these are any available model name and are listed here: "https://platform.openai.com/docs/models". # +# ## LM Studio Support +# +# The `OpenAIChatTarget` also supports running with LM Studio, a GUI-based application that allows you to run local LLM models through an OpenAI-compatible API. To use PyRIT with LM Studio: +# +# 1. Install and run LM Studio, ensuring a model is loaded and the API server is running (typically at http://127.0.0.1:1234). +# 2. Configure your environment variables: +# ``` +# OPENAI_CHAT_ENDPOINT="http://127.0.0.1:1234/v1/chat/completions" +# OPENAI_CHAT_MODEL="your-model-api-identifier" # e.g., "phi-3.1-mini-128k-instruct" +# ``` +# Note: The `OPENAI_CHAT_MODEL` value should match the model's API identifier as shown in LM Studio. +# 3. Use the `OpenAIChatTarget` in your code as shown in the example above. +# \ No newline at end of file From 1efc79d86deea6fbdac072bd51019d209a5d317b Mon Sep 17 00:00:00 2001 From: Paulina Kalicka <71526180+paulinek13@users.noreply.github.com> Date: Sat, 5 Apr 2025 17:04:03 +0200 Subject: [PATCH 2/5] improve formatting --- doc/code/targets/1_openai_chat_target.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/code/targets/1_openai_chat_target.py b/doc/code/targets/1_openai_chat_target.py index e1dba8ef03..73a90c0ada 100644 --- a/doc/code/targets/1_openai_chat_target.py +++ b/doc/code/targets/1_openai_chat_target.py @@ -58,7 +58,7 @@ # # The `OpenAIChatTarget` also supports running with LM Studio, a GUI-based application that allows you to run local LLM models through an OpenAI-compatible API. To use PyRIT with LM Studio: # -# 1. Install and run LM Studio, ensuring a model is loaded and the API server is running (typically at http://127.0.0.1:1234). +# 1. Install and run LM Studio, ensuring a model is loaded and the API server is running (typically at `http://127.0.0.1:1234`). # 2. Configure your environment variables: # ``` # OPENAI_CHAT_ENDPOINT="http://127.0.0.1:1234/v1/chat/completions" @@ -66,4 +66,4 @@ # ``` # Note: The `OPENAI_CHAT_MODEL` value should match the model's API identifier as shown in LM Studio. # 3. Use the `OpenAIChatTarget` in your code as shown in the example above. -# \ No newline at end of file +# From d0ce6887e98efd1080f311b579a2c0f49ed24046 Mon Sep 17 00:00:00 2001 From: Paulina Kalicka <71526180+paulinek13@users.noreply.github.com> Date: Sat, 5 Apr 2025 17:05:07 +0200 Subject: [PATCH 3/5] use unordered list --- doc/code/targets/1_openai_chat_target.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/code/targets/1_openai_chat_target.py b/doc/code/targets/1_openai_chat_target.py index 73a90c0ada..d3e329b229 100644 --- a/doc/code/targets/1_openai_chat_target.py +++ b/doc/code/targets/1_openai_chat_target.py @@ -58,12 +58,12 @@ # # The `OpenAIChatTarget` also supports running with LM Studio, a GUI-based application that allows you to run local LLM models through an OpenAI-compatible API. To use PyRIT with LM Studio: # -# 1. Install and run LM Studio, ensuring a model is loaded and the API server is running (typically at `http://127.0.0.1:1234`). -# 2. Configure your environment variables: +# - Install and run LM Studio, ensuring a model is loaded and the API server is running (typically at `http://127.0.0.1:1234`). +# - Configure your environment variables: # ``` # OPENAI_CHAT_ENDPOINT="http://127.0.0.1:1234/v1/chat/completions" # OPENAI_CHAT_MODEL="your-model-api-identifier" # e.g., "phi-3.1-mini-128k-instruct" # ``` # Note: The `OPENAI_CHAT_MODEL` value should match the model's API identifier as shown in LM Studio. -# 3. Use the `OpenAIChatTarget` in your code as shown in the example above. +# - Use the `OpenAIChatTarget` in your code as shown in the example above. # From 312faaa31658ec6fabd8fa0297396f076baf8d63 Mon Sep 17 00:00:00 2001 From: Paulina Kalicka <71526180+paulinek13@users.noreply.github.com> Date: Sat, 5 Apr 2025 17:24:03 +0200 Subject: [PATCH 4/5] improve the new section --- doc/code/targets/1_openai_chat_target.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/doc/code/targets/1_openai_chat_target.py b/doc/code/targets/1_openai_chat_target.py index d3e329b229..e3877f42ee 100644 --- a/doc/code/targets/1_openai_chat_target.py +++ b/doc/code/targets/1_openai_chat_target.py @@ -56,14 +56,12 @@ # # ## LM Studio Support # -# The `OpenAIChatTarget` also supports running with LM Studio, a GUI-based application that allows you to run local LLM models through an OpenAI-compatible API. To use PyRIT with LM Studio: +# You can also use `OpenAIChatTarget` with [LM Studio](https://lmstudio.ai), a desktop app for running local LLMs with OpenAI-like endpoints. To set it up with PyRIT: # -# - Install and run LM Studio, ensuring a model is loaded and the API server is running (typically at `http://127.0.0.1:1234`). -# - Configure your environment variables: +# - Launch LM Studio, ensure a model is loaded, and verify that the API server is running (typically at `http://127.0.0.1:1234`). +# - Be sure to configure your environment variables: # ``` # OPENAI_CHAT_ENDPOINT="http://127.0.0.1:1234/v1/chat/completions" # OPENAI_CHAT_MODEL="your-model-api-identifier" # e.g., "phi-3.1-mini-128k-instruct" # ``` -# Note: The `OPENAI_CHAT_MODEL` value should match the model's API identifier as shown in LM Studio. -# - Use the `OpenAIChatTarget` in your code as shown in the example above. # From b1c71a756cfa360d6c9b1e477f772b672e89e65b Mon Sep 17 00:00:00 2001 From: Paulina Kalicka <71526180+paulinek13@users.noreply.github.com> Date: Sat, 5 Apr 2025 17:30:23 +0200 Subject: [PATCH 5/5] `jupytext --update --to notebook doc\code\targets\1_openai_chat_target.py` --- doc/code/targets/1_openai_chat_target.ipynb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/doc/code/targets/1_openai_chat_target.ipynb b/doc/code/targets/1_openai_chat_target.ipynb index 45e28ab1e3..b70343c1c5 100644 --- a/doc/code/targets/1_openai_chat_target.ipynb +++ b/doc/code/targets/1_openai_chat_target.ipynb @@ -70,11 +70,25 @@ "\n", "- endpoint: The API endpoint (`OPENAI_CHAT_ENDPOINT` environment variable). For OpenAI, these are just \"https://api.openai.com/v1/chat/completions\". For Ollama, even though `/api/chat` is referenced in its official documentation, the correct endpoint to use is `/v1/chat/completions` to ensure compatibility with OpenAI's response format.\n", "- auth: The API key for authentication (`OPENAI_CHAT_KEY` environment variable).\n", - "- model_name: The model to use (`OPENAI_CHAT_MODEL` environment variable). For OpenAI, these are any available model name and are listed here: \"https://platform.openai.com/docs/models\".\n" + "- model_name: The model to use (`OPENAI_CHAT_MODEL` environment variable). For OpenAI, these are any available model name and are listed here: \"https://platform.openai.com/docs/models\".\n", + "\n", + "## LM Studio Support\n", + "\n", + "You can also use `OpenAIChatTarget` with [LM Studio](https://lmstudio.ai), a desktop app for running local LLMs with OpenAI-like endpoints. To set it up with PyRIT:\n", + "\n", + "- Launch LM Studio, ensure a model is loaded, and verify that the API server is running (typically at `http://127.0.0.1:1234`).\n", + "- Be sure to configure your environment variables:\n", + " ```\n", + " OPENAI_CHAT_ENDPOINT=\"http://127.0.0.1:1234/v1/chat/completions\"\n", + " OPENAI_CHAT_MODEL=\"your-model-api-identifier\" # e.g., \"phi-3.1-mini-128k-instruct\"\n", + " ```\n" ] } ], "metadata": { + "jupytext": { + "main_language": "python" + }, "language_info": { "codemirror_mode": { "name": "ipython",