Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
77f9e8ce
Unverified
Commit
77f9e8ce
authored
Jan 03, 2024
by
Chenhe Gu
Committed by
GitHub
Jan 03, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add example api url endpoint in placeholder (#1887)
Co-authored-by:
takatost
<
takatost@gmail.com
>
parent
5ca4c4a4
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
59 deletions
+121
-59
llm.py
..._runtime/model_providers/openai_api_compatible/llm/llm.py
+96
-52
openai_api_compatible.yaml
...roviders/openai_api_compatible/openai_api_compatible.yaml
+2
-2
text_embedding.py
...rs/openai_api_compatible/text_embedding/text_embedding.py
+23
-5
No files found.
api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py
View file @
77f9e8ce
This diff is collapsed.
Click to expand it.
api/core/model_runtime/model_providers/openai_api_compatible/openai_api_compatible.yaml
View file @
77f9e8ce
...
@@ -33,8 +33,8 @@ model_credential_schema:
...
@@ -33,8 +33,8 @@ model_credential_schema:
type
:
text-input
type
:
text-input
required
:
true
required
:
true
placeholder
:
placeholder
:
zh_Hans
:
在此输入您的 API endpoint URL
zh_Hans
:
Base URL, eg. https://api.openai.com/v1
en_US
:
Enter your API endpoint URL
en_US
:
Base URL, eg. https://api.openai.com/v1
-
variable
:
mode
-
variable
:
mode
show_on
:
show_on
:
-
variable
:
__model_type
-
variable
:
__model_type
...
...
api/core/model_runtime/model_providers/openai_api_compatible/text_embedding/text_embedding.py
View file @
77f9e8ce
import
time
import
time
from
decimal
import
Decimal
from
decimal
import
Decimal
from
typing
import
Optional
from
typing
import
Optional
from
urllib.parse
import
urljoin
import
requests
import
requests
import
json
import
json
...
@@ -42,8 +43,11 @@ class OAICompatEmbeddingModel(_CommonOAI_API_Compat, TextEmbeddingModel):
...
@@ -42,8 +43,11 @@ class OAICompatEmbeddingModel(_CommonOAI_API_Compat, TextEmbeddingModel):
if
api_key
:
if
api_key
:
headers
[
"Authorization"
]
=
f
"Bearer {api_key}"
headers
[
"Authorization"
]
=
f
"Bearer {api_key}"
endpoint_url
=
credentials
.
get
(
'endpoint_url'
)
if
not
endpoint_url
.
endswith
(
'/'
):
endpoint_url
+=
'/'
endpoint_url
=
credentials
[
'endpoint_url'
]
endpoint_url
=
urljoin
(
endpoint_url
,
'embeddings'
)
extra_model_kwargs
=
{}
extra_model_kwargs
=
{}
if
user
:
if
user
:
...
@@ -144,8 +148,11 @@ class OAICompatEmbeddingModel(_CommonOAI_API_Compat, TextEmbeddingModel):
...
@@ -144,8 +148,11 @@ class OAICompatEmbeddingModel(_CommonOAI_API_Compat, TextEmbeddingModel):
if
api_key
:
if
api_key
:
headers
[
"Authorization"
]
=
f
"Bearer {api_key}"
headers
[
"Authorization"
]
=
f
"Bearer {api_key}"
endpoint_url
=
credentials
.
get
(
'endpoint_url'
)
if
not
endpoint_url
.
endswith
(
'/'
):
endpoint_url
+=
'/'
endpoint_url
=
credentials
[
'endpoint_url'
]
endpoint_url
=
urljoin
(
endpoint_url
,
'embeddings'
)
payload
=
{
payload
=
{
'input'
:
'ping'
,
'input'
:
'ping'
,
...
@@ -160,8 +167,19 @@ class OAICompatEmbeddingModel(_CommonOAI_API_Compat, TextEmbeddingModel):
...
@@ -160,8 +167,19 @@ class OAICompatEmbeddingModel(_CommonOAI_API_Compat, TextEmbeddingModel):
)
)
if
response
.
status_code
!=
200
:
if
response
.
status_code
!=
200
:
raise
CredentialsValidateFailedError
(
f
"Invalid response status: {response.status_code}"
)
raise
CredentialsValidateFailedError
(
f
'Credentials validation failed with status code {response.status_code}'
)
try
:
json_result
=
response
.
json
()
except
json
.
JSONDecodeError
as
e
:
raise
CredentialsValidateFailedError
(
f
'Credentials validation failed: JSON decode error'
)
if
'model'
not
in
json_result
:
raise
CredentialsValidateFailedError
(
f
'Credentials validation failed: invalid response'
)
except
CredentialsValidateFailedError
:
raise
except
Exception
as
ex
:
except
Exception
as
ex
:
raise
CredentialsValidateFailedError
(
str
(
ex
))
raise
CredentialsValidateFailedError
(
str
(
ex
))
...
@@ -175,7 +193,7 @@ class OAICompatEmbeddingModel(_CommonOAI_API_Compat, TextEmbeddingModel):
...
@@ -175,7 +193,7 @@ class OAICompatEmbeddingModel(_CommonOAI_API_Compat, TextEmbeddingModel):
model_type
=
ModelType
.
TEXT_EMBEDDING
,
model_type
=
ModelType
.
TEXT_EMBEDDING
,
fetch_from
=
FetchFrom
.
CUSTOMIZABLE_MODEL
,
fetch_from
=
FetchFrom
.
CUSTOMIZABLE_MODEL
,
model_properties
=
{
model_properties
=
{
ModelPropertyKey
.
CONTEXT_SIZE
:
credentials
.
get
(
'context_size'
),
ModelPropertyKey
.
CONTEXT_SIZE
:
int
(
credentials
.
get
(
'context_size'
)
),
ModelPropertyKey
.
MAX_CHUNKS
:
1
,
ModelPropertyKey
.
MAX_CHUNKS
:
1
,
},
},
parameter_rules
=
[],
parameter_rules
=
[],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment