machine-thinking 0.0.6__tar.gz → 0.0.7__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.
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/PKG-INFO +1 -1
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/pyproject.toml +1 -1
- machine_thinking-0.0.7/src/machine_thinking/messages.py +75 -0
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/src/machine_thinking/utils.py +17 -0
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/src/machine_thinking.egg-info/PKG-INFO +1 -1
- machine_thinking-0.0.6/src/machine_thinking/messages.py +0 -81
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/LICENSE +0 -0
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/README.md +0 -0
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/setup.cfg +0 -0
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/src/__init__.py +0 -0
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/src/machine_thinking/__init__.py +0 -0
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/src/machine_thinking/chat.py +0 -0
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/src/machine_thinking/completion.py +0 -0
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/src/machine_thinking.egg-info/SOURCES.txt +0 -0
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/src/machine_thinking.egg-info/dependency_links.txt +0 -0
- {machine_thinking-0.0.6 → machine_thinking-0.0.7}/src/machine_thinking.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: machine-thinking
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: Calling the API of 'Thinking-Machines Lab' models without dependencies.
|
|
5
5
|
Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>, Alexander Fedotov <alex.fedotov@aol.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/machina-ratiocinatrix/machine-thinking
|
|
@@ -3,7 +3,7 @@ requires = ["setuptools>=67.0"]
|
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
[project]
|
|
5
5
|
name = "machine-thinking"
|
|
6
|
-
version = "0.0.
|
|
6
|
+
version = "0.0.7"
|
|
7
7
|
authors = [
|
|
8
8
|
{name="Machina Ratiocinatrix", email="machina.ratio@gmail.com"},
|
|
9
9
|
{name="Alexander Fedotov", email="alex.fedotov@aol.com"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Python
|
|
3
|
+
|
|
4
|
+
"""Copyright (c) Alexander Fedotov.
|
|
5
|
+
This source code is licensed under the license found in the
|
|
6
|
+
LICENSE file in the root directory of this source tree.
|
|
7
|
+
"""
|
|
8
|
+
from .utils import (query,
|
|
9
|
+
default_model,
|
|
10
|
+
get_function,
|
|
11
|
+
get_func_args,
|
|
12
|
+
call_function,
|
|
13
|
+
api_base_ant,
|
|
14
|
+
decode)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def get_weather(location):
|
|
18
|
+
# print(f"Executing weather tool for location: {location}")
|
|
19
|
+
return {"temperature": "72F", "condition": "Sunny"}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def message(messages=None, instructions=None, tools=None, **kwargs):
|
|
23
|
+
"""A continuation of text with a given context and instruction.
|
|
24
|
+
"""
|
|
25
|
+
messages = kwargs.get('messages', messages)
|
|
26
|
+
|
|
27
|
+
payload = {
|
|
28
|
+
"model": kwargs.get("model", default_model),
|
|
29
|
+
"system": kwargs.get("system_instruction", instructions),
|
|
30
|
+
"messages": kwargs.get('messages', messages),
|
|
31
|
+
"thinking": kwargs.get('thinking', None),
|
|
32
|
+
"max_tokens": kwargs.get("max_tokens", 100),
|
|
33
|
+
"stop_sequences": kwargs.get("stop_sequences", ['stop']),
|
|
34
|
+
"stream": kwargs.get("stream", False),
|
|
35
|
+
"temperature": 1.0,
|
|
36
|
+
"output_config": kwargs.get("output_config", {}),
|
|
37
|
+
"metadata": kwargs.get("metadata", None)
|
|
38
|
+
}
|
|
39
|
+
if tools:
|
|
40
|
+
payload['tools'] = tools
|
|
41
|
+
payload['tool_choice'] = kwargs.get('tool_choice', {})
|
|
42
|
+
|
|
43
|
+
while True:
|
|
44
|
+
result = query(payload, '/messages', api_base_ant)
|
|
45
|
+
completion_message = result['content']
|
|
46
|
+
thoughts, text, function_calls = decode(completion_message)
|
|
47
|
+
if function_calls:
|
|
48
|
+
payload['messages'].append({"role": "assistant", "content": completion_message})
|
|
49
|
+
tools_results = []
|
|
50
|
+
# Call all requested functions and create response messages.
|
|
51
|
+
for function_call in function_calls:
|
|
52
|
+
call_id = function_call.get('id')
|
|
53
|
+
func_name = function_call.get('name', '')
|
|
54
|
+
func_args_def = function_call.get('input', '{}')
|
|
55
|
+
# Look up tool by name in globals and caller frames
|
|
56
|
+
func = get_function(func_name)
|
|
57
|
+
func_args = get_func_args(func_args_def)
|
|
58
|
+
result = call_function(func, func_args)
|
|
59
|
+
tool_message = {
|
|
60
|
+
"type": "tool_result",
|
|
61
|
+
"tool_use_id": call_id,
|
|
62
|
+
"content": result
|
|
63
|
+
}
|
|
64
|
+
tools_results.append(tool_message)
|
|
65
|
+
|
|
66
|
+
# Add results to payload and make a query.
|
|
67
|
+
payload['messages'].append({"role": "user", "content": tools_results})
|
|
68
|
+
|
|
69
|
+
else:
|
|
70
|
+
break
|
|
71
|
+
|
|
72
|
+
return thoughts, text
|
|
73
|
+
|
|
74
|
+
if __name__ == '__main__':
|
|
75
|
+
...
|
|
@@ -105,3 +105,20 @@ def query(payload, url_suffix, url_prefix=None):
|
|
|
105
105
|
# Handle network/connection errors
|
|
106
106
|
print(f"Failed to reach the server: {e.reason}")
|
|
107
107
|
return {}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def decode(output):
|
|
111
|
+
text = ''
|
|
112
|
+
thoughts = ''
|
|
113
|
+
for chunk in output:
|
|
114
|
+
chunk_type = chunk.get('type', '')
|
|
115
|
+
if chunk_type == 'text':
|
|
116
|
+
addition = chunk.get('text', '')
|
|
117
|
+
if addition not in ('\n\n', '\n'):
|
|
118
|
+
text += addition
|
|
119
|
+
|
|
120
|
+
elif chunk_type == 'thinking':
|
|
121
|
+
thoughts += chunk.get('thinking', '')
|
|
122
|
+
function_calls = [part for part in output if part['type'] == 'tool_use']
|
|
123
|
+
|
|
124
|
+
return thoughts, text, function_calls
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: machine-thinking
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: Calling the API of 'Thinking-Machines Lab' models without dependencies.
|
|
5
5
|
Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>, Alexander Fedotov <alex.fedotov@aol.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/machina-ratiocinatrix/machine-thinking
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# Python
|
|
3
|
-
|
|
4
|
-
"""Copyright (c) Alexander Fedotov.
|
|
5
|
-
This source code is licensed under the license found in the
|
|
6
|
-
LICENSE file in the root directory of this source tree.
|
|
7
|
-
"""
|
|
8
|
-
from .utils import (query,
|
|
9
|
-
default_model,
|
|
10
|
-
get_function,
|
|
11
|
-
get_func_args,
|
|
12
|
-
call_function,
|
|
13
|
-
api_base_ant)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def get_weather(location):
|
|
17
|
-
# print(f"Executing weather tool for location: {location}")
|
|
18
|
-
return {"temperature": "72F", "condition": "Sunny"}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def message(messages=None, instructions=None, tools=None, **kwargs):
|
|
22
|
-
"""A continuation of text with a given context and instruction.
|
|
23
|
-
"""
|
|
24
|
-
messages = kwargs.get('messages', messages)
|
|
25
|
-
|
|
26
|
-
payload = {
|
|
27
|
-
'model': kwargs.get('model', default_model),
|
|
28
|
-
'system': kwargs.get('system', instructions),
|
|
29
|
-
'messages': kwargs.get('messages', messages),
|
|
30
|
-
'output_config': kwargs.get('output_config',{'effort': 'high'}),
|
|
31
|
-
'thinking': kwargs.get('thinking', {
|
|
32
|
-
'type': 'enabled',
|
|
33
|
-
'budget_tokens': 10000,
|
|
34
|
-
}),
|
|
35
|
-
'tool_choice': kwargs.get('tool_choice', {'type': 'auto', 'disable_parallel_tool_use': False}),
|
|
36
|
-
'max_tokens': kwargs.get('max_tokens', 4096),
|
|
37
|
-
'prompt_truncate_len': kwargs.get('prompt_truncate_len', 100000),
|
|
38
|
-
'n': kwargs.get('n', 1),
|
|
39
|
-
'top_p': kwargs.get('top_p', 0.9),
|
|
40
|
-
'top_k': kwargs.get('top_k', 10),
|
|
41
|
-
'stream': False
|
|
42
|
-
}
|
|
43
|
-
if tools:
|
|
44
|
-
payload['tools'] = tools
|
|
45
|
-
payload['parallel_tool_calls'] = True
|
|
46
|
-
payload['tool_choice'] = 'auto'
|
|
47
|
-
|
|
48
|
-
while True:
|
|
49
|
-
result = query(payload, '/messages', api_base_ant)
|
|
50
|
-
completion_message = result['choices'][0]['message']
|
|
51
|
-
messages.append(completion_message)
|
|
52
|
-
thoughts = completion_message.get('reasoning_content', '')
|
|
53
|
-
text = completion_message.get('content', '')
|
|
54
|
-
function_calls = completion_message.get('tool_calls', [])
|
|
55
|
-
|
|
56
|
-
if function_calls:
|
|
57
|
-
# Call all requested functions and create response messages.
|
|
58
|
-
for function_call in function_calls:
|
|
59
|
-
call_id = function_call.get('id')
|
|
60
|
-
func_def = function_call.get('function')
|
|
61
|
-
func_name = func_def.get('name', '')
|
|
62
|
-
|
|
63
|
-
# Look up tool by name in globals and caller frames
|
|
64
|
-
func = get_function(func_name)
|
|
65
|
-
func_args = get_func_args(func_def)
|
|
66
|
-
result = call_function(func, func_args)
|
|
67
|
-
|
|
68
|
-
tool_message = {
|
|
69
|
-
"role": "tool",
|
|
70
|
-
"tool_call_id": call_id,
|
|
71
|
-
"content": result
|
|
72
|
-
}
|
|
73
|
-
messages.append(tool_message)
|
|
74
|
-
else:
|
|
75
|
-
break
|
|
76
|
-
|
|
77
|
-
return thoughts, text
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if __name__ == '__main__':
|
|
81
|
-
...
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{machine_thinking-0.0.6 → machine_thinking-0.0.7}/src/machine_thinking.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{machine_thinking-0.0.6 → machine_thinking-0.0.7}/src/machine_thinking.egg-info/top_level.txt
RENAMED
|
File without changes
|