Skip to content

Commit 2216002

Browse files
authored
Merge pull request #48 from JigsawStack/update/params
Update/params
2 parents 0a04e8a + bd60621 commit 2216002

File tree

3 files changed

+158
-24
lines changed

3 files changed

+158
-24
lines changed

jigsawstack/image_generation.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,51 @@
66
from typing import List, Union
77
from ._config import ClientConfig
88

9+
class AdvanceConfig(TypedDict):
10+
negative_prompt: NotRequired[str]
11+
guidance: NotRequired[int]
12+
seed: NotRequired[int]
13+
914
class ImageGenerationParams(TypedDict):
1015
prompt: Required[str]
11-
""""
12-
The text to generate the image from."
16+
"""
17+
The text to generate the image from.
1318
"""
1419
aspect_ratio: NotRequired[Literal["1:1", "16:9", "21:9", "3:2", "2:3", "4:5", "5:4", "3:4", "4:3", "9:16", "9:21"]]
1520
"""
1621
The aspect ratio of the image. The default is 1:1.
1722
"""
1823
width: NotRequired[int]
19-
""""
20-
The width of the image. The default is 512."
24+
"""
25+
The width of the image. The default is 512.
2126
"""
2227
height: NotRequired[int]
2328
"""
24-
The height of the image. The default is 512."
29+
The height of the image. The default is 512.
2530
"""
2631
steps: NotRequired[int]
27-
""""
28-
The number of steps to generate the image.""
2932
"""
30-
advance_config: NotRequired[Dict[str, Union[int, str]]]
33+
The number of steps to generate the image.
34+
"""
35+
output_format: NotRequired[Literal["png", "svg"]]
36+
"""
37+
The output format of the generated image. Can be 'png' or 'svg'.
38+
"""
39+
advance_config: NotRequired[AdvanceConfig]
3140
"""
3241
The advance configuration for the image generation. The default is None.
3342
You can pass the following:
34-
- `seed`: The seed for the image generation. The default is None.
35-
- `guidance`: The guidance for the image generation. The default is None.
36-
- `negative_prompt`: The negative prompt for the image generation. The default is None.
43+
- `negative_prompt`: The negative prompt for the image generation
44+
- `guidance`: The guidance scale for the image generation
45+
- `seed`: The seed for reproducible generation
46+
"""
47+
url: NotRequired[str]
48+
"""
49+
URL to use as image input.
50+
"""
51+
file_store_key: NotRequired[str]
52+
"""
53+
File store key to use as image input.
3754
"""
3855

3956
class ImageGenerationResponse(TypedDict):

jigsawstack/search.py

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Union, cast
1+
from typing import Any, Dict, List, Union, cast, Literal
22
from typing_extensions import NotRequired, TypedDict
33
from .request import Request, RequestConfig
44
from .async_request import AsyncRequest, AsyncRequestConfig
@@ -9,30 +9,61 @@
99
class SearchResponse(TypedDict):
1010
success: bool
1111
"""
12-
Indicates whether the translation was successful.
12+
Whether the search request was successful
1313
"""
14-
results: List[Any]
1514

16-
is_safe: bool
15+
query: str
16+
"""
17+
The search query that was used
18+
"""
1719

1820
ai_overview: str
21+
"""
22+
AI-generated overview/summary of the search results
23+
or deep research results if enabled
24+
"""
1925

20-
spell_fixed: str
26+
results: List[Any]
27+
"""
28+
List of search result items
29+
"""
30+
31+
is_safe: bool
32+
"""
33+
Whether the search results passed safe search filtering
34+
"""
35+
36+
spell_fixed: bool
37+
"""
38+
Whether the query was spell-checked and fixed
39+
"""
2140

2241
geo_results: List[Any]
42+
"""
43+
List of location/geographic search results if applicable
44+
"""
2345

2446
image_urls: List[str]
47+
"""
48+
List of image URLs found in the search results
49+
"""
2550

2651
links: List[str]
52+
"""
53+
List of web page URLs found in the search results
54+
"""
2755

2856

2957
class SearchSuggestionsResponse(TypedDict):
3058
success: bool
3159
"""
32-
Indicates whether the translation was successful.
60+
Whether the search suggestions request was successful
3361
"""
3462

3563
suggestions: List[str]
64+
"""
65+
List of search suggestions
66+
"""
3667

3768

3869
class SearchSuggestionsParams(TypedDict):
@@ -41,26 +72,59 @@ class SearchSuggestionsParams(TypedDict):
4172
The search value. The maximum query character length is 200.
4273
"""
4374

75+
class DeepResearchConfig(TypedDict):
76+
max_depth: NotRequired[int]
77+
max_breadth: NotRequired[int]
78+
max_output_tokens: NotRequired[int]
79+
target_output_tokens: NotRequired[int]
4480

4581
class SearchParams(TypedDict):
4682
query: str
4783
"""
48-
The search value. The maximum query character length is 200.
84+
The search query string to execute
4985
"""
50-
ai_overview: NotRequired[bool] = True
86+
87+
spell_check: NotRequired[bool]
5188
"""
52-
Include AI powered overview in the search results. The default value is True
89+
Whether to perform spell checking on the query. Defaults to True.
5390
"""
54-
safe_search: NotRequired[str] = "moderate"
91+
92+
safe_search: NotRequired[Literal["strict", "moderate", "off"]]
5593
"""
56-
Include offensive results in the search results. The default value is "moderate". Supported values: moderate, strict, off
94+
Safe search filtering level. Can be 'strict', 'moderate', or 'off'
5795
"""
58-
spell_check: NotRequired[bool] = True
96+
97+
ai_overview: NotRequired[bool]
5998
"""
60-
Spell check the search query.
99+
Whether to generate an AI-powered overview of the search results. Defaults to True.
61100
"""
62101

63102
byo_urls: NotRequired[List[str]]
103+
"""
104+
List of custom URLs to include in the search results
105+
"""
106+
107+
country_code: NotRequired[str]
108+
"""
109+
Two-letter country code to localize search results (e.g. 'US', 'GB')
110+
"""
111+
112+
auto_scrape: bool
113+
"""
114+
Whether to automatically scrape content from search result URLs
115+
"""
116+
117+
deep_research: NotRequired[bool]
118+
"""
119+
Enable deep research mode for more comprehensive results
120+
"""
121+
122+
deep_research_config: NotRequired[DeepResearchConfig]
123+
"""
124+
Configuration options for deep research mode
125+
"""
126+
127+
64128

65129

66130
class Search(ClientConfig):

tests/test_image_generation.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from unittest.mock import MagicMock
2+
import unittest
3+
from jigsawstack.exceptions import JigsawStackError
4+
import jigsawstack
5+
import pytest
6+
import asyncio
7+
import logging
8+
import io
9+
10+
logging.basicConfig(level=logging.INFO)
11+
logger = logging.getLogger(__name__)
12+
13+
jigsaw = jigsawstack.JigsawStack()
14+
async_jigsaw = jigsawstack.AsyncJigsawStack()
15+
16+
17+
def test_image_generation_response():
18+
async def _test():
19+
client = jigsawstack.AsyncJigsawStack()
20+
try:
21+
result = await client.image_generation({
22+
"prompt": "A beautiful mountain landscape at sunset",
23+
"aspect_ratio": "16:9"
24+
})
25+
# Just check if we got some data back
26+
assert result is not None
27+
assert len(result) > 0
28+
except JigsawStackError as e:
29+
pytest.fail(f"Unexpected JigsawStackError: {e}")
30+
31+
asyncio.run(_test())
32+
33+
34+
def test_image_generation_with_advanced_config():
35+
async def _test():
36+
client = jigsawstack.AsyncJigsawStack()
37+
try:
38+
result = await client.image_generation({
39+
"prompt": "A beautiful mountain landscape at sunset",
40+
"output_format": "png",
41+
"advance_config": {
42+
"negative_prompt": "blurry, low quality",
43+
"guidance": 7,
44+
"seed": 42
45+
}
46+
})
47+
# Just check if we got some data back
48+
assert result is not None
49+
assert len(result) > 0
50+
except JigsawStackError as e:
51+
pytest.fail(f"Unexpected JigsawStackError: {e}")
52+
53+
asyncio.run(_test())

0 commit comments

Comments
 (0)