trame-llm 1.0.0__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.
- trame_llm-1.0.0/.gitignore +30 -0
- trame_llm-1.0.0/LICENSE +201 -0
- trame_llm-1.0.0/PKG-INFO +259 -0
- trame_llm-1.0.0/README.rst +218 -0
- trame_llm-1.0.0/pyproject.toml +124 -0
- trame_llm-1.0.0/src/trame/modules/llm.py +1 -0
- trame_llm-1.0.0/src/trame/widgets/llm.py +7 -0
- trame_llm-1.0.0/src/trame_llm/__init__.py +1 -0
- trame_llm-1.0.0/src/trame_llm/claude_code.py +218 -0
- trame_llm-1.0.0/src/trame_llm/conversations.py +88 -0
- trame_llm-1.0.0/src/trame_llm/core.py +710 -0
- trame_llm-1.0.0/src/trame_llm/history.py +61 -0
- trame_llm-1.0.0/src/trame_llm/module/__init__.py +25 -0
- trame_llm-1.0.0/src/trame_llm/module/serve/markdown.css +54 -0
- trame_llm-1.0.0/src/trame_llm/module/serve/react/trame-llm-react.css +1 -0
- trame_llm-1.0.0/src/trame_llm/module/serve/react/trame-llm-react.umd.js +9 -0
- trame_llm-1.0.0/src/trame_llm/module/serve/speech.js +83 -0
- trame_llm-1.0.0/src/trame_llm/module/serve/tones.css +9 -0
- trame_llm-1.0.0/src/trame_llm/render.py +12 -0
- trame_llm-1.0.0/src/trame_llm/text_tool_calls.py +98 -0
- trame_llm-1.0.0/src/trame_llm/usage.py +154 -0
- trame_llm-1.0.0/src/trame_llm/widgets/__init__.py +0 -0
- trame_llm-1.0.0/src/trame_llm/widgets/llm.py +1127 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
node_modules
|
|
3
|
+
.venv
|
|
4
|
+
.env
|
|
5
|
+
|
|
6
|
+
# local env files
|
|
7
|
+
.env.local
|
|
8
|
+
.env.*.local
|
|
9
|
+
|
|
10
|
+
# Log files
|
|
11
|
+
npm-debug.log*
|
|
12
|
+
yarn-debug.log*
|
|
13
|
+
yarn-error.log*
|
|
14
|
+
pnpm-debug.log*
|
|
15
|
+
|
|
16
|
+
# Editor directories and files
|
|
17
|
+
.idea
|
|
18
|
+
.vscode
|
|
19
|
+
*.suo
|
|
20
|
+
*.ntvs*
|
|
21
|
+
*.njsproj
|
|
22
|
+
*.sln
|
|
23
|
+
*.sw?
|
|
24
|
+
|
|
25
|
+
__pycache__
|
|
26
|
+
*egg-info
|
|
27
|
+
*pyc
|
|
28
|
+
|
|
29
|
+
react-components/node_modules
|
|
30
|
+
src/trame_llm/module/serve/react
|
trame_llm-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
trame_llm-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: trame-llm
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: LLM helpers and components for trame
|
|
5
|
+
Author: Kitware Inc.
|
|
6
|
+
License: Apache Software License
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: Application,Framework,Interactive,Python,Web
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Requires-Dist: fastmcp<=2.13.0.2,>=2.12
|
|
19
|
+
Requires-Dist: markdown
|
|
20
|
+
Requires-Dist: nh3
|
|
21
|
+
Requires-Dist: openai>=1
|
|
22
|
+
Requires-Dist: python-dotenv
|
|
23
|
+
Requires-Dist: trame-client>=3.10
|
|
24
|
+
Provides-Extra: claude
|
|
25
|
+
Requires-Dist: claude-agent-sdk>=0.2; extra == 'claude'
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: nox; extra == 'dev'
|
|
28
|
+
Requires-Dist: pre-commit; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-cov>=3; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=6; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
32
|
+
Provides-Extra: examples
|
|
33
|
+
Requires-Dist: trame; extra == 'examples'
|
|
34
|
+
Requires-Dist: trame-vtk; extra == 'examples'
|
|
35
|
+
Requires-Dist: vtk; extra == 'examples'
|
|
36
|
+
Provides-Extra: react
|
|
37
|
+
Requires-Dist: trame-mui; extra == 'react'
|
|
38
|
+
Provides-Extra: vue
|
|
39
|
+
Requires-Dist: trame-vuetify>=3.3; extra == 'vue'
|
|
40
|
+
Description-Content-Type: text/x-rst
|
|
41
|
+
|
|
42
|
+
Trame LLM
|
|
43
|
+
----------------------------------------
|
|
44
|
+
|
|
45
|
+
LLM helpers and components for trame
|
|
46
|
+
|
|
47
|
+
License
|
|
48
|
+
----------------------------------------
|
|
49
|
+
|
|
50
|
+
This library is OpenSource and follow the Apache Software License
|
|
51
|
+
|
|
52
|
+
Installation
|
|
53
|
+
----------------------------------------
|
|
54
|
+
|
|
55
|
+
Install the library with the extra for your client:
|
|
56
|
+
|
|
57
|
+
.. code-block:: console
|
|
58
|
+
|
|
59
|
+
pip install "trame-llm[vue]" # Vue apps (Vuetify)
|
|
60
|
+
pip install "trame-llm[react]" # React apps (MUI)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
Configuration
|
|
64
|
+
----------------------------------------
|
|
65
|
+
|
|
66
|
+
trame-llm works with any OpenAI-compatible API. Environment variables (or a
|
|
67
|
+
``.env`` file) choose the provider and model the app starts with:
|
|
68
|
+
|
|
69
|
+
.. list-table::
|
|
70
|
+
:header-rows: 1
|
|
71
|
+
|
|
72
|
+
* - Variable
|
|
73
|
+
- Description
|
|
74
|
+
* - ``LLM_PROVIDER``
|
|
75
|
+
- ``openai`` (default), ``anthropic``, ``gemini``, ``nim``, ``llama``
|
|
76
|
+
or ``claude-code``
|
|
77
|
+
* - ``LLM_MODEL``
|
|
78
|
+
- Model name; each provider has a default (see below)
|
|
79
|
+
* - ``LLM_API_KEY``
|
|
80
|
+
- API key for the chosen provider
|
|
81
|
+
* - ``LLM_BASEURL``
|
|
82
|
+
- API endpoint for the chosen provider, for example a local server
|
|
83
|
+
|
|
84
|
+
Each provider also reads its own key variable, so several can be ready at once:
|
|
85
|
+
|
|
86
|
+
.. list-table::
|
|
87
|
+
:header-rows: 1
|
|
88
|
+
|
|
89
|
+
* - Provider
|
|
90
|
+
- Key variable
|
|
91
|
+
- Default model
|
|
92
|
+
* - ``openai``
|
|
93
|
+
- ``OPENAI_API_KEY``
|
|
94
|
+
- ``gpt-4o``
|
|
95
|
+
* - ``anthropic``
|
|
96
|
+
- ``ANTHROPIC_API_KEY``
|
|
97
|
+
- ``claude-opus-4-5``
|
|
98
|
+
* - ``gemini``
|
|
99
|
+
- ``GEMINI_API_KEY``
|
|
100
|
+
- ``gemini-2.0-flash``
|
|
101
|
+
* - ``nim``
|
|
102
|
+
- ``NVIDIA_API_KEY``
|
|
103
|
+
- ``meta/llama-3.3-70b-instruct``
|
|
104
|
+
* - ``llama`` (Ollama, LM Studio)
|
|
105
|
+
- none needed
|
|
106
|
+
- ``llama3``
|
|
107
|
+
|
|
108
|
+
Example ``.env`` for Ollama::
|
|
109
|
+
|
|
110
|
+
LLM_PROVIDER=llama
|
|
111
|
+
LLM_MODEL=qwen3-coder-next:q4_K_M
|
|
112
|
+
LLM_BASEURL=http://localhost:11434/v1
|
|
113
|
+
|
|
114
|
+
While the app runs, ``LLMClient.select(provider=..., model=..., api_key=...,
|
|
115
|
+
base_url=...)`` switches provider or model and keeps the conversation, and
|
|
116
|
+
``llm.ModelPicker(llm_client=...)`` gives users a form for it. The picker never
|
|
117
|
+
sends API keys to the browser; it only shows whether a key is set.
|
|
118
|
+
|
|
119
|
+
Conversations
|
|
120
|
+
----------------------------------------
|
|
121
|
+
|
|
122
|
+
The chat panel keeps several conversations, each with its own model history,
|
|
123
|
+
and saves each one after every turn as a JSON file in
|
|
124
|
+
``~/.trame-llm/conversations/<app_name>``. Pass ``conversations_dir`` to save
|
|
125
|
+
them elsewhere, or ``conversations_dir=False`` to keep them in memory. The list
|
|
126
|
+
in the panel switches, renames, pins and deletes conversations. A reply always
|
|
127
|
+
lands in the conversation that asked for it, even if the user has switched to
|
|
128
|
+
another one meanwhile. Each turn's steps (tool calls, their results and
|
|
129
|
+
progress notes) fold into one collapsible block, so the request and the reply
|
|
130
|
+
stay easy to follow. Apps driving the client directly can do the same with
|
|
131
|
+
``llm_client.process_prompt(prompt, messages=..., progress=...)``.
|
|
132
|
+
|
|
133
|
+
MCP servers
|
|
134
|
+
----------------------------------------
|
|
135
|
+
|
|
136
|
+
An app gives the model tools by registering MCP servers. A controller object
|
|
137
|
+
with an ``mcp`` property runs in the app's own process; a running server is
|
|
138
|
+
reached by URL (streamable HTTP, or SSE for URLs ending in ``/sse``):
|
|
139
|
+
|
|
140
|
+
.. code-block:: python
|
|
141
|
+
|
|
142
|
+
llm_client.register_mcp(controller)
|
|
143
|
+
await llm_client.add_mcp_server("http://localhost:8765/mcp")
|
|
144
|
+
llm_client.set_tool_enabled("multiply", False)
|
|
145
|
+
|
|
146
|
+
``llm.McpServers(llm_client=...)`` lets users do the same: add a server by URL,
|
|
147
|
+
reconnect or remove it, and turn its tools on or off.
|
|
148
|
+
|
|
149
|
+
Claude Code
|
|
150
|
+
----------------------------------------
|
|
151
|
+
|
|
152
|
+
The ``claude-code`` provider runs each turn through Claude Code with the Claude
|
|
153
|
+
login on the machine running the app, so people can use their Claude plan
|
|
154
|
+
instead of an API key.
|
|
155
|
+
|
|
156
|
+
Set it up on the machine that runs the app:
|
|
157
|
+
|
|
158
|
+
1. Install the extra. It brings the Agent SDK, which bundles Claude Code:
|
|
159
|
+
|
|
160
|
+
.. code-block:: console
|
|
161
|
+
|
|
162
|
+
pip install "trame-llm[claude]"
|
|
163
|
+
|
|
164
|
+
2. Sign in with your Claude account. The command prints a link; over SSH, open
|
|
165
|
+
it in your local browser and paste the code back. ``status`` shows who is
|
|
166
|
+
signed in.
|
|
167
|
+
|
|
168
|
+
.. code-block:: console
|
|
169
|
+
|
|
170
|
+
python -m trame_llm.claude_code login
|
|
171
|
+
python -m trame_llm.claude_code status
|
|
172
|
+
|
|
173
|
+
3. Start the app with ``LLM_PROVIDER=claude-code`` (and ``LLM_MODEL`` set to
|
|
174
|
+
``sonnet``, ``opus`` or ``haiku``), or choose "Claude Code" in the model
|
|
175
|
+
picker.
|
|
176
|
+
|
|
177
|
+
On a server where an interactive login is awkward,
|
|
178
|
+
``python -m trame_llm.claude_code setup-token`` creates a long-lived token;
|
|
179
|
+
give it to the app as ``CLAUDE_CODE_OAUTH_TOKEN``.
|
|
180
|
+
|
|
181
|
+
Claude Code can only call the app's MCP tools: its own tools (shell, files,
|
|
182
|
+
web) are off, the user's Claude Code settings are not loaded, and tools turned
|
|
183
|
+
off in the MCP servers panel are denied. Each conversation resumes its Claude
|
|
184
|
+
Code session. One login serves everyone using the app, so this suits a local
|
|
185
|
+
app or one process per user. Programmatic use of Claude Code draws on the
|
|
186
|
+
plan's Agent SDK allowance; check Anthropic's current terms.
|
|
187
|
+
|
|
188
|
+
Message colors
|
|
189
|
+
----------------------------------------
|
|
190
|
+
|
|
191
|
+
Each message has a tone that names its meaning: ``user``, ``assistant``,
|
|
192
|
+
``info``, ``tool``, ``success``, ``warning`` or ``error``. The Vue and React
|
|
193
|
+
panels both color messages from the matching CSS variable, so an app can
|
|
194
|
+
restyle them in one place:
|
|
195
|
+
|
|
196
|
+
.. code-block:: css
|
|
197
|
+
|
|
198
|
+
:root {
|
|
199
|
+
--trame-llm-assistant: #d1c4e9;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
Examples
|
|
203
|
+
----------------------------------------
|
|
204
|
+
|
|
205
|
+
``examples/widgets/app.py`` shows the chat panel with a sample conversation
|
|
206
|
+
that covers each message style, and the model picker in the app bar. Run it
|
|
207
|
+
with the Vue or the React client:
|
|
208
|
+
|
|
209
|
+
.. code-block:: console
|
|
210
|
+
|
|
211
|
+
python examples/widgets/app.py
|
|
212
|
+
python examples/widgets/app.py --react
|
|
213
|
+
|
|
214
|
+
From a source checkout, build the React components first with
|
|
215
|
+
``npm ci && npm run build`` in ``react-components``.
|
|
216
|
+
|
|
217
|
+
``examples/widgets/mcp_server.py`` is a small MCP server to add by URL
|
|
218
|
+
(``http://localhost:8765/mcp``). ``examples/cone/app.py`` drives a VTK cone
|
|
219
|
+
through an MCP server.
|
|
220
|
+
|
|
221
|
+
Development setup
|
|
222
|
+
----------------------------------------
|
|
223
|
+
|
|
224
|
+
We recommend using uv for setting up and managing a virtual environment for your development.
|
|
225
|
+
|
|
226
|
+
.. code-block:: console
|
|
227
|
+
|
|
228
|
+
# Create venv and install all dependencies
|
|
229
|
+
uv sync --all-extras --dev
|
|
230
|
+
|
|
231
|
+
# Activate environment
|
|
232
|
+
source .venv/bin/activate
|
|
233
|
+
|
|
234
|
+
# Install commit analysis
|
|
235
|
+
pre-commit install
|
|
236
|
+
pre-commit install --hook-type commit-msg
|
|
237
|
+
|
|
238
|
+
# Allow live code edit
|
|
239
|
+
uv pip install -e .
|
|
240
|
+
|
|
241
|
+
For running tests and checks, you can run ``nox``.
|
|
242
|
+
|
|
243
|
+
.. code-block:: console
|
|
244
|
+
|
|
245
|
+
# run all
|
|
246
|
+
nox
|
|
247
|
+
|
|
248
|
+
# lint
|
|
249
|
+
nox -s lint
|
|
250
|
+
|
|
251
|
+
# tests
|
|
252
|
+
nox -s tests
|
|
253
|
+
|
|
254
|
+
Professional Support
|
|
255
|
+
----------------------------------------
|
|
256
|
+
|
|
257
|
+
* `Training <https://www.kitware.com/courses/trame/>`_: Learn how to confidently use trame from the expert developers at Kitware.
|
|
258
|
+
* `Support <https://www.kitware.com/trame/support/>`_: Our experts can assist your team as you build your web application and establish in-house expertise.
|
|
259
|
+
* `Custom Development <https://www.kitware.com/trame/support/>`_: Leverage Kitware’s 25+ years of experience to quickly build your web application.
|