cozeloop 0.1.25__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. cozeloop-0.1.25/LICENSE +21 -0
  2. cozeloop-0.1.25/PKG-INFO +100 -0
  3. cozeloop-0.1.25/README.md +73 -0
  4. cozeloop-0.1.25/cozeloop/__init__.py +35 -0
  5. cozeloop-0.1.25/cozeloop/_client.py +520 -0
  6. cozeloop-0.1.25/cozeloop/_noop.py +79 -0
  7. cozeloop-0.1.25/cozeloop/client.py +28 -0
  8. cozeloop-0.1.25/cozeloop/decorator/__init__.py +8 -0
  9. cozeloop-0.1.25/cozeloop/decorator/decorator.py +638 -0
  10. cozeloop-0.1.25/cozeloop/decorator/utils.py +25 -0
  11. cozeloop-0.1.25/cozeloop/entities/__init__.py +9 -0
  12. cozeloop-0.1.25/cozeloop/entities/prompt.py +152 -0
  13. cozeloop-0.1.25/cozeloop/entities/stream.py +36 -0
  14. cozeloop-0.1.25/cozeloop/integration/__init__.py +3 -0
  15. cozeloop-0.1.25/cozeloop/integration/langchain/__init__.py +3 -0
  16. cozeloop-0.1.25/cozeloop/integration/langchain/trace_callback.py +618 -0
  17. cozeloop-0.1.25/cozeloop/integration/langchain/trace_model/__init__.py +32 -0
  18. cozeloop-0.1.25/cozeloop/integration/langchain/trace_model/llm_model.py +282 -0
  19. cozeloop-0.1.25/cozeloop/integration/langchain/trace_model/prompt_template.py +57 -0
  20. cozeloop-0.1.25/cozeloop/integration/langchain/trace_model/runtime.py +35 -0
  21. cozeloop-0.1.25/cozeloop/integration/langchain/util.py +60 -0
  22. cozeloop-0.1.25/cozeloop/integration/wrapper/__init__.py +3 -0
  23. cozeloop-0.1.25/cozeloop/integration/wrapper/_openai.py +273 -0
  24. cozeloop-0.1.25/cozeloop/internal/__init__.py +5 -0
  25. cozeloop-0.1.25/cozeloop/internal/consts/__init__.py +122 -0
  26. cozeloop-0.1.25/cozeloop/internal/consts/error.py +138 -0
  27. cozeloop-0.1.25/cozeloop/internal/httpclient/__init__.py +8 -0
  28. cozeloop-0.1.25/cozeloop/internal/httpclient/auth.py +90 -0
  29. cozeloop-0.1.25/cozeloop/internal/httpclient/auth_client.py +214 -0
  30. cozeloop-0.1.25/cozeloop/internal/httpclient/base_model.py +9 -0
  31. cozeloop-0.1.25/cozeloop/internal/httpclient/client.py +233 -0
  32. cozeloop-0.1.25/cozeloop/internal/httpclient/http_client.py +82 -0
  33. cozeloop-0.1.25/cozeloop/internal/httpclient/user_agent.py +38 -0
  34. cozeloop-0.1.25/cozeloop/internal/idgen/__init__.py +8 -0
  35. cozeloop-0.1.25/cozeloop/internal/idgen/idgen.py +71 -0
  36. cozeloop-0.1.25/cozeloop/internal/prompt/__init__.py +4 -0
  37. cozeloop-0.1.25/cozeloop/internal/prompt/cache.py +118 -0
  38. cozeloop-0.1.25/cozeloop/internal/prompt/converter.py +437 -0
  39. cozeloop-0.1.25/cozeloop/internal/prompt/execute_stream_reader.py +226 -0
  40. cozeloop-0.1.25/cozeloop/internal/prompt/openapi.py +275 -0
  41. cozeloop-0.1.25/cozeloop/internal/prompt/prompt.py +521 -0
  42. cozeloop-0.1.25/cozeloop/internal/stream/__init__.py +11 -0
  43. cozeloop-0.1.25/cozeloop/internal/stream/base_stream_reader.py +273 -0
  44. cozeloop-0.1.25/cozeloop/internal/stream/sse.py +224 -0
  45. cozeloop-0.1.25/cozeloop/internal/trace/__init__.py +8 -0
  46. cozeloop-0.1.25/cozeloop/internal/trace/exporter.py +434 -0
  47. cozeloop-0.1.25/cozeloop/internal/trace/model/__init__.py +3 -0
  48. cozeloop-0.1.25/cozeloop/internal/trace/model/model.py +69 -0
  49. cozeloop-0.1.25/cozeloop/internal/trace/noop_span.py +135 -0
  50. cozeloop-0.1.25/cozeloop/internal/trace/queue_manager.py +185 -0
  51. cozeloop-0.1.25/cozeloop/internal/trace/span.py +737 -0
  52. cozeloop-0.1.25/cozeloop/internal/trace/span_processor.py +241 -0
  53. cozeloop-0.1.25/cozeloop/internal/trace/trace.py +164 -0
  54. cozeloop-0.1.25/cozeloop/internal/utils/__init__.py +19 -0
  55. cozeloop-0.1.25/cozeloop/internal/utils/convert.py +116 -0
  56. cozeloop-0.1.25/cozeloop/internal/utils/get.py +24 -0
  57. cozeloop-0.1.25/cozeloop/internal/utils/validation.py +35 -0
  58. cozeloop-0.1.25/cozeloop/internal/version.py +4 -0
  59. cozeloop-0.1.25/cozeloop/logger.py +34 -0
  60. cozeloop-0.1.25/cozeloop/prompt.py +89 -0
  61. cozeloop-0.1.25/cozeloop/span.py +253 -0
  62. cozeloop-0.1.25/cozeloop/spec/__init__.py +3 -0
  63. cozeloop-0.1.25/cozeloop/spec/tracespec/__init__.py +9 -0
  64. cozeloop-0.1.25/cozeloop/spec/tracespec/model.py +106 -0
  65. cozeloop-0.1.25/cozeloop/spec/tracespec/prompt.py +30 -0
  66. cozeloop-0.1.25/cozeloop/spec/tracespec/retriever.py +23 -0
  67. cozeloop-0.1.25/cozeloop/spec/tracespec/runtime.py +18 -0
  68. cozeloop-0.1.25/cozeloop/spec/tracespec/span_key.py +40 -0
  69. cozeloop-0.1.25/cozeloop/spec/tracespec/span_value.py +40 -0
  70. cozeloop-0.1.25/cozeloop/trace.py +48 -0
  71. cozeloop-0.1.25/pyproject.toml +24 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,100 @@
1
+ Metadata-Version: 2.4
2
+ Name: cozeloop
3
+ Version: 0.1.25
4
+ Summary: coze loop sdk
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: JiangQi715
8
+ Author-email: jiangqi.rrt@bytedance.com
9
+ Requires-Python: >=3.8,<4.0
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Requires-Dist: apscheduler (>=3.11.0,<4.0.0)
20
+ Requires-Dist: authlib (>=1.2.0,<2.0.0)
21
+ Requires-Dist: cachetools (>=5.5.2,<7.0.0)
22
+ Requires-Dist: httpx (>=0.23.0,<1.0.0)
23
+ Requires-Dist: jinja2 (>=3.1.6,<4.0.0)
24
+ Requires-Dist: pydantic (>=1.10.12,<3.0.0)
25
+ Description-Content-Type: text/markdown
26
+
27
+ # CozeLoop Python SDK
28
+ English | [简体中文](README.zh_CN.md)
29
+
30
+ ## Overview
31
+
32
+ The CozeLoop SDK is a Python client for interacting with [CozeLoop platform](https://loop.coze.cn).
33
+ Key features:
34
+ - Report trace
35
+ - Get and format prompt
36
+ - Execute Prompt as a Service (PTaaS)
37
+
38
+ ## Requirements
39
+ - Python 3.8 or higher
40
+
41
+ ## Installation
42
+
43
+ `pip install CozeLoop`
44
+
45
+ ## Usage
46
+
47
+ ### Initialize
48
+
49
+ To get started, visit https://www.coze.cn/open/oauth/apps and create an OAuth app.
50
+ Then you can get your owner appid, public key and private key.
51
+
52
+ Set your environment variables:
53
+ ```bash
54
+ export COZELOOP_WORKSPACE_ID=your workspace id
55
+ export COZELOOP_JWT_OAUTH_CLIENT_ID=your client id
56
+ export COZELOOP_JWT_OAUTH_PRIVATE_KEY=your private key
57
+ export COZELOOP_JWT_OAUTH_PUBLIC_KEY_ID=your public key id
58
+ ```
59
+
60
+ ### Report Trace
61
+
62
+ ```python
63
+ def main():
64
+ span = cozeloop.start_span("root", "custom")
65
+
66
+ span.set_input("Hello")
67
+ span.set_output("World")
68
+
69
+ span.finish()
70
+
71
+ cozeloop.close()
72
+ ```
73
+
74
+ ### Get Prompt
75
+ ```python
76
+ def main():
77
+ prompt = cozeloop.get_prompt(prompt_key="your_prompt_key")
78
+ messages = cozeloop.prompt_format(
79
+ prompt,
80
+ {"var1": "your content"},
81
+ )
82
+ ```
83
+
84
+ You can see more examples [here](examples).
85
+
86
+ ## Contribution
87
+
88
+ Please check [Contributing](CONTRIBUTING.md) for more details.
89
+
90
+ ## Security
91
+
92
+ If you discover a potential security issue in this project, or think you may
93
+ have discovered a security issue, we ask that you notify Bytedance Security via our [security center](https://security.bytedance.com/src) or [vulnerability reporting email](sec@bytedance.com).
94
+
95
+ Please do **not** create a public GitHub issue.
96
+
97
+ ## License
98
+
99
+ This project is licensed under the [MIT License](LICENSE).
100
+
@@ -0,0 +1,73 @@
1
+ # CozeLoop Python SDK
2
+ English | [简体中文](README.zh_CN.md)
3
+
4
+ ## Overview
5
+
6
+ The CozeLoop SDK is a Python client for interacting with [CozeLoop platform](https://loop.coze.cn).
7
+ Key features:
8
+ - Report trace
9
+ - Get and format prompt
10
+ - Execute Prompt as a Service (PTaaS)
11
+
12
+ ## Requirements
13
+ - Python 3.8 or higher
14
+
15
+ ## Installation
16
+
17
+ `pip install CozeLoop`
18
+
19
+ ## Usage
20
+
21
+ ### Initialize
22
+
23
+ To get started, visit https://www.coze.cn/open/oauth/apps and create an OAuth app.
24
+ Then you can get your owner appid, public key and private key.
25
+
26
+ Set your environment variables:
27
+ ```bash
28
+ export COZELOOP_WORKSPACE_ID=your workspace id
29
+ export COZELOOP_JWT_OAUTH_CLIENT_ID=your client id
30
+ export COZELOOP_JWT_OAUTH_PRIVATE_KEY=your private key
31
+ export COZELOOP_JWT_OAUTH_PUBLIC_KEY_ID=your public key id
32
+ ```
33
+
34
+ ### Report Trace
35
+
36
+ ```python
37
+ def main():
38
+ span = cozeloop.start_span("root", "custom")
39
+
40
+ span.set_input("Hello")
41
+ span.set_output("World")
42
+
43
+ span.finish()
44
+
45
+ cozeloop.close()
46
+ ```
47
+
48
+ ### Get Prompt
49
+ ```python
50
+ def main():
51
+ prompt = cozeloop.get_prompt(prompt_key="your_prompt_key")
52
+ messages = cozeloop.prompt_format(
53
+ prompt,
54
+ {"var1": "your content"},
55
+ )
56
+ ```
57
+
58
+ You can see more examples [here](examples).
59
+
60
+ ## Contribution
61
+
62
+ Please check [Contributing](CONTRIBUTING.md) for more details.
63
+
64
+ ## Security
65
+
66
+ If you discover a potential security issue in this project, or think you may
67
+ have discovered a security issue, we ask that you notify Bytedance Security via our [security center](https://security.bytedance.com/src) or [vulnerability reporting email](sec@bytedance.com).
68
+
69
+ Please do **not** create a public GitHub issue.
70
+
71
+ ## License
72
+
73
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ from .entities.prompt import Prompt, Message
5
+ from .logger import set_log_level, add_log_handler
6
+
7
+ from .internal import __version__
8
+ from .internal.consts import (
9
+ CN_BASE_URL,
10
+ )
11
+ from .internal.consts.error import *
12
+
13
+ from .client import Client
14
+ from ._client import (
15
+ new_client,
16
+ set_default_client,
17
+ workspace_id,
18
+ close,
19
+ get_prompt,
20
+ prompt_format,
21
+ execute_prompt,
22
+ aexecute_prompt,
23
+ start_span,
24
+ get_span_from_context,
25
+ get_span_from_header,
26
+ flush,
27
+ ENV_API_BASE_URL,
28
+ ENV_WORKSPACE_ID,
29
+ ENV_API_TOKEN,
30
+ ENV_JWT_OAUTH_CLIENT_ID,
31
+ ENV_JWT_OAUTH_PRIVATE_KEY,
32
+ ENV_JWT_OAUTH_PUBLIC_KEY_ID
33
+ )
34
+
35
+ from .span import SpanContext, Span