Files
dify-plugin-sdks/python/tests/entities/models/test_llm.py
QuantumGhost 5cb24625c3 ci(python): Add CI Pipeline for Python SDK (#72)
* chore(python): temporarily disable `UP007` rule in Ruff

Disable the `UP007` rule temporarily due to numerous existing
violations in the current codebase.

* ci(python): add lint and test for Python SDK

* ci: Add mega-linter

* chore(python): Add final newline to markdown files

* fix(python): Fix linter issues by using ruff's auto fix

* fix(python): Fix TRY400 linter violations

Ruff suggests using `logger.exception` to log when
logging an exception, instead of using `logging.error`.

The former logs the exception and the traceback
automatically.

ref: https://docs.astral.sh/ruff/rules/error-instead-of-exception/

* fix(python): fix ruff linter violations

* test(python): Add Test cases for LLM entities

Test the initialization of `LLMResult` and `LLMResultChunk`.

* test(python): Add test for `AgentModelConfig`

Ensures that the `history_prompt_messages` attribute is
not shared between instances of `AgentModelConfig`.

* chore(python): output diffs in Ruff's format check

* style(python): format code with Ruff

* chore(python): Add a bash script for fix and format python code

* chore: add `persist-credentials: false` to checkout action

Enhances security by preventing subsequent
steps from accessing GitHub credentials, reducing
potential attack surfaces.

Ref: https://github.com/actions/checkout#checkout-v4
2025-04-14 20:25:19 +08:00

55 lines
1.6 KiB
Python

from dify_plugin.entities.model.llm import (
LLMResult,
LLMResultChunk,
LLMResultChunkDelta,
LLMUsage,
)
from dify_plugin.entities.model.message import (
AssistantPromptMessage,
PromptMessage,
PromptMessageRole,
)
class TestLLMResultChunk:
def test_init(self):
model = "gpt-4o"
delta = LLMResultChunkDelta(
index=0,
message=AssistantPromptMessage(content="Hello, World!", role=PromptMessageRole.ASSISTANT),
)
prompt_message = PromptMessage(
role=PromptMessageRole.USER,
content="Hello",
)
LLMResultChunk(model=model, delta=delta)
LLMResultChunk(model=model, delta=delta, system_fingerprint="123")
LLMResultChunk(model=model, prompt_messages=[], delta=delta, system_fingerprint="123")
LLMResultChunk(model=model, prompt_messages=[prompt_message], delta=delta, system_fingerprint="123")
class TestLLMResult:
def test_init(self):
model = "gpt-4o"
assistant_message = AssistantPromptMessage(content="Hello, World!", role=PromptMessageRole.ASSISTANT)
usage = LLMUsage.empty_usage()
prompt_message = PromptMessage(
role=PromptMessageRole.USER,
content="Hello",
)
LLMResult(model=model, message=assistant_message, usage=usage)
LLMResult(model=model, prompt_messages=[], message=assistant_message, usage=usage, system_fingerprint="123")
LLMResult(
model=model,
prompt_messages=[prompt_message],
message=assistant_message,
usage=usage,
system_fingerprint="123",
)