Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make stream work with returned pipeline_run_id #48

Merged
merged 7 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import asyncio
import os

import gentrace
from dotenv import load_dotenv
from gentrace import providers

load_dotenv()


async def main():
gentrace.api_key = os.getenv("GENTRACE_API_KEY")
gentrace.host = "http://localhost:3000/api/v1"

providers.openai_api_key = os.getenv("OPENAI_KEY")
openai = providers.openai

result = await openai.ChatCompletion.acreate(
pipeline_id="testing-chat-completion-value",
messages=[{"role": "user", "content": "Hello!"}],
model="gpt-3.5-turbo",
stream=True,
)

pipeline_run_id = None
async for value in result:
if value.get("pipeline_run_id"):
pipeline_run_id = value.get("pipeline_run_id")

gentrace.flush()

print("Result: ", pipeline_run_id)


asyncio.run(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import asyncio
import os

import gentrace
from dotenv import load_dotenv
from gentrace import providers

load_dotenv()


async def main():
gentrace.api_key = os.getenv("GENTRACE_API_KEY")
gentrace.host = "http://localhost:3000/api/v1"

providers.openai_api_key = os.getenv("OPENAI_KEY")
openai = providers.openai

result = await openai.ChatCompletion.acreate(
pipeline_id="testing-chat-completion-value",
messages=[{"role": "user", "content": "Hello!"}],
model="gpt-3.5-turbo",
)

gentrace.flush()

print("Result: ", result.pipeline_run_id)


asyncio.run(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

import gentrace
from dotenv import load_dotenv
from gentrace import providers

load_dotenv()

gentrace.api_key = os.getenv("GENTRACE_API_KEY")
gentrace.host = "http://localhost:3000/api/v1"

providers.openai_api_key = os.getenv("OPENAI_KEY")
openai = providers.openai

result = openai.ChatCompletion.create(
pipeline_id="testing-chat-completion-value",
messages=[{"role": "user", "content": "Hello!"}],
model="gpt-3.5-turbo",
stream=True,
)

pipeline_run_id = None

for value in result:
if value.get("pipeline_run_id"):
pipeline_run_id = value.get("pipeline_run_id")

print("Result: ", pipeline_run_id)

gentrace.flush()
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os

import gentrace
from dotenv import load_dotenv
from gentrace import providers

load_dotenv()

gentrace.api_key = os.getenv("GENTRACE_API_KEY")
gentrace.host = "http://localhost:3000/api/v1"

providers.openai_api_key = os.getenv("OPENAI_KEY")
openai = providers.openai

result = openai.ChatCompletion.create(
pipeline_id="testing-chat-completion-value",
messages=[{"role": "user", "content": "Hello!"}],
model="gpt-3.5-turbo",
)

gentrace.flush()

print("Result: ", result.pipeline_run_id)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import asyncio
import os

import gentrace
from dotenv import load_dotenv
from gentrace import providers

load_dotenv()


async def main():
gentrace.api_key = os.getenv("GENTRACE_API_KEY")
gentrace.host = "http://localhost:3000/api/v1"

providers.openai_api_key = os.getenv("OPENAI_KEY")
openai = providers.openai

result = await openai.Completion.acreate(
pipeline_id="text-generation",
model="text-davinci-003",
prompt_template="Hello world {{ name }}",
prompt_inputs={"name": "test"},
stream=True,
)

pipeline_run_id = None
async for value in result:
if value.get("pipeline_run_id"):
pipeline_run_id = value.get("pipeline_run_id")

gentrace.flush()

print("Result: ", pipeline_run_id)


asyncio.run(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import asyncio
import os

import gentrace
from dotenv import load_dotenv
from gentrace import providers

load_dotenv()


async def main():
gentrace.api_key = os.getenv("GENTRACE_API_KEY")
gentrace.host = "http://localhost:3000/api/v1"

providers.openai_api_key = os.getenv("OPENAI_KEY")
openai = providers.openai

result = await openai.Completion.acreate(
pipeline_id="text-generation",
model="text-davinci-003",
prompt_template="Hello world {{ name }}",
prompt_inputs={"name": "test"},
)

gentrace.flush()

print("Result: ", result.pipeline_run_id)


asyncio.run(main())
24 changes: 24 additions & 0 deletions examples/examples/self-contained/openai/create-completion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os

import gentrace
from dotenv import load_dotenv
from gentrace import providers

load_dotenv()

gentrace.api_key = os.getenv("GENTRACE_API_KEY")
gentrace.host = "http://localhost:3000/api/v1"

providers.openai_api_key = os.getenv("OPENAI_KEY")
openai = providers.openai

result = openai.Completion.create(
pipeline_id="text-generation",
model="text-davinci-003",
prompt_template="Hello world {{ name }}",
prompt_inputs={"name": "test"},
)

gentrace.flush()

print("Result: ", result.pipeline_run_id)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import asyncio
import os

import gentrace
from dotenv import load_dotenv
from gentrace import providers

load_dotenv()


async def main():
gentrace.api_key = os.getenv("GENTRACE_API_KEY")
gentrace.host = "http://localhost:3000/api/v1"

providers.openai_api_key = os.getenv("OPENAI_KEY")
openai = providers.openai

result = await openai.Embedding.acreate(
input="sample text",
model="text-similarity-davinci-001",
pipeline_id="testing-value",
)

gentrace.flush()

print("Result: ", result.pipeline_run_id)


asyncio.run(main())
8 changes: 4 additions & 4 deletions examples/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ openai = "^0.27.4"
pinecone-client = "^2.2.1"
python = "^3.11"
python-dotenv = "^1.0.0"
gentrace-py = {path = "../package/dist/gentrace_py-0.3.0.tar.gz", develop = true}
gentrace-py = {path = "../package/dist/gentrace_py-0.4.0.tar.gz", develop = true}

[tool.poetry.group.lint.dependencies]
black = "^23.3.0"
Expand Down
Loading