machine-thinking 0.0.2__tar.gz → 0.0.4__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 (21) hide show
  1. machine_thinking-0.0.4/PKG-INFO +68 -0
  2. machine_thinking-0.0.4/README.md +52 -0
  3. {machine_thinking-0.0.2 → machine_thinking-0.0.4}/pyproject.toml +2 -9
  4. machine_thinking-0.0.2/src/machine_thinking/main.py → machine_thinking-0.0.4/src/machine_thinking/__init__.py +0 -8
  5. {machine_thinking-0.0.2 → machine_thinking-0.0.4}/src/machine_thinking/chat.py +1 -9
  6. machine_thinking-0.0.4/src/machine_thinking/completion.py +48 -0
  7. machine_thinking-0.0.4/src/machine_thinking/messages.py +80 -0
  8. machine_thinking-0.0.4/src/machine_thinking.egg-info/PKG-INFO +68 -0
  9. {machine_thinking-0.0.2 → machine_thinking-0.0.4}/src/machine_thinking.egg-info/SOURCES.txt +3 -4
  10. {machine_thinking-0.0.2 → machine_thinking-0.0.4}/src/machine_thinking.egg-info/top_level.txt +1 -0
  11. machine_thinking-0.0.2/PKG-INFO +0 -26
  12. machine_thinking-0.0.2/README.md +0 -9
  13. machine_thinking-0.0.2/src/machine_thinking/cli.py +0 -12
  14. machine_thinking-0.0.2/src/machine_thinking.egg-info/PKG-INFO +0 -26
  15. machine_thinking-0.0.2/src/machine_thinking.egg-info/entry_points.txt +0 -2
  16. machine_thinking-0.0.2/src/machine_thinking.egg-info/requires.txt +0 -1
  17. {machine_thinking-0.0.2 → machine_thinking-0.0.4}/LICENSE +0 -0
  18. {machine_thinking-0.0.2 → machine_thinking-0.0.4}/setup.cfg +0 -0
  19. {machine_thinking-0.0.2/src/machine_thinking → machine_thinking-0.0.4/src}/__init__.py +0 -0
  20. {machine_thinking-0.0.2 → machine_thinking-0.0.4}/src/machine_thinking/utils.py +0 -0
  21. {machine_thinking-0.0.2 → machine_thinking-0.0.4}/src/machine_thinking.egg-info/dependency_links.txt +0 -0
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: machine-thinking
3
+ Version: 0.0.4
4
+ Summary: Calling the API of 'Thinking-Machines Lab' models without dependencies.
5
+ Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>, Alexander Fedotov <alex.fedotov@aol.com>
6
+ Project-URL: Homepage, https://github.com/machina-ratiocinatrix/machine-thinking
7
+ Project-URL: Bug Tracker, https://github.com/machina-ratiocinatrix/machine-thinking/issues
8
+ Keywords: machine-thinking
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Dynamic: license-file
16
+
17
+ # Machine thinking
18
+ Tinker API calls to Inkling model without dependencies.
19
+ <pre>
20
+ pip install machine-thinking
21
+ </pre>
22
+ Then:
23
+ ```Python
24
+ # Python
25
+ from yaml import safe_load as yl
26
+ from machine_thinking.chat import chat_complete as cc
27
+
28
+ kwargs = """ # this is a string in YAML format
29
+ max_tokens: 32000
30
+ stop_sequences:
31
+ - STOP
32
+ - "\nTitle"
33
+ temperature: 1.0
34
+ top_k: 10
35
+ top_p: 0.5
36
+ reasoning_effort: high
37
+ """
38
+
39
+ instruction = 'You are a helpful assistant. Do not use markdown or lists in your responses.'
40
+
41
+ weather_tool = """ # YAML definition of a function (old format)
42
+ type: function
43
+ function:
44
+ name: get_weather
45
+ description: Determine weather in a location
46
+ parameters:
47
+ type: object
48
+ properties:
49
+ location:
50
+ type: string
51
+ description: The city and state, e.g. San Francisco, CA
52
+ additionalProperties: false
53
+ required:
54
+ - location
55
+ """
56
+
57
+ tools = [yl(weather_tool)]
58
+
59
+ msgs = [{'role': 'user', 'content': 'What is the weather in Chicago, IL and Paris, France?'}]
60
+
61
+ thoughts, text = cc(
62
+ messages=msgs,
63
+ instructions=instruction,
64
+ tools=tools,
65
+ **yl(kwargs)
66
+ )
67
+ ```
68
+
@@ -0,0 +1,52 @@
1
+ # Machine thinking
2
+ Tinker API calls to Inkling model without dependencies.
3
+ <pre>
4
+ pip install machine-thinking
5
+ </pre>
6
+ Then:
7
+ ```Python
8
+ # Python
9
+ from yaml import safe_load as yl
10
+ from machine_thinking.chat import chat_complete as cc
11
+
12
+ kwargs = """ # this is a string in YAML format
13
+ max_tokens: 32000
14
+ stop_sequences:
15
+ - STOP
16
+ - "\nTitle"
17
+ temperature: 1.0
18
+ top_k: 10
19
+ top_p: 0.5
20
+ reasoning_effort: high
21
+ """
22
+
23
+ instruction = 'You are a helpful assistant. Do not use markdown or lists in your responses.'
24
+
25
+ weather_tool = """ # YAML definition of a function (old format)
26
+ type: function
27
+ function:
28
+ name: get_weather
29
+ description: Determine weather in a location
30
+ parameters:
31
+ type: object
32
+ properties:
33
+ location:
34
+ type: string
35
+ description: The city and state, e.g. San Francisco, CA
36
+ additionalProperties: false
37
+ required:
38
+ - location
39
+ """
40
+
41
+ tools = [yl(weather_tool)]
42
+
43
+ msgs = [{'role': 'user', 'content': 'What is the weather in Chicago, IL and Paris, France?'}]
44
+
45
+ thoughts, text = cc(
46
+ messages=msgs,
47
+ instructions=instruction,
48
+ tools=tools,
49
+ **yl(kwargs)
50
+ )
51
+ ```
52
+
@@ -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.2"
6
+ version = "0.0.4"
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()
@@ -13,19 +13,11 @@ from .utils import (query,
13
13
 
14
14
 
15
15
  def get_weather(location):
16
- # print(f"Executing weather tool for location: {location}")
17
16
  return {"temperature": "72F", "condition": "Sunny"}
18
17
 
19
18
 
20
19
  def chat_complete(messages=None, instructions=None, tools=None, **kwargs):
21
- """A continuation of text with a given context and instruction.
22
- kwargs:
23
- temperature = 0 to 1.0
24
- top_p = 0.0 to 1.0
25
- top_k = The maximum number of tokens to consider when sampling.
26
- n = 1 is mandatory for this method continuationS have n > 1
27
- max_tokens = number of tokens
28
- stop = ['stop'] array of up to 4 sequences
20
+ """
29
21
  """
30
22
  instruction = kwargs.get('system_instruction', instructions)
31
23
  first_message = [dict(role='system', content=instruction)] if instruction else []
@@ -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,80 @@
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
+
14
+
15
+ def get_weather(location):
16
+ # print(f"Executing weather tool for location: {location}")
17
+ return {"temperature": "72F", "condition": "Sunny"}
18
+
19
+
20
+ def message(messages=None, instructions=None, tools=None, **kwargs):
21
+ """A continuation of text with a given context and instruction.
22
+ """
23
+ messages = kwargs.get('messages', messages)
24
+
25
+ payload = {
26
+ 'model': kwargs.get('model', default_model),
27
+ 'system': kwargs.get('system', instructions),
28
+ 'messages': kwargs.get('messages', messages),
29
+ 'output_config': kwargs.get('output_config',{'effort': 'high'}),
30
+ 'thinking': kwargs.get('thinking', {
31
+ 'type': 'enabled',
32
+ 'budget_tokens': 10000,
33
+ }),
34
+ 'tool_choice': kwargs.get('tool_choice', {'type': 'auto', 'disable_parallel_tool_use': False}),
35
+ 'max_tokens': kwargs.get('max_tokens', 4096),
36
+ 'prompt_truncate_len': kwargs.get('prompt_truncate_len', 100000),
37
+ 'n': kwargs.get('n', 1),
38
+ 'top_p': kwargs.get('top_p', 0.9),
39
+ 'top_k': kwargs.get('top_k', 10),
40
+ 'stream': False
41
+ }
42
+ if tools:
43
+ payload['tools'] = tools
44
+ payload['parallel_tool_calls'] = True
45
+ payload['tool_choice'] = 'auto'
46
+
47
+ while True:
48
+ result = query(payload, '/messages')
49
+ completion_message = result['choices'][0]['message']
50
+ messages.append(completion_message)
51
+ thoughts = completion_message.get('reasoning_content', '')
52
+ text = completion_message.get('content', '')
53
+ function_calls = completion_message.get('tool_calls', [])
54
+
55
+ if function_calls:
56
+ # Call all requested functions and create response messages.
57
+ for function_call in function_calls:
58
+ call_id = function_call.get('id')
59
+ func_def = function_call.get('function')
60
+ func_name = func_def.get('name', '')
61
+
62
+ # Look up tool by name in globals and caller frames
63
+ func = get_function(func_name)
64
+ func_args = get_func_args(func_def)
65
+ result = call_function(func, func_args)
66
+
67
+ tool_message = {
68
+ "role": "tool",
69
+ "tool_call_id": call_id,
70
+ "content": result
71
+ }
72
+ messages.append(tool_message)
73
+ else:
74
+ break
75
+
76
+ return thoughts, text
77
+
78
+
79
+ if __name__ == '__main__':
80
+ ...
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: machine-thinking
3
+ Version: 0.0.4
4
+ Summary: Calling the API of 'Thinking-Machines Lab' models without dependencies.
5
+ Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>, Alexander Fedotov <alex.fedotov@aol.com>
6
+ Project-URL: Homepage, https://github.com/machina-ratiocinatrix/machine-thinking
7
+ Project-URL: Bug Tracker, https://github.com/machina-ratiocinatrix/machine-thinking/issues
8
+ Keywords: machine-thinking
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Dynamic: license-file
16
+
17
+ # Machine thinking
18
+ Tinker API calls to Inkling model without dependencies.
19
+ <pre>
20
+ pip install machine-thinking
21
+ </pre>
22
+ Then:
23
+ ```Python
24
+ # Python
25
+ from yaml import safe_load as yl
26
+ from machine_thinking.chat import chat_complete as cc
27
+
28
+ kwargs = """ # this is a string in YAML format
29
+ max_tokens: 32000
30
+ stop_sequences:
31
+ - STOP
32
+ - "\nTitle"
33
+ temperature: 1.0
34
+ top_k: 10
35
+ top_p: 0.5
36
+ reasoning_effort: high
37
+ """
38
+
39
+ instruction = 'You are a helpful assistant. Do not use markdown or lists in your responses.'
40
+
41
+ weather_tool = """ # YAML definition of a function (old format)
42
+ type: function
43
+ function:
44
+ name: get_weather
45
+ description: Determine weather in a location
46
+ parameters:
47
+ type: object
48
+ properties:
49
+ location:
50
+ type: string
51
+ description: The city and state, e.g. San Francisco, CA
52
+ additionalProperties: false
53
+ required:
54
+ - location
55
+ """
56
+
57
+ tools = [yl(weather_tool)]
58
+
59
+ msgs = [{'role': 'user', 'content': 'What is the weather in Chicago, IL and Paris, France?'}]
60
+
61
+ thoughts, text = cc(
62
+ messages=msgs,
63
+ instructions=instruction,
64
+ tools=tools,
65
+ **yl(kwargs)
66
+ )
67
+ ```
68
+
@@ -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,26 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: machine-thinking
3
- Version: 0.0.2
4
- Summary: Package description
5
- Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>, Alexander Fedotov <alex.fedotov@aol.com>
6
- Project-URL: Homepage, https://github.com/machina-ratiocinatrix/machine-thinking
7
- Project-URL: Bug Tracker, https://github.com/machina-ratiocinatrix/machine-thinking/issues
8
- Keywords: machine-thinking
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.10
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
- Requires-Dist: pyyaml==6.0.3
16
- Dynamic: license-file
17
-
18
- # Machine thinking
19
- <pre>
20
- pip install machine-thinking
21
- </pre>
22
- Then:
23
- ```Python
24
- # Python
25
- import machine_thinking
26
- ```
@@ -1,9 +0,0 @@
1
- # Machine thinking
2
- <pre>
3
- pip install machine-thinking
4
- </pre>
5
- Then:
6
- ```Python
7
- # Python
8
- import machine_thinking
9
- ```
@@ -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,26 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: machine-thinking
3
- Version: 0.0.2
4
- Summary: Package description
5
- Author-email: Machina Ratiocinatrix <machina.ratio@gmail.com>, Alexander Fedotov <alex.fedotov@aol.com>
6
- Project-URL: Homepage, https://github.com/machina-ratiocinatrix/machine-thinking
7
- Project-URL: Bug Tracker, https://github.com/machina-ratiocinatrix/machine-thinking/issues
8
- Keywords: machine-thinking
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.10
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
- Requires-Dist: pyyaml==6.0.3
16
- Dynamic: license-file
17
-
18
- # Machine thinking
19
- <pre>
20
- pip install machine-thinking
21
- </pre>
22
- Then:
23
- ```Python
24
- # Python
25
- import machine_thinking
26
- ```
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- machine-thinking = machine_thinking.cli:run
@@ -1 +0,0 @@
1
- pyyaml==6.0.3