-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1051 from parea-ai/PAI-1464-make-trace-decorator-…
…work-with-iterator-responses Pai 1464 make trace decorator work with iterator responses
- Loading branch information
Showing
7 changed files
with
130 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,81 @@ | ||
import os | ||
|
||
import anthropic | ||
import instructor | ||
from dotenv import load_dotenv | ||
from openai import AsyncOpenAI | ||
from pydantic import BaseModel | ||
|
||
from parea import Parea | ||
from parea import Parea, trace | ||
|
||
load_dotenv() | ||
|
||
client = AsyncOpenAI() | ||
oai_aclient = AsyncOpenAI() | ||
ant_client = anthropic.AsyncClient() | ||
|
||
p = Parea(api_key=os.getenv("PAREA_API_KEY")) | ||
p.wrap_openai_client(client, "instructor") | ||
|
||
client = instructor.from_openai(client) | ||
|
||
p.wrap_openai_client(oai_aclient, "instructor") | ||
p.wrap_anthropic_client(ant_client) | ||
|
||
from pydantic import BaseModel | ||
oai_aclient = instructor.from_openai(oai_aclient) | ||
ant_client = instructor.from_anthropic(ant_client) | ||
|
||
|
||
class UserDetail(BaseModel): | ||
name: str | ||
age: int | ||
age: str | ||
|
||
|
||
async def main(): | ||
user = client.completions.create_partial( | ||
model="gpt-3.5-turbo", | ||
@trace | ||
async def ainner_main(): | ||
user = oai_aclient.completions.create_partial( | ||
model="gpt-4o-mini", | ||
max_tokens=1024, | ||
max_retries=3, | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": "Please crea a user", | ||
"content": "Please create a user", | ||
} | ||
], | ||
response_model=UserDetail, | ||
) | ||
# print(user) | ||
async for u in user: | ||
return user | ||
|
||
|
||
async def amain(): | ||
resp = await ainner_main() | ||
async for u in resp: | ||
print(u) | ||
|
||
# user2 = client.completions.create_partial( | ||
# model="gpt-3.5-turbo", | ||
# max_tokens=1024, | ||
# max_retries=3, | ||
# messages=[ | ||
# { | ||
# "role": "user", | ||
# "content": "Please crea a user", | ||
# } | ||
# ], | ||
# response_model=UserDetail, | ||
# ) | ||
# async for u in user2: | ||
# print(u) | ||
|
||
@trace | ||
def inner_main(): | ||
user = ant_client.completions.create_partial( | ||
model="claude-3-5-sonnet-20240620", | ||
max_tokens=1024, | ||
max_retries=3, | ||
messages=[ | ||
{ | ||
"role": "user", | ||
"content": "Please create a user", | ||
} | ||
], | ||
response_model=UserDetail, | ||
) | ||
return user | ||
|
||
|
||
def main(): | ||
resp = inner_main() | ||
for u in resp: | ||
print(u) | ||
|
||
|
||
if __name__ == "__main__": | ||
import asyncio | ||
|
||
asyncio.run(main()) | ||
asyncio.run(amain()) | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api" | |
[tool.poetry] | ||
name = "parea-ai" | ||
packages = [{ include = "parea" }] | ||
version = "0.2.201" | ||
version = "0.2.202" | ||
description = "Parea python sdk" | ||
readme = "README.md" | ||
authors = ["joel-parea-ai <[email protected]>"] | ||
|