machine-thinking 0.0.3__tar.gz → 0.0.5__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 (18) hide show
  1. {machine_thinking-0.0.3 → machine_thinking-0.0.5}/PKG-INFO +2 -3
  2. {machine_thinking-0.0.3 → machine_thinking-0.0.5}/pyproject.toml +2 -9
  3. machine_thinking-0.0.3/src/machine_thinking/main.py → machine_thinking-0.0.5/src/machine_thinking/__init__.py +0 -8
  4. machine_thinking-0.0.5/src/machine_thinking/completion.py +48 -0
  5. machine_thinking-0.0.5/src/machine_thinking/messages.py +81 -0
  6. {machine_thinking-0.0.3 → machine_thinking-0.0.5}/src/machine_thinking/utils.py +7 -2
  7. {machine_thinking-0.0.3 → machine_thinking-0.0.5}/src/machine_thinking.egg-info/PKG-INFO +2 -3
  8. {machine_thinking-0.0.3 → machine_thinking-0.0.5}/src/machine_thinking.egg-info/SOURCES.txt +3 -4
  9. {machine_thinking-0.0.3 → machine_thinking-0.0.5}/src/machine_thinking.egg-info/top_level.txt +1 -0
  10. machine_thinking-0.0.3/src/machine_thinking/cli.py +0 -12
  11. machine_thinking-0.0.3/src/machine_thinking.egg-info/entry_points.txt +0 -2
  12. machine_thinking-0.0.3/src/machine_thinking.egg-info/requires.txt +0 -1
  13. {machine_thinking-0.0.3 → machine_thinking-0.0.5}/LICENSE +0 -0
  14. {machine_thinking-0.0.3 → machine_thinking-0.0.5}/README.md +0 -0
  15. {machine_thinking-0.0.3 → machine_thinking-0.0.5}/setup.cfg +0 -0
  16. {machine_thinking-0.0.3/src/machine_thinking → machine_thinking-0.0.5/src}/__init__.py +0 -0
  17. {machine_thinking-0.0.3 → machine_thinking-0.0.5}/src/machine_thinking/chat.py +0 -0
  18. {machine_thinking-0.0.3 → machine_thinking-0.0.5}/src/machine_thinking.egg-info/dependency_links.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: machine-thinking
3
- Version: 0.0.3
4
- Summary: Package description
3
+ Version: 0.0.5
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
7
7
  Project-URL: Bug Tracker, https://github.com/machina-ratiocinatrix/machine-thinking/issues
@@ -12,7 +12,6 @@ Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.10
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
- Requires-Dist: pyyaml==6.0.3
16
15
  Dynamic: license-file
17
16
 
18
17
  # Machine thinking
@@ -3,12 +3,12 @@ requires = ["setuptools>=67.0"]
3
3
  build-backend = "setuptools.build_meta"
4
4
  [project]
5
5
  name = "machine-thinking"
6
- version = "0.0.3"
6
+ version = "0.0.5"
7
7
  authors = [
8
8
  {name="Machina Ratiocinatrix", email="machina.ratio@gmail.com"},
9
9
  {name="Alexander Fedotov", email="alex.fedotov@aol.com"}
10
10
  ]
11
- description = "Package description"
11
+ description = "Calling the API of 'Thinking-Machines Lab' models without dependencies."
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.10"
14
14
  classifiers=[
@@ -19,13 +19,6 @@ classifiers=[
19
19
 
20
20
  keywords = ["machine-thinking"]
21
21
 
22
- dependencies = [
23
- "pyyaml == 6.0.3"
24
- ]
25
-
26
- [project.scripts]
27
- machine-thinking = "machine_thinking.cli:run"
28
-
29
22
  [project.urls]
30
23
  "Homepage" = "https://github.com/machina-ratiocinatrix/machine-thinking"
31
24
  "Bug Tracker" = "https://github.com/machina-ratiocinatrix/machine-thinking/issues"
@@ -5,11 +5,3 @@
5
5
  This source code is licensed under the license found in the
6
6
  LICENSE file in the root directory of this source tree.
7
7
  """
8
-
9
-
10
- def main(): # arg=None):
11
- print(' main.')
12
-
13
-
14
- if __name__ == '__main__':
15
- main()
@@ -0,0 +1,48 @@
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 (default_model,
9
+ query)
10
+
11
+
12
+ def complete(text, **kwargs):
13
+ """A completions endpoint call
14
+ """
15
+ responses = []
16
+ payload = {
17
+ "model": kwargs.get("model", default_model),
18
+ "prompt": kwargs.get("prompt", text),
19
+ "response_format": kwargs.get('response_format', {'type': 'text'}),
20
+ "reasoning_effort": kwargs.get("reasoning_effort", "high"),
21
+ "reasoning_history":kwargs.get("reasoning_history", "interleaved"),
22
+ "thinking": kwargs.get("thinking", None),
23
+ "max_tokens": kwargs.get("max_tokens", 5),
24
+ "n": kwargs.get("n", 1),
25
+ "stop": kwargs.get("stop_sequences", ["stop"]),
26
+ # "seed": kwargs.get("seed", None),
27
+ "frequency_penalty":kwargs.get("frequency_penalty", 0),
28
+ "presence_penalty": kwargs.get("presence_penalty", 0),
29
+ # "logit_bias": kwargs.get("logit_bias", None),
30
+ "logprobs": kwargs.get("logprobs", None),
31
+ # "top_logprobs": kwargs.get("top_logprobs", None),
32
+ "temperature": kwargs.get("temperature", 1),
33
+ "top_p": kwargs.get("top_p", 1),
34
+ 'top_k': kwargs.get('top_k', 50),
35
+ 'stream': False,
36
+ # "user": kwargs.get("user", None)
37
+ }
38
+
39
+ responses = query(payload, '/completions')
40
+ response = responses['choices'][0]
41
+ text = response['text']
42
+ thoughts = ''
43
+
44
+ return thoughts, text
45
+
46
+
47
+ if __name__ == '__main__':
48
+ ...
@@ -0,0 +1,81 @@
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
+ ...
@@ -13,7 +13,8 @@ from os import environ
13
13
 
14
14
  api_key = environ.get("TINKER_API_KEY", '')
15
15
  default_model = environ.get("TINKER_DEFAULT_MODEL", 'thinkingmachines/Inkling')
16
- api_base = environ.get("TINKER_API_BASE", 'https://tinker.thinkingmachines.dev/services/tinker-prod/oai/api/v1')
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')
17
18
 
18
19
 
19
20
  # Set the mandatory headers
@@ -72,8 +73,12 @@ def call_function(func, func_args):
72
73
  return result
73
74
 
74
75
 
75
- def query(payload, url_suffix):
76
+ def query(payload, url_suffix, url_prefix=None):
76
77
  # Convert data dictionary to JSON and encode it to bytes
78
+ if url_prefix:
79
+ api_base = url_prefix
80
+ else:
81
+ api_base= api_base_oai
77
82
  data_bytes = json.dumps(payload).encode('utf-8')
78
83
  # Create the Request object
79
84
  req = urllib.request.Request(
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: machine-thinking
3
- Version: 0.0.3
4
- Summary: Package description
3
+ Version: 0.0.5
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
7
7
  Project-URL: Bug Tracker, https://github.com/machina-ratiocinatrix/machine-thinking/issues
@@ -12,7 +12,6 @@ Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.10
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
- Requires-Dist: pyyaml==6.0.3
16
15
  Dynamic: license-file
17
16
 
18
17
  # Machine thinking
@@ -1,14 +1,13 @@
1
1
  LICENSE
2
2
  README.md
3
3
  pyproject.toml
4
+ src/__init__.py
4
5
  src/machine_thinking/__init__.py
5
6
  src/machine_thinking/chat.py
6
- src/machine_thinking/cli.py
7
- src/machine_thinking/main.py
7
+ src/machine_thinking/completion.py
8
+ src/machine_thinking/messages.py
8
9
  src/machine_thinking/utils.py
9
10
  src/machine_thinking.egg-info/PKG-INFO
10
11
  src/machine_thinking.egg-info/SOURCES.txt
11
12
  src/machine_thinking.egg-info/dependency_links.txt
12
- src/machine_thinking.egg-info/entry_points.txt
13
- src/machine_thinking.egg-info/requires.txt
14
13
  src/machine_thinking.egg-info/top_level.txt
@@ -1,12 +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 .main import main
9
-
10
-
11
- def run(): #arg): # (count, arg): if with option.
12
- main() #arg)
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- machine-thinking = machine_thinking.cli:run
@@ -1 +0,0 @@
1
- pyyaml==6.0.3