latitude-sdk 1.0.3__tar.gz → 1.1.0__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.
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/PKG-INFO +1 -1
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/pyproject.toml +1 -1
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/client/payloads.py +6 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/client/router.py +11 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/sdk/prompts.py +24 -1
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/sdk/types.py +11 -0
- latitude_sdk-1.1.0/tests/prompts/get_all_test.py +62 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/utils/fixtures.py +4 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/uv.lock +1 -1
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/.gitignore +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/.python-version +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/README.md +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/scripts/format.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/scripts/lint.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/scripts/test.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/__init__.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/client/__init__.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/client/client.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/env/__init__.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/env/env.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/py.typed +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/sdk/__init__.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/sdk/errors.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/sdk/evaluations.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/sdk/latitude.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/sdk/logs.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/util/__init__.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/src/latitude_sdk/util/utils.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/__init__.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/evaluations/__init__.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/evaluations/create_result_test.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/evaluations/trigger_test.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/logs/__init__.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/logs/create_test.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/prompts/__init__.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/prompts/chat_test.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/prompts/get_or_create_test.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/prompts/get_test.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/prompts/render_chain_test.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/prompts/render_test.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/prompts/run_test.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/utils/__init__.py +0 -0
- {latitude_sdk-1.0.3 → latitude_sdk-1.1.0}/tests/utils/utils.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: latitude-sdk
|
3
|
-
Version: 1.0
|
3
|
+
Version: 1.1.0
|
4
4
|
Summary: Latitude SDK for Python
|
5
5
|
Project-URL: repository, https://github.com/latitude-dev/latitude-llm/tree/main/packages/sdks/python
|
6
6
|
Project-URL: homepage, https://github.com/latitude-dev/latitude-llm/tree/main/packages/sdks/python#readme
|
@@ -23,6 +23,10 @@ class GetPromptRequestParams(PromptRequestParams, Model):
|
|
23
23
|
path: str
|
24
24
|
|
25
25
|
|
26
|
+
class GetAllPromptRequestParams(PromptRequestParams, Model):
|
27
|
+
pass
|
28
|
+
|
29
|
+
|
26
30
|
class GetOrCreatePromptRequestParams(PromptRequestParams, Model):
|
27
31
|
pass
|
28
32
|
|
@@ -90,6 +94,7 @@ class CreateEvaluationResultRequestBody(Model):
|
|
90
94
|
|
91
95
|
RequestParams = Union[
|
92
96
|
GetPromptRequestParams,
|
97
|
+
GetAllPromptRequestParams,
|
93
98
|
GetOrCreatePromptRequestParams,
|
94
99
|
RunPromptRequestParams,
|
95
100
|
ChatPromptRequestParams,
|
@@ -111,6 +116,7 @@ RequestBody = Union[
|
|
111
116
|
|
112
117
|
class RequestHandler(StrEnum):
|
113
118
|
GetPrompt = "GET_PROMPT"
|
119
|
+
GetAllPrompts = "GET_ALL_PROMPTS"
|
114
120
|
GetOrCreatePrompt = "GET_OR_CREATE_PROMPT"
|
115
121
|
RunPrompt = "RUN_PROMPT"
|
116
122
|
ChatPrompt = "CHAT_PROMPT"
|
@@ -4,6 +4,7 @@ from latitude_sdk.client.payloads import (
|
|
4
4
|
ChatPromptRequestParams,
|
5
5
|
CreateEvaluationResultRequestParams,
|
6
6
|
CreateLogRequestParams,
|
7
|
+
GetAllPromptRequestParams,
|
7
8
|
GetOrCreatePromptRequestParams,
|
8
9
|
GetPromptRequestParams,
|
9
10
|
RequestHandler,
|
@@ -36,6 +37,14 @@ class Router:
|
|
36
37
|
version_uuid=params.version_uuid,
|
37
38
|
).prompt(params.path)
|
38
39
|
|
40
|
+
if handler == RequestHandler.GetAllPrompts:
|
41
|
+
assert isinstance(params, GetAllPromptRequestParams)
|
42
|
+
|
43
|
+
return "GET", self.prompts(
|
44
|
+
project_id=params.project_id,
|
45
|
+
version_uuid=params.version_uuid,
|
46
|
+
).all_prompts
|
47
|
+
|
39
48
|
elif handler == RequestHandler.GetOrCreatePrompt:
|
40
49
|
assert isinstance(params, GetOrCreatePromptRequestParams)
|
41
50
|
|
@@ -94,6 +103,7 @@ class Router:
|
|
94
103
|
|
95
104
|
class Prompts(Model):
|
96
105
|
prompt: Callable[[str], str]
|
106
|
+
all_prompts: str
|
97
107
|
get_or_create: str
|
98
108
|
run: str
|
99
109
|
logs: str
|
@@ -102,6 +112,7 @@ class Router:
|
|
102
112
|
base_url = f"{self.commits_url(project_id, version_uuid)}/documents"
|
103
113
|
|
104
114
|
return self.Prompts(
|
115
|
+
all_prompts=f"{base_url}",
|
105
116
|
prompt=lambda path: f"{base_url}/{path}",
|
106
117
|
get_or_create=f"{base_url}/get-or-create",
|
107
118
|
run=f"{base_url}/run",
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import asyncio
|
2
|
-
from typing import Any, AsyncGenerator, Optional, Sequence, Union
|
2
|
+
from typing import Any, AsyncGenerator, List, Optional, Sequence, Union
|
3
3
|
|
4
4
|
from promptl_ai import Adapter, Message, MessageLike, Promptl, ToolMessage, ToolResultContent
|
5
5
|
from promptl_ai.bindings.types import _Message
|
@@ -9,6 +9,7 @@ from latitude_sdk.client import (
|
|
9
9
|
ChatPromptRequestParams,
|
10
10
|
Client,
|
11
11
|
ClientEvent,
|
12
|
+
GetAllPromptRequestParams,
|
12
13
|
GetOrCreatePromptRequestBody,
|
13
14
|
GetOrCreatePromptRequestParams,
|
14
15
|
GetPromptRequestParams,
|
@@ -33,6 +34,7 @@ from latitude_sdk.sdk.types import (
|
|
33
34
|
ToolResult,
|
34
35
|
_LatitudeEvent,
|
35
36
|
)
|
37
|
+
from latitude_sdk.util import Adapter as AdapterUtil
|
36
38
|
from latitude_sdk.util import Model
|
37
39
|
|
38
40
|
_PROVIDER_TO_ADAPTER = {
|
@@ -67,6 +69,13 @@ class GetPromptResult(Prompt, Model):
|
|
67
69
|
pass
|
68
70
|
|
69
71
|
|
72
|
+
_GetAllPromptResults = AdapterUtil[List[GetPromptResult]](List[GetPromptResult])
|
73
|
+
|
74
|
+
|
75
|
+
class GetAllPromptOptions(PromptOptions, Model):
|
76
|
+
pass
|
77
|
+
|
78
|
+
|
70
79
|
class GetOrCreatePromptOptions(PromptOptions, Model):
|
71
80
|
prompt: Optional[str] = None
|
72
81
|
|
@@ -283,6 +292,20 @@ class Prompts:
|
|
283
292
|
) as response:
|
284
293
|
return GetPromptResult.model_validate_json(response.content)
|
285
294
|
|
295
|
+
async def get_all(self, options: Optional[GetAllPromptOptions] = None) -> List[GetPromptResult]:
|
296
|
+
options = GetAllPromptOptions(**{**dict(self._options), **dict(options or {})})
|
297
|
+
self._ensure_prompt_options(options)
|
298
|
+
assert options.project_id is not None
|
299
|
+
|
300
|
+
async with self._client.request(
|
301
|
+
handler=RequestHandler.GetAllPrompts,
|
302
|
+
params=GetAllPromptRequestParams(
|
303
|
+
project_id=options.project_id,
|
304
|
+
version_uuid=options.version_uuid,
|
305
|
+
),
|
306
|
+
) as response:
|
307
|
+
return _GetAllPromptResults.validate_json(response.content)
|
308
|
+
|
286
309
|
async def get_or_create(
|
287
310
|
self, path: str, options: Optional[GetOrCreatePromptOptions] = None
|
288
311
|
) -> GetOrCreatePromptResult:
|
@@ -24,11 +24,22 @@ class Providers(StrEnum):
|
|
24
24
|
Custom = "custom"
|
25
25
|
|
26
26
|
|
27
|
+
class ParameterType(StrEnum):
|
28
|
+
Text = "text"
|
29
|
+
File = "file"
|
30
|
+
Image = "image"
|
31
|
+
|
32
|
+
|
33
|
+
class PromptParameter(Model):
|
34
|
+
type: ParameterType
|
35
|
+
|
36
|
+
|
27
37
|
class Prompt(Model):
|
28
38
|
uuid: str
|
29
39
|
path: str
|
30
40
|
content: str
|
31
41
|
config: dict[str, Any]
|
42
|
+
parameters: dict[str, PromptParameter]
|
32
43
|
provider: Optional[Providers] = None
|
33
44
|
|
34
45
|
|
@@ -0,0 +1,62 @@
|
|
1
|
+
from typing import List, cast
|
2
|
+
|
3
|
+
import httpx
|
4
|
+
|
5
|
+
from latitude_sdk.sdk.prompts import GetAllPromptOptions, GetPromptResult
|
6
|
+
from tests.utils import TestCase, fixtures
|
7
|
+
|
8
|
+
|
9
|
+
class TestGetAllPrompts(TestCase):
|
10
|
+
async def test_success_global_options(self):
|
11
|
+
endpoint = f"/projects/{self.project_id}/versions/{self.version_uuid}/documents"
|
12
|
+
endpoint_mock = self.gateway_mock.get(endpoint).mock(
|
13
|
+
return_value=httpx.Response(200, json=[fixtures.PROMPT_RESPONSE])
|
14
|
+
)
|
15
|
+
|
16
|
+
result = await self.sdk.prompts.get_all()
|
17
|
+
request, _ = endpoint_mock.calls.last
|
18
|
+
|
19
|
+
self.assert_requested(request, method="GET", endpoint=endpoint)
|
20
|
+
self.assertEqual(endpoint_mock.call_count, 1)
|
21
|
+
self.assertEqual(result, [GetPromptResult(**dict(fixtures.PROMPT))])
|
22
|
+
|
23
|
+
async def test_success_overrides_options(self):
|
24
|
+
options = GetAllPromptOptions(project_id=21, version_uuid="version-uuid")
|
25
|
+
endpoint = f"/projects/{options.project_id}/versions/{options.version_uuid}/documents"
|
26
|
+
endpoint_mock = self.gateway_mock.get(endpoint).mock(
|
27
|
+
return_value=httpx.Response(200, json=[fixtures.PROMPT_RESPONSE])
|
28
|
+
)
|
29
|
+
|
30
|
+
result = await self.sdk.prompts.get_all(options)
|
31
|
+
request, _ = endpoint_mock.calls.last
|
32
|
+
|
33
|
+
self.assert_requested(request, method="GET", endpoint=endpoint)
|
34
|
+
self.assertEqual(endpoint_mock.call_count, 1)
|
35
|
+
self.assertEqual(result, [GetPromptResult(**dict(fixtures.PROMPT))])
|
36
|
+
|
37
|
+
async def test_success_default_version_uuid(self):
|
38
|
+
self.sdk._options.version_uuid = None # pyright: ignore [reportPrivateUsage]
|
39
|
+
endpoint = f"/projects/{self.project_id}/versions/live/documents"
|
40
|
+
endpoint_mock = self.gateway_mock.get(endpoint).mock(
|
41
|
+
return_value=httpx.Response(200, json=[fixtures.PROMPT_RESPONSE])
|
42
|
+
)
|
43
|
+
|
44
|
+
result = await self.sdk.prompts.get_all()
|
45
|
+
request, _ = endpoint_mock.calls.last
|
46
|
+
|
47
|
+
self.assert_requested(request, method="GET", endpoint=endpoint)
|
48
|
+
self.assertEqual(endpoint_mock.call_count, 1)
|
49
|
+
self.assertEqual(result, [GetPromptResult(**dict(fixtures.PROMPT))])
|
50
|
+
|
51
|
+
async def test_fails(self):
|
52
|
+
endpoint = f"/projects/{self.project_id}/versions/{self.version_uuid}/documents"
|
53
|
+
endpoint_mock = self.gateway_mock.get(endpoint).mock(
|
54
|
+
return_value=httpx.Response(500, json=fixtures.ERROR_RESPONSE)
|
55
|
+
)
|
56
|
+
|
57
|
+
with self.assertRaisesRegex(type(fixtures.ERROR), fixtures.ERROR.message):
|
58
|
+
await self.sdk.prompts.get_all()
|
59
|
+
requests = cast(List[httpx.Request], [request for request, _ in endpoint_mock.calls]) # type: ignore
|
60
|
+
|
61
|
+
[self.assert_requested(request, method="GET", endpoint=endpoint) for request in requests]
|
62
|
+
self.assertEqual(endpoint_mock.call_count, self.internal_options.retries)
|
@@ -35,7 +35,9 @@ from latitude_sdk import (
|
|
35
35
|
Log,
|
36
36
|
LogSources,
|
37
37
|
ModelUsage,
|
38
|
+
ParameterType,
|
38
39
|
Prompt,
|
40
|
+
PromptParameter,
|
39
41
|
Providers,
|
40
42
|
StreamEvent,
|
41
43
|
StreamEvents,
|
@@ -86,6 +88,7 @@ topP: 0.9
|
|
86
88
|
"topP": 0.9,
|
87
89
|
},
|
88
90
|
"provider": "openai",
|
91
|
+
"parameters": {"question": {"type": "text"}},
|
89
92
|
}
|
90
93
|
|
91
94
|
PROMPT = Prompt(
|
@@ -116,6 +119,7 @@ topP: 0.9
|
|
116
119
|
"topP": 0.9,
|
117
120
|
},
|
118
121
|
provider=Providers.OpenAI,
|
122
|
+
parameters={"question": PromptParameter(type=ParameterType.Text)},
|
119
123
|
)
|
120
124
|
|
121
125
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|