Skip to content

Commit 47c8966

Browse files
authored
Plugin instance invocation + Block and Tag (#30)
Combined Dave/Ted work for bringing Python client up to current. * Changes to accommodate plugin instances - all plugin invocations happen via a Plugin Instance * Many changes to client inputs and outputs based on block and tag refactor * Temporary separation of File 'verbs' into extension package; this likely needs generalized / revisited later Generalize the data/extensions pattern; probably rename the packages #29 * Adjustments to test expectations based on block / tag refactor
1 parent 2e2a17b commit 47c8966

95 files changed

Lines changed: 2298 additions & 2369 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ __pycache__/*
2020
.pydevproject
2121
.settings
2222
.idea
23-
tags
2423

2524
# Package files
2625
*.egg

src/steamship/base/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any, TypeVar, Union
44

55
import requests # type: ignore
6+
67
from steamship.base.configuration import Configuration
78
from steamship.base.error import SteamshipError
89
from steamship.base.mime_types import MimeTypes
@@ -206,7 +207,7 @@ def call(
206207
appCall: bool = False,
207208
appOwner: str = None,
208209
appId: str = None,
209-
appInstanceId: str = None
210+
appInstanceId: str = None,
210211
) -> Union[Any, Response[T]]:
211212
"""Post to the Steamship API.
212213

src/steamship/base/mime_types.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ class MimeTypes:
1616
PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
1717
RTF = "application/rtf"
1818
BINARY = "application/octet-stream"
19+
20+
21+
TEXT_MIME_TYPES = [
22+
MimeTypes.TXT,
23+
MimeTypes.MKD,
24+
MimeTypes.HTML,
25+
MimeTypes.DOCX,
26+
MimeTypes.PPTX
27+
]

src/steamship/base/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def update(self, response: "Response[T]"):
2424
def wait(self, max_timeout_s: float = 60, retry_delay_s: float = 1):
2525
"""Polls and blocks until the task has succeeded or failed (or timeout reached)."""
2626
start = time.time()
27-
if self.task is None:
27+
if self.task is None or self.task.state == TaskStatus.failed:
2828
return
2929

3030
self.check()

src/steamship/client/client.py

Lines changed: 30 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import logging
22
from typing import List
33

4+
from steamship import Block
45
from steamship.base import Client, Response
6+
from steamship.client.operations.embedder import EmbedRequest
7+
from steamship.client.operations.tagger import TagRequest
58
from steamship.client.tasks import Tasks
6-
from steamship.data import Block, Classifier, Corpus, File
7-
from steamship.data.embedding import EmbedAndSearchRequest, EmbedAndSearchResponse, EmbedRequest, EmbedResponse
8-
from steamship.data.embedding_index import EmbeddingIndex
9-
from steamship.data.parser import TokenMatcher, PhraseMatcher, DependencyMatcher, ParseRequest, ParseResponse
9+
from steamship.data import File
10+
from steamship.data.embeddings import EmbedAndSearchRequest, EmbedAndSearchResponse, EmbeddingIndex
1011
from steamship.data.space import Space
11-
from steamship.data.tagging import TagRequest, TagResponse
1212

1313
__copyright__ = "Steamship"
1414
__license__ = "MIT"
1515

16+
from steamship.extension.file import TagResponse
17+
from steamship.plugin.outputs.embedded_items_plugin_output import EmbeddedItemsPluginOutput
18+
1619
_logger = logging.getLogger(__name__)
1720

1821

22+
1923
class Steamship(Client):
2024
"""Steamship Python Client."""
2125

@@ -56,40 +60,11 @@ def __init__(
5660
"""
5761
self.tasks = Tasks(self)
5862

59-
def create_corpus(
60-
self,
61-
name: str,
62-
handle: str = None,
63-
description: str = None,
64-
externalId: str = None,
65-
externalType: str = None,
66-
metadata: any = None,
67-
isPublic: bool = False,
68-
upsert: bool = False,
69-
spaceId: bool = False,
70-
spaceHandle: bool = False,
71-
space: Space = None
72-
) -> Corpus:
73-
return Corpus.create(
74-
client=self,
75-
name=name,
76-
handle=handle,
77-
description=description,
78-
isPublic=isPublic,
79-
upsert=upsert,
80-
externalId=externalId,
81-
externalType=externalType,
82-
metadata=metadata,
83-
spaceId=spaceId,
84-
spaceHandle=spaceHandle,
85-
space=space
86-
)
87-
8863
def create_index(
8964
self,
9065
handle: str = None,
9166
name: str = None,
92-
plugin: str = None,
67+
pluginInstance: str = None,
9368
upsert: bool = True,
9469
externalId: str = None,
9570
externalType: str = None,
@@ -102,7 +77,7 @@ def create_index(
10277
client=self,
10378
handle=handle,
10479
name=name,
105-
plugin=plugin,
80+
pluginInstance=pluginInstance,
10681
upsert=upsert,
10782
externalId=externalId,
10883
externalType=externalType,
@@ -112,29 +87,6 @@ def create_index(
11287
space=space
11388
)
11489

115-
def create_classifier(
116-
self,
117-
name: str,
118-
plugin: str,
119-
upsert: bool = True,
120-
save: bool = None,
121-
labels: List[str] = None,
122-
spaceId: str = None,
123-
spaceHandle: str = None,
124-
space: Space = None
125-
) -> Classifier:
126-
return Classifier.create(
127-
client=self,
128-
plugin=plugin,
129-
name=name,
130-
upsert=upsert,
131-
save=save,
132-
labels=labels,
133-
spaceId=spaceId,
134-
spaceHandle=spaceHandle,
135-
space=space
136-
)
137-
13890
def upload(
13991
self,
14092
filename: str = None,
@@ -146,7 +98,7 @@ def upload(
14698
spaceHandle: str = None,
14799
space: Space = None
148100
) -> File:
149-
return File.upload(
101+
return File.create(
150102
self,
151103
filename=filename,
152104
name=name,
@@ -179,19 +131,19 @@ def scrape(
179131
def embed(
180132
self,
181133
docs: List[str],
182-
plugin: str,
134+
pluginInstance: str,
183135
spaceId: str = None,
184136
spaceHandle: str = None,
185137
space: Space = None
186-
) -> Response[EmbedResponse]:
138+
) -> Response[EmbeddedItemsPluginOutput]:
187139
req = EmbedRequest(
188140
docs=docs,
189-
plugin=plugin
141+
pluginInstance=pluginInstance
190142
)
191143
return self.post(
192144
'embedding/create',
193145
req,
194-
expect=EmbedResponse,
146+
expect=EmbeddedItemsPluginOutput,
195147
spaceId=spaceId,
196148
spaceHandle=spaceHandle,
197149
space=space
@@ -201,7 +153,7 @@ def embed_and_search(
201153
self,
202154
query: str,
203155
docs: List[str],
204-
plugin: str,
156+
pluginInstance: str,
205157
k: int = 1,
206158
spaceId: str = None,
207159
spaceHandle: str = None,
@@ -210,7 +162,7 @@ def embed_and_search(
210162
req = EmbedAndSearchRequest(
211163
query=query,
212164
docs=docs,
213-
plugin=plugin,
165+
pluginInstance=pluginInstance,
214166
k=k
215167
)
216168
return self.post(
@@ -222,61 +174,28 @@ def embed_and_search(
222174
space=space
223175
)
224176

225-
def parse(
226-
self,
227-
docs: List[str],
228-
plugin: str = None,
229-
tokenMatchers: List[TokenMatcher] = None,
230-
phraseMatchers: List[PhraseMatcher] = None,
231-
dependencyMatchers: List[DependencyMatcher] = None,
232-
includeTokens: bool = True,
233-
includeParseData: bool = True,
234-
includeEntities: bool = False,
235-
metadata: any = None,
236-
spaceId: str = None,
237-
spaceHandle: str = None,
238-
space: Space = None
239-
) -> Response[ParseResponse]:
240-
req = ParseRequest(
241-
type="inline",
242-
docs=docs,
243-
plugin=plugin,
244-
tokenMatchers=tokenMatchers,
245-
phraseMatchers=phraseMatchers,
246-
dependencyMatchers=dependencyMatchers,
247-
includeTokens=includeTokens,
248-
includeParseData=includeParseData,
249-
includeEntities=includeEntities,
250-
metadata=metadata
251-
)
252-
return self.post(
253-
'plugin/parse',
254-
req,
255-
expect=ParseResponse,
256-
spaceId=spaceId,
257-
spaceHandle=spaceHandle,
258-
space=space
259-
)
260-
261177
def tag(
262178
self,
263-
blocks: List[Block],
264-
plugin: str = None,
265-
metadata: any = None,
179+
doc: str,
180+
pluginInstance: str = None,
266181
spaceId: str = None,
267182
spaceHandle: str = None,
268183
space: Space = None
269-
) -> Response[ParseResponse]:
184+
) -> Response[TagResponse]:
270185
req = TagRequest(
271-
blocks=blocks,
272-
plugin=plugin,
273-
metadata=metadata
186+
type="inline",
187+
file=File.CreateRequest(
188+
blocks=[Block.CreateRequest(
189+
text=doc
190+
)]
191+
),
192+
pluginInstance=pluginInstance,
274193
)
275194
return self.post(
276-
'tagger/tag',
195+
'plugin/instance/tag',
277196
req,
278197
expect=TagResponse,
279198
spaceId=spaceId,
280199
spaceHandle=spaceHandle,
281-
space=Space
200+
space=space
282201
)

src/steamship/client/operations/__init__.py

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from dataclasses import dataclass
2+
3+
from steamship.base import Client
4+
5+
6+
@dataclass
7+
class ConvertRequest:
8+
type: str = None
9+
pluginInstance: str = None
10+
id: str = None
11+
handle: str = None
12+
name: str = None
13+
14+
@staticmethod
15+
def from_dict(d: any, client: Client = None) -> "ConvertRequest":
16+
return ConvertRequest(
17+
type=d.get('type', None),
18+
pluginInstance=d.get('pluginInstance', None),
19+
id=d.get('id', None),
20+
handle=d.get('handle', None),
21+
name=d.get('name', None)
22+
)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from abc import ABC
2+
from dataclasses import dataclass
3+
from typing import List
4+
5+
from steamship import File
6+
from steamship.base import Client
7+
8+
@dataclass
9+
class CorpusImportRequest:
10+
# The Corpus Identifiers
11+
client: Client = None
12+
id: str = None
13+
handle: str = None
14+
type: str = 'corpus'
15+
16+
# Data for the plugin
17+
value: str = None
18+
data: str = None
19+
url: str = None
20+
pluginInstance: str = None
21+
fileImporterPluginInstance: str = None
22+
23+
@staticmethod
24+
def from_dict(d: any, client: Client = None) -> "CorpusImportRequest":
25+
return CorpusImportRequest(
26+
client=client,
27+
id=d.get('id', None),
28+
handle=d.get('handle', None),
29+
type='corpus',
30+
value=d.get('value', None),
31+
data=d.get('data', None),
32+
url=d.get('url', None),
33+
pluginInstance=d.get('pluginInstance', None),
34+
fileImporterPluginInstance=d.get('fileImporterPluginInstance', None)
35+
)
36+
37+
def to_dict(self) -> dict:
38+
return dict(
39+
id=self.id,
40+
handle=self.handle,
41+
type=self.type,
42+
value=self.value,
43+
data=self.data,
44+
url=self.url,
45+
pluginInstance=self.pluginInstance,
46+
fileImporterPluginInstance=self.fileImporterPluginInstance
47+
)
48+
49+
50+
@dataclass
51+
class CorpusImportResponse:
52+
client: Client = None
53+
fileImportRequests: List[File.CreateRequest] = None
54+
55+
def __init__(
56+
self,
57+
fileImportRequests: List[File.CreateRequest] = None
58+
):
59+
self.fileImportRequests = fileImportRequests
60+
61+
@staticmethod
62+
def from_dict(d: any, client: Client = None) -> "CorpusImportResponse":
63+
return CorpusImportResponse(
64+
client=client,
65+
fileImportRequests=[File.CreateRequest.from_dict(req) for req in d.get('fileImportRequests', [])]
66+
)
67+
68+
def to_dict(self) -> dict:
69+
return dict(
70+
fileImportRequests=self.fileImportRequests
71+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from dataclasses import dataclass
2+
from typing import List, Dict
3+
from steamship.base import Client
4+
5+
6+
@dataclass
7+
class EmbedRequest:
8+
docs: List[str]
9+
pluginInstance: str
10+
metadata: Dict = None
11+
12+
@staticmethod
13+
def from_dict(d: any, client: Client = None) -> "EmbedRequest":
14+
return EmbedRequest(
15+
docs=d.get('docs', None),
16+
pluginInstance=d.get('pluginInstance', None),
17+
metadata=d.get('metadata', {})
18+
)

0 commit comments

Comments
 (0)