-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'langgenius:main' into main
- Loading branch information
Showing
34 changed files
with
539 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,8 @@ parameter_rules: | |
default: 1024 | ||
min: 1 | ||
max: 8192 | ||
pricing: | ||
input: '0.1' | ||
output: '0.1' | ||
unit: '0.001' | ||
currency: RMB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
- bing | ||
- perplexity | ||
- duckduckgo | ||
- searchapi | ||
- serper | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import Any | ||
|
||
import requests | ||
|
||
from core.tools.errors import ToolProviderCredentialValidationError | ||
from core.tools.provider.builtin.perplexity.tools.perplexity_search import PERPLEXITY_API_URL | ||
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController | ||
|
||
|
||
class PerplexityProvider(BuiltinToolProviderController): | ||
def _validate_credentials(self, credentials: dict[str, Any]) -> None: | ||
headers = { | ||
"Authorization": f"Bearer {credentials.get('perplexity_api_key')}", | ||
"Content-Type": "application/json" | ||
} | ||
|
||
payload = { | ||
"model": "llama-3.1-sonar-small-128k-online", | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are a helpful assistant." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "Hello" | ||
} | ||
], | ||
"max_tokens": 5, | ||
"temperature": 0.1, | ||
"top_p": 0.9, | ||
"stream": False | ||
} | ||
|
||
try: | ||
response = requests.post(PERPLEXITY_API_URL, json=payload, headers=headers) | ||
response.raise_for_status() | ||
except requests.RequestException as e: | ||
raise ToolProviderCredentialValidationError( | ||
f"Failed to validate Perplexity API key: {str(e)}" | ||
) | ||
|
||
if response.status_code != 200: | ||
raise ToolProviderCredentialValidationError( | ||
f"Perplexity API key is invalid. Status code: {response.status_code}" | ||
) |
26 changes: 26 additions & 0 deletions
26
api/core/tools/provider/builtin/perplexity/perplexity.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
identity: | ||
author: Dify | ||
name: perplexity | ||
label: | ||
en_US: Perplexity | ||
zh_Hans: Perplexity | ||
description: | ||
en_US: Perplexity.AI | ||
zh_Hans: Perplexity.AI | ||
icon: icon.svg | ||
tags: | ||
- search | ||
credentials_for_provider: | ||
perplexity_api_key: | ||
type: secret-input | ||
required: true | ||
label: | ||
en_US: Perplexity API key | ||
zh_Hans: Perplexity API key | ||
placeholder: | ||
en_US: Please input your Perplexity API key | ||
zh_Hans: 请输入你的 Perplexity API key | ||
help: | ||
en_US: Get your Perplexity API key from Perplexity | ||
zh_Hans: 从 Perplexity 获取您的 Perplexity API key | ||
url: https://www.perplexity.ai/settings/api |
Oops, something went wrong.