WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
131 changes: 126 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions promptlayer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,8 @@ def cleaned_result(self):
if stop_reason:
final_result.stop_reason = stop_reason
return final_result
else:
return deepcopy(self.results[-1])

# OpenAI and other providers
if hasattr(self.results[0].choices[0], "text"): # this is regular completion
response = ""
for result in self.results:
Expand All @@ -891,9 +891,7 @@ def cleaned_result(self):
if hasattr(result.choices[0].delta, "role") and result.choices[0].delta.role is not None:
response["role"] = result.choices[0].delta.role
if hasattr(result.choices[0].delta, "content") and result.choices[0].delta.content is not None:
response["content"] = response["content"] = (
f"{response['content']}{result.choices[0].delta.content}"
)
response["content"] = f"{response['content']}{result.choices[0].delta.content}"
final_result = deepcopy(self.results[-1])
final_result.choices[0] = response
return final_result
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pydantic = "^2.11.7"
pydantic-settings = "^2.10.1"
boto3 = "^1.35.0"
aioboto3 = "^13.0.0"
pre-commit = "^4.3.0"

[build-system]
requires = ["poetry-core"]
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
anthropic_client,
openai_async_client,
openai_client,
openai_compatible_api_key,
openai_compatible_client,
promptlayer_async_client,
promptlayer_client,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
interactions:
- request:
body: '{"messages": [{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of China? Answer in one sentence."}],
"model": "deepseek-chat", "stream": true}'
headers:
Authorization:
- sanitized
accept:
- application/json
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- '193'
content-type:
- application/json
host:
- api.deepseek.com
user-agent:
- OpenAI/Python 1.60.1
x-stainless-arch:
- arm64
x-stainless-async:
- 'false'
x-stainless-lang:
- python
x-stainless-os:
- MacOS
x-stainless-package-version:
- 1.60.1
x-stainless-retry-count:
- '0'
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.13.4
method: POST
uri: https://api.deepseek.com/beta/chat/completions
response:
body:
string: 'data: {"id":"0f12a0f7-1142-4b7f-94f0-14432d543e56","object":"chat.completion.chunk","created":1759203810,"model":"deepseek-chat","system_fingerprint":"fp_ffc7281d48_prod0820_fp8_kvcache","choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]}


data: {"id":"0f12a0f7-1142-4b7f-94f0-14432d543e56","object":"chat.completion.chunk","created":1759203810,"model":"deepseek-chat","system_fingerprint":"fp_ffc7281d48_prod0820_fp8_kvcache","choices":[{"index":0,"delta":{"content":"The"},"logprobs":null,"finish_reason":null}]}


data: {"id":"0f12a0f7-1142-4b7f-94f0-14432d543e56","object":"chat.completion.chunk","created":1759203810,"model":"deepseek-chat","system_fingerprint":"fp_ffc7281d48_prod0820_fp8_kvcache","choices":[{"index":0,"delta":{"content":"
capital"},"logprobs":null,"finish_reason":null}]}


data: {"id":"0f12a0f7-1142-4b7f-94f0-14432d543e56","object":"chat.completion.chunk","created":1759203810,"model":"deepseek-chat","system_fingerprint":"fp_ffc7281d48_prod0820_fp8_kvcache","choices":[{"index":0,"delta":{"content":"
of"},"logprobs":null,"finish_reason":null}]}


data: {"id":"0f12a0f7-1142-4b7f-94f0-14432d543e56","object":"chat.completion.chunk","created":1759203810,"model":"deepseek-chat","system_fingerprint":"fp_ffc7281d48_prod0820_fp8_kvcache","choices":[{"index":0,"delta":{"content":"
China"},"logprobs":null,"finish_reason":null}]}


data: {"id":"0f12a0f7-1142-4b7f-94f0-14432d543e56","object":"chat.completion.chunk","created":1759203810,"model":"deepseek-chat","system_fingerprint":"fp_ffc7281d48_prod0820_fp8_kvcache","choices":[{"index":0,"delta":{"content":"
is"},"logprobs":null,"finish_reason":null}]}


data: {"id":"0f12a0f7-1142-4b7f-94f0-14432d543e56","object":"chat.completion.chunk","created":1759203810,"model":"deepseek-chat","system_fingerprint":"fp_ffc7281d48_prod0820_fp8_kvcache","choices":[{"index":0,"delta":{"content":"
Beijing"},"logprobs":null,"finish_reason":null}]}


data: {"id":"0f12a0f7-1142-4b7f-94f0-14432d543e56","object":"chat.completion.chunk","created":1759203810,"model":"deepseek-chat","system_fingerprint":"fp_ffc7281d48_prod0820_fp8_kvcache","choices":[{"index":0,"delta":{"content":"."},"logprobs":null,"finish_reason":null}]}


data: {"id":"0f12a0f7-1142-4b7f-94f0-14432d543e56","object":"chat.completion.chunk","created":1759203810,"model":"deepseek-chat","system_fingerprint":"fp_ffc7281d48_prod0820_fp8_kvcache","choices":[{"index":0,"delta":{"content":""},"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":22,"completion_tokens":7,"total_tokens":29,"prompt_tokens_details":{"cached_tokens":0},"prompt_cache_hit_tokens":0,"prompt_cache_miss_tokens":22}}


data: [DONE]


'
headers:
Connection:
- keep-alive
Content-Type:
- text/event-stream; charset=utf-8
Date:
- Tue, 30 Sep 2025 03:43:30 GMT
Server:
- CW
Set-Cookie:
- HWWAFSESTIME=1759203809896; path=/
- HWWAFSESID=b8ff6799743aa04a94; path=/
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-allow-credentials:
- 'true'
cache-control:
- no-cache
vary:
- origin, access-control-request-method, access-control-request-headers
x-ds-trace-id:
- 3317092e58b76a99226aa9753487241b
status:
code: 200
message: OK
version: 1
13 changes: 13 additions & 0 deletions tests/fixtures/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,16 @@ def openai_client(promptlayer_client, openai_api_key):
@pytest.fixture
def openai_async_client(promptlayer_client, openai_api_key):
return promptlayer_client.openai.AsyncOpenAI(api_key=openai_api_key)


@pytest.fixture
def openai_compatible_api_key():
import os

return os.environ.get("OPENAI_COMPATIBLE_API_KEY", "sk-sanitized")


@pytest.fixture
def openai_compatible_client(promptlayer_client, openai_compatible_api_key):
# Use DeepSeek API (OpenAI compatible) here
return promptlayer_client.openai.OpenAI(api_key=openai_compatible_api_key, base_url="https://api.deepseek.com/beta")
Loading