thinking-machine 0.1.8__tar.gz → 0.1.9__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.
- {thinking_machine-0.1.8/src/thinking_machine.egg-info → thinking_machine-0.1.9}/PKG-INFO +1 -1
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/pyproject.toml +1 -1
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/cli.py +4 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/machine.py +43 -1
- thinking_machine-0.1.9/src/thinking_machine/providers/illuminati.py +188 -0
- thinking_machine-0.1.9/src/thinking_machine/providers/tink.py +188 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9/src/thinking_machine.egg-info}/PKG-INFO +1 -1
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine.egg-info/SOURCES.txt +2 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/LICENSE +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/MANIFEST.in +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/README.md +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/setup.cfg +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/__init__.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/config.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/githf.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/machina.yaml +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/__init__.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/basta.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/camelids.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/castor_pollux.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/depsek.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/electroid.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/light.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/openai.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/qrog.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/strangelove.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/utilities.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine.egg-info/dependency_links.txt +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine.egg-info/entry_points.txt +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine.egg-info/requires.txt +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine.egg-info/top_level.txt +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/tests/test_cli.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/tests/test_e2e.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/tests/test_llm_soup.py +0 -0
- {thinking_machine-0.1.8 → thinking_machine-0.1.9}/tests/test_utilities.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: thinking-machine
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.9
|
|
4
4
|
Summary: A Machine that thinks.
|
|
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/thinking-machine
|
|
@@ -106,6 +106,10 @@ def run():
|
|
|
106
106
|
else:
|
|
107
107
|
if config.provider == 'Baseten':
|
|
108
108
|
os.environ['BASETEN_API_KEY'] = args.provider_api_key
|
|
109
|
+
elif config.provider == 'Fireworks':
|
|
110
|
+
os.environ['FIREWORKS_API_KEY'] = args.provider_api_key
|
|
111
|
+
elif config.provider == 'Tinker':
|
|
112
|
+
os.environ['TINKER_API_KEY'] = args.provider_api_key
|
|
109
113
|
elif config.provider == 'Lightning':
|
|
110
114
|
os.environ['LIGHTNING_API_KEY'] = args.provider_api_key
|
|
111
115
|
else:
|
|
@@ -15,7 +15,7 @@ from .utilities import (plato_text_to_muj,
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def machine(plato_text, config, **kwargs):
|
|
18
|
-
"""Core
|
|
18
|
+
"""Core machine logic.
|
|
19
19
|
|
|
20
20
|
1. Fetches the system prompt from a private GitHub repo.
|
|
21
21
|
2. Calls Provider
|
|
@@ -49,6 +49,27 @@ def machine(plato_text, config, **kwargs):
|
|
|
49
49
|
thoughts = llm_soup_to_text(thoughts)
|
|
50
50
|
return thoughts, text
|
|
51
51
|
|
|
52
|
+
elif provider == 'Tinker':
|
|
53
|
+
# Transform plato_text to MUJ format
|
|
54
|
+
messages = plato_text_to_muj(plato_text=plato_text,
|
|
55
|
+
machine_name=name)
|
|
56
|
+
# Call OpenAI API
|
|
57
|
+
environ['TINKER_API_KEY'] = api_key
|
|
58
|
+
try:
|
|
59
|
+
from .providers import tink
|
|
60
|
+
except ImportError:
|
|
61
|
+
print("openai module is missing.", file=sys.stderr)
|
|
62
|
+
sys.exit(1)
|
|
63
|
+
|
|
64
|
+
thoughts, text = tink.respond(
|
|
65
|
+
messages=messages,
|
|
66
|
+
instructions=system_prompt,
|
|
67
|
+
**kwargs
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
thoughts = llm_soup_to_text(thoughts)
|
|
71
|
+
return thoughts, text
|
|
72
|
+
|
|
52
73
|
elif provider == 'Gemini':
|
|
53
74
|
# Transform plato_text to MPUJ format
|
|
54
75
|
messages = plato_text_to_mpuj(plato_text=plato_text,
|
|
@@ -212,6 +233,27 @@ def machine(plato_text, config, **kwargs):
|
|
|
212
233
|
|
|
213
234
|
return thoughts, text
|
|
214
235
|
|
|
236
|
+
elif provider == 'Fireworks':
|
|
237
|
+
# Transform plato_text to MUJ format
|
|
238
|
+
messages = plato_text_to_muj(plato_text=plato_text,
|
|
239
|
+
machine_name=name)
|
|
240
|
+
# Call OpenAI API via opehaina
|
|
241
|
+
environ['FIREWORKS_API_KEY'] = api_key
|
|
242
|
+
try:
|
|
243
|
+
from .providers import illuminati
|
|
244
|
+
except ImportError:
|
|
245
|
+
print("illuminati module is missing.", file=sys.stderr)
|
|
246
|
+
sys.exit(1)
|
|
247
|
+
|
|
248
|
+
thoughts, text = illuminati.respond(
|
|
249
|
+
messages=messages,
|
|
250
|
+
instructions=system_prompt,
|
|
251
|
+
**kwargs
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
thoughts = llm_soup_to_text(thoughts)
|
|
255
|
+
return thoughts, text
|
|
256
|
+
|
|
215
257
|
|
|
216
258
|
if __name__ == '__main__':
|
|
217
259
|
print('You have launched main')
|
|
@@ -0,0 +1,188 @@
|
|
|
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
|
+
import json
|
|
9
|
+
import urllib.request
|
|
10
|
+
import urllib.error
|
|
11
|
+
from os import environ
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
api_key = environ.get("TINKER_API_KEY", '')
|
|
15
|
+
default_model = environ.get("TINKER_DEFAULT_MODEL", 'thinkingmachines/Inkling')
|
|
16
|
+
api_base_oai = environ.get("TINKER_OAI_API_BASE", 'https://tinker.thinkingmachines.dev/services/tinker-prod/oai/api/v1')
|
|
17
|
+
api_base_ant = environ.get("TINKER_ANT_API_BASE", 'https://tinker.thinkingmachines.dev/services/tinker-prod/anthropic/api/v1')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Set the mandatory headers
|
|
21
|
+
headers = {
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
"Authorization": f"Bearer {api_key}",
|
|
24
|
+
"User-Agent": "machine-thinking"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_function(func_name):
|
|
29
|
+
# Look up tool by name in globals
|
|
30
|
+
func = globals().get(func_name)
|
|
31
|
+
# Look up in the caller frames
|
|
32
|
+
if not func:
|
|
33
|
+
import inspect
|
|
34
|
+
frame = inspect.currentframe().f_back
|
|
35
|
+
while frame:
|
|
36
|
+
if func_name in frame.f_globals:
|
|
37
|
+
func = frame.f_globals[func_name]
|
|
38
|
+
break
|
|
39
|
+
frame = frame.f_back
|
|
40
|
+
|
|
41
|
+
return func
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_func_args(func_args_def):
|
|
45
|
+
try:
|
|
46
|
+
if isinstance(func_args_def, str):
|
|
47
|
+
func_args = json.loads(func_args_def)
|
|
48
|
+
else:
|
|
49
|
+
func_args = func_args_def
|
|
50
|
+
except Exception as e:
|
|
51
|
+
func_args = {}
|
|
52
|
+
print(f"Error parsing tool arguments: {e}")
|
|
53
|
+
|
|
54
|
+
return func_args
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def call_function(func, func_args):
|
|
58
|
+
if func and callable(func):
|
|
59
|
+
try:
|
|
60
|
+
tool_result = func(**func_args)
|
|
61
|
+
if isinstance(tool_result, (dict, list)):
|
|
62
|
+
result = json.dumps(tool_result)
|
|
63
|
+
else:
|
|
64
|
+
result = str(tool_result)
|
|
65
|
+
except Exception as e:
|
|
66
|
+
result = f"Error executing tool: {str(e)}"
|
|
67
|
+
print(result)
|
|
68
|
+
else:
|
|
69
|
+
result = f"Error: Tool function not callable."
|
|
70
|
+
print(result)
|
|
71
|
+
|
|
72
|
+
return result
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def query(payload, url_suffix, url_prefix=None):
|
|
76
|
+
# Convert data dictionary to JSON and encode it to bytes
|
|
77
|
+
if url_prefix:
|
|
78
|
+
api_base = url_prefix
|
|
79
|
+
else:
|
|
80
|
+
api_base= api_base_oai
|
|
81
|
+
data_bytes = json.dumps(payload).encode('utf-8')
|
|
82
|
+
# Create the Request object
|
|
83
|
+
req = urllib.request.Request(
|
|
84
|
+
f'{api_base}{url_suffix}',
|
|
85
|
+
data=data_bytes,
|
|
86
|
+
headers=headers,
|
|
87
|
+
method="POST")
|
|
88
|
+
# Try to query
|
|
89
|
+
try:
|
|
90
|
+
# Execute the request
|
|
91
|
+
with urllib.request.urlopen(req, timeout=3000) as response:
|
|
92
|
+
response_data = response.read().decode('utf-8')
|
|
93
|
+
output = json.loads(response_data)
|
|
94
|
+
return output
|
|
95
|
+
|
|
96
|
+
except urllib.error.HTTPError as e:
|
|
97
|
+
# Handle HTTP errors (e.g., 401 Unauthorized, 400 Bad Request)
|
|
98
|
+
error_info = e.read().decode('utf-8', errors='ignore')
|
|
99
|
+
print(f"HTTP Error {e.code}: {e.reason}")
|
|
100
|
+
print(f"Error Details: {error_info}")
|
|
101
|
+
return {}
|
|
102
|
+
|
|
103
|
+
except urllib.error.URLError as e:
|
|
104
|
+
# Handle network/connection errors
|
|
105
|
+
print(f"Failed to reach the server: {e.reason}")
|
|
106
|
+
return {}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def decode_output(output):
|
|
110
|
+
# Parse the result
|
|
111
|
+
text = ''; thoughts = ''
|
|
112
|
+
for part in output:
|
|
113
|
+
part_type = part.get('type', None)
|
|
114
|
+
if part_type == 'message':
|
|
115
|
+
text = " ".join([chunk['text'] for chunk in part['content'] if chunk['type'] == 'output_text'])
|
|
116
|
+
elif part_type == 'reasoning':
|
|
117
|
+
thoughts = " ".join([chunk['text'] for chunk in part['summary'] if chunk['type'] == 'summary_text'])
|
|
118
|
+
function_calls = [part for part in output if part['type'] == 'function_call']
|
|
119
|
+
return thoughts, text, function_calls
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def get_weather(location):
|
|
123
|
+
# print(f"Executing weather tool for location: {location}")
|
|
124
|
+
return {"temperature": "72F", "condition": "Sunny"}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def respond(messages=None, instructions=None, tools=None, **kwargs):
|
|
128
|
+
"""
|
|
129
|
+
"""
|
|
130
|
+
# Receive the instruction
|
|
131
|
+
instruction = kwargs.get('system_instruction', instructions)
|
|
132
|
+
|
|
133
|
+
# Define the initial payload
|
|
134
|
+
payload = {
|
|
135
|
+
"model": kwargs.get("model", default_model),
|
|
136
|
+
"instructions": instruction,
|
|
137
|
+
"input": messages,
|
|
138
|
+
"max_output_tokens": kwargs.get("max_tokens", 132000),
|
|
139
|
+
"prompt_cache_retention": "in_memory",
|
|
140
|
+
"include": ["reasoning.encrypted_content"],
|
|
141
|
+
"reasoning": {
|
|
142
|
+
"effort": "high",
|
|
143
|
+
"summary": "detailed"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
# Tools if there are some
|
|
147
|
+
if tools:
|
|
148
|
+
payload['tools'] = tools
|
|
149
|
+
payload['tool_choice'] = 'auto'
|
|
150
|
+
|
|
151
|
+
while True:
|
|
152
|
+
# Query the API
|
|
153
|
+
result = query(payload, '/responses')
|
|
154
|
+
# id of the response
|
|
155
|
+
response_id = result['id']
|
|
156
|
+
thoughts, text, function_calls = decode_output(result.get('output', {}))
|
|
157
|
+
|
|
158
|
+
if function_calls:
|
|
159
|
+
function_outputs_messages = []
|
|
160
|
+
for function_call in function_calls:
|
|
161
|
+
call_id = function_call.get('call_id')
|
|
162
|
+
func_name = function_call.get('name', '')
|
|
163
|
+
func_args_str = function_call.get('arguments', '{}')
|
|
164
|
+
# Look up tool by name in globals and caller frames
|
|
165
|
+
func = get_function(func_name)
|
|
166
|
+
func_args = get_func_args(func_args_str)
|
|
167
|
+
result = call_function(func, func_args)
|
|
168
|
+
|
|
169
|
+
tool_message = {
|
|
170
|
+
"type": "function_call_output",
|
|
171
|
+
"call_id": call_id,
|
|
172
|
+
"output": result
|
|
173
|
+
}
|
|
174
|
+
function_outputs_messages.append(tool_message)
|
|
175
|
+
|
|
176
|
+
# Now that all responses have been gathered
|
|
177
|
+
# we can change the payload and send them back
|
|
178
|
+
payload['include'] = [] # must be removed if response_id
|
|
179
|
+
payload['previous_response_id'] = response_id
|
|
180
|
+
payload['input'] = function_outputs_messages
|
|
181
|
+
else:
|
|
182
|
+
break
|
|
183
|
+
|
|
184
|
+
return thoughts, text
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
if __name__ == "__main__":
|
|
188
|
+
...
|
|
@@ -0,0 +1,188 @@
|
|
|
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
|
+
import json
|
|
9
|
+
import urllib.request
|
|
10
|
+
import urllib.error
|
|
11
|
+
from os import environ
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
api_key = environ.get("TINKER_API_KEY", '')
|
|
15
|
+
default_model = environ.get("TINKER_DEFAULT_MODEL", 'thinkingmachines/Inkling')
|
|
16
|
+
api_base_oai = environ.get("TINKER_OAI_API_BASE", 'https://tinker.thinkingmachines.dev/services/tinker-prod/oai/api/v1')
|
|
17
|
+
api_base_ant = environ.get("TINKER_ANT_API_BASE", 'https://tinker.thinkingmachines.dev/services/tinker-prod/anthropic/api/v1')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Set the mandatory headers
|
|
21
|
+
headers = {
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
"Authorization": f"Bearer {api_key}",
|
|
24
|
+
"User-Agent": "machine-thinking"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_function(func_name):
|
|
29
|
+
# Look up tool by name in globals
|
|
30
|
+
func = globals().get(func_name)
|
|
31
|
+
# Look up in the caller frames
|
|
32
|
+
if not func:
|
|
33
|
+
import inspect
|
|
34
|
+
frame = inspect.currentframe().f_back
|
|
35
|
+
while frame:
|
|
36
|
+
if func_name in frame.f_globals:
|
|
37
|
+
func = frame.f_globals[func_name]
|
|
38
|
+
break
|
|
39
|
+
frame = frame.f_back
|
|
40
|
+
|
|
41
|
+
return func
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_func_args(func_args_def):
|
|
45
|
+
try:
|
|
46
|
+
if isinstance(func_args_def, str):
|
|
47
|
+
func_args = json.loads(func_args_def)
|
|
48
|
+
else:
|
|
49
|
+
func_args = func_args_def
|
|
50
|
+
except Exception as e:
|
|
51
|
+
func_args = {}
|
|
52
|
+
print(f"Error parsing tool arguments: {e}")
|
|
53
|
+
|
|
54
|
+
return func_args
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def call_function(func, func_args):
|
|
58
|
+
if func and callable(func):
|
|
59
|
+
try:
|
|
60
|
+
tool_result = func(**func_args)
|
|
61
|
+
if isinstance(tool_result, (dict, list)):
|
|
62
|
+
result = json.dumps(tool_result)
|
|
63
|
+
else:
|
|
64
|
+
result = str(tool_result)
|
|
65
|
+
except Exception as e:
|
|
66
|
+
result = f"Error executing tool: {str(e)}"
|
|
67
|
+
print(result)
|
|
68
|
+
else:
|
|
69
|
+
result = f"Error: Tool function not callable."
|
|
70
|
+
print(result)
|
|
71
|
+
|
|
72
|
+
return result
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def query(payload, url_suffix, url_prefix=None):
|
|
76
|
+
# Convert data dictionary to JSON and encode it to bytes
|
|
77
|
+
if url_prefix:
|
|
78
|
+
api_base = url_prefix
|
|
79
|
+
else:
|
|
80
|
+
api_base= api_base_oai
|
|
81
|
+
data_bytes = json.dumps(payload).encode('utf-8')
|
|
82
|
+
# Create the Request object
|
|
83
|
+
req = urllib.request.Request(
|
|
84
|
+
f'{api_base}{url_suffix}',
|
|
85
|
+
data=data_bytes,
|
|
86
|
+
headers=headers,
|
|
87
|
+
method="POST")
|
|
88
|
+
# Try to query
|
|
89
|
+
try:
|
|
90
|
+
# Execute the request
|
|
91
|
+
with urllib.request.urlopen(req, timeout=3000) as response:
|
|
92
|
+
response_data = response.read().decode('utf-8')
|
|
93
|
+
output = json.loads(response_data)
|
|
94
|
+
return output
|
|
95
|
+
|
|
96
|
+
except urllib.error.HTTPError as e:
|
|
97
|
+
# Handle HTTP errors (e.g., 401 Unauthorized, 400 Bad Request)
|
|
98
|
+
error_info = e.read().decode('utf-8', errors='ignore')
|
|
99
|
+
print(f"HTTP Error {e.code}: {e.reason}")
|
|
100
|
+
print(f"Error Details: {error_info}")
|
|
101
|
+
return {}
|
|
102
|
+
|
|
103
|
+
except urllib.error.URLError as e:
|
|
104
|
+
# Handle network/connection errors
|
|
105
|
+
print(f"Failed to reach the server: {e.reason}")
|
|
106
|
+
return {}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def decode_output(output):
|
|
110
|
+
# Parse the result
|
|
111
|
+
text = ''; thoughts = ''
|
|
112
|
+
for part in output:
|
|
113
|
+
part_type = part.get('type', None)
|
|
114
|
+
if part_type == 'message':
|
|
115
|
+
text = " ".join([chunk['text'] for chunk in part['content'] if chunk['type'] == 'output_text'])
|
|
116
|
+
elif part_type == 'reasoning':
|
|
117
|
+
thoughts = " ".join([chunk['text'] for chunk in part['summary'] if chunk['type'] == 'summary_text'])
|
|
118
|
+
function_calls = [part for part in output if part['type'] == 'function_call']
|
|
119
|
+
return thoughts, text, function_calls
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def get_weather(location):
|
|
123
|
+
# print(f"Executing weather tool for location: {location}")
|
|
124
|
+
return {"temperature": "72F", "condition": "Sunny"}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def respond(messages=None, instructions=None, tools=None, **kwargs):
|
|
128
|
+
"""
|
|
129
|
+
"""
|
|
130
|
+
# Receive the instruction
|
|
131
|
+
instruction = kwargs.get('system_instruction', instructions)
|
|
132
|
+
|
|
133
|
+
# Define the initial payload
|
|
134
|
+
payload = {
|
|
135
|
+
"model": kwargs.get("model", default_model),
|
|
136
|
+
"instructions": instruction,
|
|
137
|
+
"input": messages,
|
|
138
|
+
"max_output_tokens": kwargs.get("max_tokens", 132000),
|
|
139
|
+
"prompt_cache_retention": "in_memory",
|
|
140
|
+
"include": ["reasoning.encrypted_content"],
|
|
141
|
+
"reasoning": {
|
|
142
|
+
"effort": "high",
|
|
143
|
+
"summary": "detailed"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
# Tools if there are some
|
|
147
|
+
if tools:
|
|
148
|
+
payload['tools'] = tools
|
|
149
|
+
payload['tool_choice'] = 'auto'
|
|
150
|
+
|
|
151
|
+
while True:
|
|
152
|
+
# Query the API
|
|
153
|
+
result = query(payload, '/responses')
|
|
154
|
+
# id of the response
|
|
155
|
+
response_id = result['id']
|
|
156
|
+
thoughts, text, function_calls = decode_output(result.get('output', {}))
|
|
157
|
+
|
|
158
|
+
if function_calls:
|
|
159
|
+
function_outputs_messages = []
|
|
160
|
+
for function_call in function_calls:
|
|
161
|
+
call_id = function_call.get('call_id')
|
|
162
|
+
func_name = function_call.get('name', '')
|
|
163
|
+
func_args_str = function_call.get('arguments', '{}')
|
|
164
|
+
# Look up tool by name in globals and caller frames
|
|
165
|
+
func = get_function(func_name)
|
|
166
|
+
func_args = get_func_args(func_args_str)
|
|
167
|
+
result = call_function(func, func_args)
|
|
168
|
+
|
|
169
|
+
tool_message = {
|
|
170
|
+
"type": "function_call_output",
|
|
171
|
+
"call_id": call_id,
|
|
172
|
+
"output": result
|
|
173
|
+
}
|
|
174
|
+
function_outputs_messages.append(tool_message)
|
|
175
|
+
|
|
176
|
+
# Now that all responses have been gathered
|
|
177
|
+
# we can change the payload and send them back
|
|
178
|
+
payload['include'] = [] # must be removed if response_id
|
|
179
|
+
payload['previous_response_id'] = response_id
|
|
180
|
+
payload['input'] = function_outputs_messages
|
|
181
|
+
else:
|
|
182
|
+
break
|
|
183
|
+
|
|
184
|
+
return thoughts, text
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
if __name__ == "__main__":
|
|
188
|
+
...
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: thinking-machine
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.9
|
|
4
4
|
Summary: A Machine that thinks.
|
|
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/thinking-machine
|
|
@@ -21,10 +21,12 @@ src/thinking_machine/providers/camelids.py
|
|
|
21
21
|
src/thinking_machine/providers/castor_pollux.py
|
|
22
22
|
src/thinking_machine/providers/depsek.py
|
|
23
23
|
src/thinking_machine/providers/electroid.py
|
|
24
|
+
src/thinking_machine/providers/illuminati.py
|
|
24
25
|
src/thinking_machine/providers/light.py
|
|
25
26
|
src/thinking_machine/providers/openai.py
|
|
26
27
|
src/thinking_machine/providers/qrog.py
|
|
27
28
|
src/thinking_machine/providers/strangelove.py
|
|
29
|
+
src/thinking_machine/providers/tink.py
|
|
28
30
|
tests/test_cli.py
|
|
29
31
|
tests/test_e2e.py
|
|
30
32
|
tests/test_llm_soup.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/camelids.py
RENAMED
|
File without changes
|
{thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/castor_pollux.py
RENAMED
|
File without changes
|
|
File without changes
|
{thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/electroid.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine/providers/strangelove.py
RENAMED
|
File without changes
|
|
File without changes
|
{thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine.egg-info/requires.txt
RENAMED
|
File without changes
|
{thinking_machine-0.1.8 → thinking_machine-0.1.9}/src/thinking_machine.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|