Co-authored-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
@@ -23,21 +23,17 @@ def test_validate_credentials():
|
||||
|
||||
with pytest.raises(CredentialsValidateFailedError):
|
||||
model.validate_credentials(
|
||||
model='mistralai/Mixtral-8x7B-Instruct-v0.1',
|
||||
credentials={
|
||||
'api_key': 'invalid_key',
|
||||
'endpoint_url': 'https://api.together.xyz/v1/',
|
||||
'mode': 'chat'
|
||||
}
|
||||
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
||||
credentials={"api_key": "invalid_key", "endpoint_url": "https://api.together.xyz/v1/", "mode": "chat"},
|
||||
)
|
||||
|
||||
model.validate_credentials(
|
||||
model='mistralai/Mixtral-8x7B-Instruct-v0.1',
|
||||
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
||||
credentials={
|
||||
'api_key': os.environ.get('TOGETHER_API_KEY'),
|
||||
'endpoint_url': 'https://api.together.xyz/v1/',
|
||||
'mode': 'chat'
|
||||
}
|
||||
"api_key": os.environ.get("TOGETHER_API_KEY"),
|
||||
"endpoint_url": "https://api.together.xyz/v1/",
|
||||
"mode": "chat",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -45,28 +41,26 @@ def test_invoke_model():
|
||||
model = OAIAPICompatLargeLanguageModel()
|
||||
|
||||
response = model.invoke(
|
||||
model='mistralai/Mixtral-8x7B-Instruct-v0.1',
|
||||
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
||||
credentials={
|
||||
'api_key': os.environ.get('TOGETHER_API_KEY'),
|
||||
'endpoint_url': 'https://api.together.xyz/v1/',
|
||||
'mode': 'completion'
|
||||
"api_key": os.environ.get("TOGETHER_API_KEY"),
|
||||
"endpoint_url": "https://api.together.xyz/v1/",
|
||||
"mode": "completion",
|
||||
},
|
||||
prompt_messages=[
|
||||
SystemPromptMessage(
|
||||
content='You are a helpful AI assistant.',
|
||||
content="You are a helpful AI assistant.",
|
||||
),
|
||||
UserPromptMessage(
|
||||
content='Who are you?'
|
||||
)
|
||||
UserPromptMessage(content="Who are you?"),
|
||||
],
|
||||
model_parameters={
|
||||
'temperature': 1.0,
|
||||
'top_k': 2,
|
||||
'top_p': 0.5,
|
||||
"temperature": 1.0,
|
||||
"top_k": 2,
|
||||
"top_p": 0.5,
|
||||
},
|
||||
stop=['How'],
|
||||
stop=["How"],
|
||||
stream=False,
|
||||
user="abc-123"
|
||||
user="abc-123",
|
||||
)
|
||||
|
||||
assert isinstance(response, LLMResult)
|
||||
@@ -77,29 +71,27 @@ def test_invoke_stream_model():
|
||||
model = OAIAPICompatLargeLanguageModel()
|
||||
|
||||
response = model.invoke(
|
||||
model='mistralai/Mixtral-8x7B-Instruct-v0.1',
|
||||
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
||||
credentials={
|
||||
'api_key': os.environ.get('TOGETHER_API_KEY'),
|
||||
'endpoint_url': 'https://api.together.xyz/v1/',
|
||||
'mode': 'chat',
|
||||
'stream_mode_delimiter': '\\n\\n'
|
||||
"api_key": os.environ.get("TOGETHER_API_KEY"),
|
||||
"endpoint_url": "https://api.together.xyz/v1/",
|
||||
"mode": "chat",
|
||||
"stream_mode_delimiter": "\\n\\n",
|
||||
},
|
||||
prompt_messages=[
|
||||
SystemPromptMessage(
|
||||
content='You are a helpful AI assistant.',
|
||||
content="You are a helpful AI assistant.",
|
||||
),
|
||||
UserPromptMessage(
|
||||
content='Who are you?'
|
||||
)
|
||||
UserPromptMessage(content="Who are you?"),
|
||||
],
|
||||
model_parameters={
|
||||
'temperature': 1.0,
|
||||
'top_k': 2,
|
||||
'top_p': 0.5,
|
||||
"temperature": 1.0,
|
||||
"top_k": 2,
|
||||
"top_p": 0.5,
|
||||
},
|
||||
stop=['How'],
|
||||
stop=["How"],
|
||||
stream=True,
|
||||
user="abc-123"
|
||||
user="abc-123",
|
||||
)
|
||||
|
||||
assert isinstance(response, Generator)
|
||||
@@ -114,28 +106,26 @@ def test_invoke_stream_model_without_delimiter():
|
||||
model = OAIAPICompatLargeLanguageModel()
|
||||
|
||||
response = model.invoke(
|
||||
model='mistralai/Mixtral-8x7B-Instruct-v0.1',
|
||||
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
||||
credentials={
|
||||
'api_key': os.environ.get('TOGETHER_API_KEY'),
|
||||
'endpoint_url': 'https://api.together.xyz/v1/',
|
||||
'mode': 'chat'
|
||||
"api_key": os.environ.get("TOGETHER_API_KEY"),
|
||||
"endpoint_url": "https://api.together.xyz/v1/",
|
||||
"mode": "chat",
|
||||
},
|
||||
prompt_messages=[
|
||||
SystemPromptMessage(
|
||||
content='You are a helpful AI assistant.',
|
||||
content="You are a helpful AI assistant.",
|
||||
),
|
||||
UserPromptMessage(
|
||||
content='Who are you?'
|
||||
)
|
||||
UserPromptMessage(content="Who are you?"),
|
||||
],
|
||||
model_parameters={
|
||||
'temperature': 1.0,
|
||||
'top_k': 2,
|
||||
'top_p': 0.5,
|
||||
"temperature": 1.0,
|
||||
"top_k": 2,
|
||||
"top_p": 0.5,
|
||||
},
|
||||
stop=['How'],
|
||||
stop=["How"],
|
||||
stream=True,
|
||||
user="abc-123"
|
||||
user="abc-123",
|
||||
)
|
||||
|
||||
assert isinstance(response, Generator)
|
||||
@@ -151,51 +141,37 @@ def test_invoke_chat_model_with_tools():
|
||||
model = OAIAPICompatLargeLanguageModel()
|
||||
|
||||
result = model.invoke(
|
||||
model='gpt-3.5-turbo',
|
||||
model="gpt-3.5-turbo",
|
||||
credentials={
|
||||
'api_key': os.environ.get('OPENAI_API_KEY'),
|
||||
'endpoint_url': 'https://api.openai.com/v1/',
|
||||
'mode': 'chat'
|
||||
"api_key": os.environ.get("OPENAI_API_KEY"),
|
||||
"endpoint_url": "https://api.openai.com/v1/",
|
||||
"mode": "chat",
|
||||
},
|
||||
prompt_messages=[
|
||||
SystemPromptMessage(
|
||||
content='You are a helpful AI assistant.',
|
||||
content="You are a helpful AI assistant.",
|
||||
),
|
||||
UserPromptMessage(
|
||||
content="what's the weather today in London?",
|
||||
)
|
||||
),
|
||||
],
|
||||
tools=[
|
||||
PromptMessageTool(
|
||||
name='get_weather',
|
||||
description='Determine weather in my location',
|
||||
name="get_weather",
|
||||
description="Determine weather in my location",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "The city and state e.g. San Francisco, CA"
|
||||
},
|
||||
"unit": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"celsius",
|
||||
"fahrenheit"
|
||||
]
|
||||
}
|
||||
"location": {"type": "string", "description": "The city and state e.g. San Francisco, CA"},
|
||||
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
|
||||
},
|
||||
"required": [
|
||||
"location"
|
||||
]
|
||||
}
|
||||
"required": ["location"],
|
||||
},
|
||||
),
|
||||
],
|
||||
model_parameters={
|
||||
'temperature': 0.0,
|
||||
'max_tokens': 1024
|
||||
},
|
||||
model_parameters={"temperature": 0.0, "max_tokens": 1024},
|
||||
stream=False,
|
||||
user="abc-123"
|
||||
user="abc-123",
|
||||
)
|
||||
|
||||
assert isinstance(result, LLMResult)
|
||||
@@ -207,19 +183,14 @@ def test_get_num_tokens():
|
||||
model = OAIAPICompatLargeLanguageModel()
|
||||
|
||||
num_tokens = model.get_num_tokens(
|
||||
model='mistralai/Mixtral-8x7B-Instruct-v0.1',
|
||||
credentials={
|
||||
'api_key': os.environ.get('OPENAI_API_KEY'),
|
||||
'endpoint_url': 'https://api.openai.com/v1/'
|
||||
},
|
||||
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
||||
credentials={"api_key": os.environ.get("OPENAI_API_KEY"), "endpoint_url": "https://api.openai.com/v1/"},
|
||||
prompt_messages=[
|
||||
SystemPromptMessage(
|
||||
content='You are a helpful AI assistant.',
|
||||
content="You are a helpful AI assistant.",
|
||||
),
|
||||
UserPromptMessage(
|
||||
content='Hello World!'
|
||||
)
|
||||
]
|
||||
UserPromptMessage(content="Hello World!"),
|
||||
],
|
||||
)
|
||||
|
||||
assert isinstance(num_tokens, int)
|
||||
|
||||
@@ -14,18 +14,12 @@ def test_validate_credentials():
|
||||
with pytest.raises(CredentialsValidateFailedError):
|
||||
model.validate_credentials(
|
||||
model="whisper-1",
|
||||
credentials={
|
||||
"api_key": "invalid_key",
|
||||
"endpoint_url": "https://api.openai.com/v1/"
|
||||
},
|
||||
credentials={"api_key": "invalid_key", "endpoint_url": "https://api.openai.com/v1/"},
|
||||
)
|
||||
|
||||
model.validate_credentials(
|
||||
model="whisper-1",
|
||||
credentials={
|
||||
"api_key": os.environ.get("OPENAI_API_KEY"),
|
||||
"endpoint_url": "https://api.openai.com/v1/"
|
||||
},
|
||||
credentials={"api_key": os.environ.get("OPENAI_API_KEY"), "endpoint_url": "https://api.openai.com/v1/"},
|
||||
)
|
||||
|
||||
|
||||
@@ -47,13 +41,10 @@ def test_invoke_model():
|
||||
|
||||
result = model.invoke(
|
||||
model="whisper-1",
|
||||
credentials={
|
||||
"api_key": os.environ.get("OPENAI_API_KEY"),
|
||||
"endpoint_url": "https://api.openai.com/v1/"
|
||||
},
|
||||
credentials={"api_key": os.environ.get("OPENAI_API_KEY"), "endpoint_url": "https://api.openai.com/v1/"},
|
||||
file=file,
|
||||
user="abc-123",
|
||||
)
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert result == '1, 2, 3, 4, 5, 6, 7, 8, 9, 10'
|
||||
assert result == "1, 2, 3, 4, 5, 6, 7, 8, 9, 10"
|
||||
|
||||
@@ -12,27 +12,23 @@ from core.model_runtime.model_providers.openai_api_compatible.text_embedding.tex
|
||||
Using OpenAI's API as testing endpoint
|
||||
"""
|
||||
|
||||
|
||||
def test_validate_credentials():
|
||||
model = OAICompatEmbeddingModel()
|
||||
|
||||
with pytest.raises(CredentialsValidateFailedError):
|
||||
model.validate_credentials(
|
||||
model='text-embedding-ada-002',
|
||||
credentials={
|
||||
'api_key': 'invalid_key',
|
||||
'endpoint_url': 'https://api.openai.com/v1/',
|
||||
'context_size': 8184
|
||||
|
||||
}
|
||||
model="text-embedding-ada-002",
|
||||
credentials={"api_key": "invalid_key", "endpoint_url": "https://api.openai.com/v1/", "context_size": 8184},
|
||||
)
|
||||
|
||||
model.validate_credentials(
|
||||
model='text-embedding-ada-002',
|
||||
model="text-embedding-ada-002",
|
||||
credentials={
|
||||
'api_key': os.environ.get('OPENAI_API_KEY'),
|
||||
'endpoint_url': 'https://api.openai.com/v1/',
|
||||
'context_size': 8184
|
||||
}
|
||||
"api_key": os.environ.get("OPENAI_API_KEY"),
|
||||
"endpoint_url": "https://api.openai.com/v1/",
|
||||
"context_size": 8184,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -40,19 +36,14 @@ def test_invoke_model():
|
||||
model = OAICompatEmbeddingModel()
|
||||
|
||||
result = model.invoke(
|
||||
model='text-embedding-ada-002',
|
||||
model="text-embedding-ada-002",
|
||||
credentials={
|
||||
'api_key': os.environ.get('OPENAI_API_KEY'),
|
||||
'endpoint_url': 'https://api.openai.com/v1/',
|
||||
'context_size': 8184
|
||||
"api_key": os.environ.get("OPENAI_API_KEY"),
|
||||
"endpoint_url": "https://api.openai.com/v1/",
|
||||
"context_size": 8184,
|
||||
},
|
||||
texts=[
|
||||
"hello",
|
||||
"world",
|
||||
" ".join(["long_text"] * 100),
|
||||
" ".join(["another_long_text"] * 100)
|
||||
],
|
||||
user="abc-123"
|
||||
texts=["hello", "world", " ".join(["long_text"] * 100), " ".join(["another_long_text"] * 100)],
|
||||
user="abc-123",
|
||||
)
|
||||
|
||||
assert isinstance(result, TextEmbeddingResult)
|
||||
@@ -64,16 +55,13 @@ def test_get_num_tokens():
|
||||
model = OAICompatEmbeddingModel()
|
||||
|
||||
num_tokens = model.get_num_tokens(
|
||||
model='text-embedding-ada-002',
|
||||
model="text-embedding-ada-002",
|
||||
credentials={
|
||||
'api_key': os.environ.get('OPENAI_API_KEY'),
|
||||
'endpoint_url': 'https://api.openai.com/v1/embeddings',
|
||||
'context_size': 8184
|
||||
"api_key": os.environ.get("OPENAI_API_KEY"),
|
||||
"endpoint_url": "https://api.openai.com/v1/embeddings",
|
||||
"context_size": 8184,
|
||||
},
|
||||
texts=[
|
||||
"hello",
|
||||
"world"
|
||||
]
|
||||
texts=["hello", "world"],
|
||||
)
|
||||
|
||||
assert num_tokens == 2
|
||||
assert num_tokens == 2
|
||||
|
||||
Reference in New Issue
Block a user