Skip to content

Commit 3146819

Browse files
committed
feat: get_output_text
1 parent e86093a commit 3146819

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

genstack/genstack.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ async def __call(self, payload: Dict[str, Any]) -> Dict[str, Any]:
2929
return {"error" : str(e)}
3030
async def __generate_async(self, payload : Dict[str, Any]) -> Dict[str, Any]:
3131
return await self.__call(payload=payload)
32+
def __extract_first_text(self, result: dict) -> str:
33+
for o in result.get("output", []):
34+
if o.get("output", {}).get("type") == "TEXT":
35+
return o["output"].get("text", "")
36+
return ""
3237
def generate(self, input : Union[str, Dict[str, Any]], model : Optional[str] = "auto", track : Optional[str] = None) -> Dict[str, Any]:
3338
if not track :
3439
raise ValueError("Track is required.")
@@ -44,4 +49,8 @@ def generate(self, input : Union[str, Dict[str, Any]], model : Optional[str] = "
4449
"model": model,
4550
"track": track
4651
}
47-
return asyncio.run(self.__generate_async(payload=payload))
52+
return asyncio.run(self.__generate_async(payload=payload))
53+
def get_output_text(self, input: Union[str, Dict[str, Any]], model: Optional[str] = "auto", track: Optional[str] = None) -> str:
54+
result = self.generate(input=input, model=model, track=track)
55+
first_text : str = self.__extract_first_text(result)
56+
return first_text

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "genstack"
3-
version = "0.1.9"
3+
version = "0.2.0"
44
description = "Universal AI SDK from Genstack"
55
authors = [{name="Shrey Kumar", email="shreyk.dev@gmail.com"}]
66
readme = "README.md"

tests/call_test.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
client = Genstack(api_key=os.getenv("GENSTACK_API_KEY"))
1010

1111

12-
res = client.generate(input="3 fun facts about Ferrari", track="dragon-track", model="gpt-4-1-nano-oai")
12+
res = client.get_output_text(input="3 fun facts about Ferrari", track="ultimate-track", model="gpt-4o-oai")
1313

14-
if "output" in res:
15-
print(res["output"][0]["output"]["text"])
16-
else:
17-
print("Error:", res.get("message", "Unknown error"))
14+
print(res)

0 commit comments

Comments
 (0)