mara-client 0.15.3__py3-none-any.whl → 0.15.4__py3-none-any.whl

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.
mara_client/clients.py CHANGED
@@ -1,5 +1,5 @@
1
1
  import requests
2
- from typing import List, Optional
2
+ from typing import List, Optional, Union
3
3
  from .models import ChatFile, ChatResult, DataTable
4
4
  from . import utils
5
5
 
@@ -122,12 +122,12 @@ class FileManager:
122
122
 
123
123
  def upload(self, filepath: str) -> ChatFile:
124
124
  path = f'chats/{self.chat_id}/files'
125
- with open(filepath, 'rb') as file:
126
- resp = self.client._request(
127
- method='POST',
128
- path=path,
129
- files={'file': open(filepath, 'rb')}
130
- )
125
+ resp = self.client._request(
126
+ method='POST',
127
+ path=path,
128
+ json=None,
129
+ files={'file': open(filepath, 'rb')}
130
+ )
131
131
  return ChatFile(**resp.json())
132
132
 
133
133
  def list(self) -> List[dict]:
@@ -166,16 +166,20 @@ class Chat:
166
166
  """Delete the chat and all of its data and files."""
167
167
  self.client._request(method='DELETE', path=f'chats/{self.chat_id}')
168
168
 
169
- def prompt(self, content: str, files: List[str] = None) -> ChatResult:
169
+ def prompt(self, content: str, files: List[Union[str, ChatFile]] = None) -> ChatResult:
170
170
  """Prompt the chat with a message and optional files. Return the result."""
171
171
  files = files or []
172
172
 
173
- files_payload = []
173
+ file_ids = []
174
174
  for fi in files:
175
- files_payload.append(('file', (fi, open(fi, 'rb'))))
176
- data = {'content': content}
175
+ if isinstance(fi, str):
176
+ fi = self.files.upload(fi)
177
+ elif not isinstance(fi, ChatFile):
178
+ raise ValueError('Files must be either string file paths or ChatFile objects')
179
+ file_ids.append(fi.id)
180
+ data = {'content': content, 'files': file_ids}
177
181
  path = f'chats/{self.chat_id}'
178
- r = self.client._request(path=path, json=data, files=files_payload)
182
+ r = self.client._request(path=path, json=data)
179
183
  return ChatResult.from_response(r.text)
180
184
 
181
185
  def get_context(self) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mara_client
3
- Version: 0.15.3
3
+ Version: 0.15.4
4
4
  Summary: A client for the MARA conversational agent for cheminformatics.
5
5
  Home-page: https://nanome.ai/mara
6
6
  Author: Sam Hessenauer, Alex McNerney, Mike Rosengrant
@@ -37,11 +37,11 @@ To use the MARA client, you need to have an API key. You can create one at https
37
37
  MARA chats are created using the `new_chat` method, or retrieved with the `get_chat` method of the client. You can then interact with the chat using the `prompt` method. The `prompt` method returns a `ChatResult` object, which contains the response from MARA, intermediate messages such as tool runs, and any files that were generated during the conversation. You can download these files using the `download_file` method of the chat. Chat will be visible as conversations in the MARA web interface, and can be deleted using the `delete` method.
38
38
 
39
39
  ```python
40
- import mara_client
40
+ from mara_client import MARAClient
41
41
 
42
42
  API_KEY = "..."
43
43
  URL = "https://mara.example.com" # optional
44
- client = mara.Client(API_KEY, URL)
44
+ client = MARAClient(API_KEY, URL)
45
45
 
46
46
  chat = client.new_chat()
47
47
  # or, chat = client.get_chat("chat_id")
@@ -72,6 +72,28 @@ chat.delete()
72
72
  # remove chat from history, delete associated files and data
73
73
  ```
74
74
 
75
+ ### Files
76
+
77
+ The chat object contains a `files` attribute for working with files.
78
+
79
+ ```python
80
+ # Upload a file as part of a prompt
81
+ file_path = './example.sdf'
82
+ result = chat.prompt('Convert this to SMILES', files=[file_path])
83
+
84
+ # List all files
85
+ file_list = chat.files.list()
86
+
87
+ # Download a file
88
+ file_name = file_list[0].name
89
+ chat.files.download(file_name, 'output.sdf')
90
+
91
+ # Upload a file directly
92
+ file_path = './example.sdf'
93
+ file = chat.files.upload(file_path)
94
+ print(file.id)
95
+ ```
96
+
75
97
  ### Data Tables
76
98
 
77
99
  The chat object contains a `datatables` attribute for working with DataTables.
@@ -0,0 +1,8 @@
1
+ mara_client/__init__.py,sha256=Bj_FA5MS3KtXjoE1f_AqPisZI01daWj3eru14UCK4tw,45
2
+ mara_client/clients.py,sha256=9V_hRnD34wHSjE1rskGtCJG7ysubKMa_Qm9bijgxPQA,7847
3
+ mara_client/models.py,sha256=FdHv87TohZSfAXjh9UxAJQX7x0LFtZfoNao6yeEesCs,2719
4
+ mara_client/utils.py,sha256=_pK30UynDGE9MaEbSY_INxcjIyxhlXBI8eMzPF_ryg0,755
5
+ mara_client-0.15.4.dist-info/METADATA,sha256=G-wdcXi0hagMOVJT-Y23hovHqOU28qnnzYBCKSs0T9o,3688
6
+ mara_client-0.15.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
+ mara_client-0.15.4.dist-info/top_level.txt,sha256=kBfHb_yKywadvXTNAMeOIMgWpS7lqON93jMRUG6Wgqc,12
8
+ mara_client-0.15.4.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- mara_client/__init__.py,sha256=Bj_FA5MS3KtXjoE1f_AqPisZI01daWj3eru14UCK4tw,45
2
- mara_client/clients.py,sha256=GawEFJ5UQhOfuus8D-MhE6a_w5MWbzDT2eC_NLXxYHs,7679
3
- mara_client/models.py,sha256=FdHv87TohZSfAXjh9UxAJQX7x0LFtZfoNao6yeEesCs,2719
4
- mara_client/utils.py,sha256=_pK30UynDGE9MaEbSY_INxcjIyxhlXBI8eMzPF_ryg0,755
5
- mara_client-0.15.3.dist-info/METADATA,sha256=EKBZh0fomM5AOaiCHrzbLMgGXcl5YzBPE-JFOnrbDZY,3200
6
- mara_client-0.15.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
- mara_client-0.15.3.dist-info/top_level.txt,sha256=kBfHb_yKywadvXTNAMeOIMgWpS7lqON93jMRUG6Wgqc,12
8
- mara_client-0.15.3.dist-info/RECORD,,