Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New PF Tool: Open_Source_llm - Dev, Test, & Documentation #531

Merged
merged 36 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
37c20bc
[Open_Source_llm] Initial Setup
gjwoods Sep 15, 2023
64303c3
Add docs
gjwoods Sep 18, 2023
4ebe71b
Merge branch 'main' of https://github.com/gjwoods/promptflow into use…
gjwoods Sep 21, 2023
1d0eab5
Add tests and resolve
gjwoods Sep 25, 2023
6e9e03d
fix code quality
gjwoods Sep 25, 2023
b65b968
doc miss & whitespace
gjwoods Sep 25, 2023
944e19e
Merge branch 'microsoft:main' into users/gewoods/open_source_llm/initial
gjwoods Sep 25, 2023
893d7e8
Merge branch 'users/gewoods/open_source_llm/initial' of https://githu…
gjwoods Sep 25, 2023
c4c4344
Merge branch 'main' into users/gewoods/open_source_llm/initial
gjwoods Sep 26, 2023
96a0477
Ignore tests & clean set
gjwoods Sep 26, 2023
84f7a75
Merge branch 'users/gewoods/open_source_llm/initial' of https://githu…
gjwoods Sep 26, 2023
27d8089
fix test connections
gjwoods Sep 26, 2023
156b674
flake
gjwoods Sep 26, 2023
7678f6e
Merge pull request #1 from gjwoods/users/gewoods/open_source_llm/initial
gjwoods Sep 26, 2023
48c17df
Merge branch 'main' into users/gewoods/open_source_llm/initial
gjwoods Sep 26, 2023
165dc9e
Automated Pull Master Merge Tue 09/26/202311:46:35.80
gjwoods Sep 26, 2023
e9abc85
restore deployment_name values
gjwoods Sep 26, 2023
70b6ae5
Merge branch 'users/gewoods/open_source_llm/initial' of https://githu…
gjwoods Sep 26, 2023
f0a38ec
test name
gjwoods Sep 26, 2023
7331734
Merge pull request #5 from gjwoods/users/gewoods/open_source_llm/initial
gjwoods Sep 26, 2023
62ff1d9
Merge branch 'microsoft:main' into main
gjwoods Sep 27, 2023
c11fd1b
update for review comments
gjwoods Sep 27, 2023
b5920bc
code qual
gjwoods Sep 27, 2023
99349f6
Merge branch 'main' into users/gewoods/open_source_llm/initial
gjwoods Sep 27, 2023
25ef9cb
flake sucks
gjwoods Sep 27, 2023
f9eefca
Merge branch 'users/gewoods/open_source_llm/initial' of https://githu…
gjwoods Sep 27, 2023
4140569
Merge branch 'main' into users/gewoods/open_source_llm/initial
chjinche Sep 27, 2023
d468c81
Merge branch 'main' into users/gewoods/open_source_llm/initial
chjinche Sep 27, 2023
c6816d8
Review comments
gjwoods Sep 28, 2023
640b41a
Update documentation
gjwoods Sep 28, 2023
fa18abd
spelling issue
gjwoods Sep 28, 2023
5b815fd
Merge branch 'microsoft:main' into main
gjwoods Sep 28, 2023
f80b564
Merge branch 'main' of https://github.com/gjwoods/promptflow into use…
gjwoods Sep 28, 2023
6d0f143
Merge branch 'main' into users/gewoods/open_source_llm/initial
chjinche Sep 28, 2023
5e7e114
Merge branch 'main' into users/gewoods/open_source_llm/initial
chjinche Sep 28, 2023
a108fd9
Merge branch 'main' into users/gewoods/open_source_llm/initial
gjwoods Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
"aggr",
"tcsetattr",
"pysqlite",
"AADSTS700082"
"AADSTS700082",
"Mobius"
],
"allowCompoundWords": true
}
1 change: 1 addition & 0 deletions docs/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tools-reference/serp-api-tool
tools-reference/faiss_index_lookup_tool
tools-reference/vector_db_lookup_tool
tools-reference/embedding_tool
tools-reference/open_source_llm_tool
```
gjwoods marked this conversation as resolved.
Show resolved Hide resolved

```{toctree}
Expand Down
58 changes: 58 additions & 0 deletions docs/reference/tools-reference/open_source_llm_tool.md
gjwoods marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Open Source LLM

## Introduction

The Prompt flow Open Source LLM tool enables you to utilize a variety of Open Source and Foundational Models, such as [Falcon](https://aka.ms/AAlc25c) or [Llama 2](https://aka.ms/AAlc258) for natural language processing, in PromptFlow.

This Prompt flow supports two different LLM API types:

- **Completion**: to generate text based on provided prompts.
- **Chat**: to facilitate interactive conversations with text-based inputs and responses.

## Prerequisite

1. Pick the model to use with from the [Azure Machine Learning model catalog](https://ml.azure.com/model/catalog).
2. Use the "Deploy" button to deploy the model to AzureML Inference endpoint.

More detailed instructions can be found here [Deploying foundation models to endpoints for inferencing.](https://learn.microsoft.com/en-us/azure/machine-learning/how-to-use-foundation-models?view=azureml-api-2#deploying-foundation-models-to-endpoints-for-inferencing)

## **Connections**

Setup connections to provisioned resources in prompt flow.

| Type | Name | API KEY | API Type | API Version |
|-------------|----------|----------|----------|-------------|
| CustomConnection | Required | Required | - | - |

Instructions to create a Custom Connection [can be found here.](https://learn.microsoft.com/en-us/azure/machine-learning/prompt-flow/how-to-integrate-with-langchain?view=azureml-api-2#create-a-connection)
gjwoods marked this conversation as resolved.
Show resolved Hide resolved

The keys to set are:

1. endpoint_url
2. endpoint_api_key
gjwoods marked this conversation as resolved.
Show resolved Hide resolved
3. model_family
gjwoods marked this conversation as resolved.
Show resolved Hide resolved

*These values can be found at the previously created Inferencing endpoint.*

## Inputs

| Name | Type | Description | Required |
|------------------------|-------------|-----------------------------------------------------------------------------------------|----------|
| api | string | this will be Completion or Chat, depending on the scenario selected | Yes |
| connection | CustomConnection | the name of the connection which points to the Inferencing endpoint | Yes |
| model_kwargs | dictionary | generic model configuration values, for example temperature | Yes |
| prompt | string | text prompt that the language model will complete | Yes |

## Outputs

| API | Return Type | Description |
|------------|-------------|------------------------------------------|
| Completion | string | The text of one predicted completion |
| Chat | string | The text of one response of conversation |

## How to use Open Source LLM Tool?

1. Choose a Model from the catalog and deploy.
2. Setup and select the connections to model deployment.
3. Configure the model api and its parameters
4. Prepare the Prompt with [guidance](./prompt-tool.md#how-to-write-prompt).
gjwoods marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 5 additions & 2 deletions src/promptflow-tools/promptflow/tools/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
from promptflow.tools.exception import ChatAPIInvalidRole, WrappedOpenAIError, LLMError, JinjaTemplateError, \
ExceedMaxRetryTimes, ChatAPIInvalidFunctions, FunctionCallNotSupportedInStreamMode, \
ChatAPIFunctionRoleInvalidFormat
from typing import List


def validate_role(role):
valid_roles = {"system", "user", "assistant", "function"}
def validate_role(role: str, valid_roles: List[str] = None):
gjwoods marked this conversation as resolved.
Show resolved Hide resolved
if not valid_roles:
valid_roles = {"system", "user", "assistant", "function"}

if role not in valid_roles:
valid_roles_str = ','.join([f'\'{role}:\\n\''for role in valid_roles])
error_message = (
Expand Down
21 changes: 21 additions & 0 deletions src/promptflow-tools/promptflow/tools/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,24 @@ class SerpAPIUserError(UserErrorException):

def __init__(self, **kwargs):
super().__init__(**kwargs, target=ErrorTarget.TOOL)


class OpenSourceLLMOnlineEndpointError(UserErrorException):
"""Base exception raised when the call to an online endpoint failed."""

def __init__(self, **kwargs):
super().__init__(**kwargs, target=ErrorTarget.TOOL)


class OpenSourceLLMUserError(UserErrorException):
"""Base exception raised when the call to Open Source LLM failed with a user error."""

def __init__(self, **kwargs):
super().__init__(**kwargs, target=ErrorTarget.TOOL)


class OpenSourceLLMKeyValidationError(ToolValidationError):
"""Base exception raised when failed to validate functions when call chat api."""

def __init__(self, **kwargs):
super().__init__(**kwargs)
Loading