Skip to content

Commit

Permalink
feat: add in gentrace.flush (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
viveknair committed Apr 19, 2023
1 parent 5dcd0b2 commit f896cc2
Show file tree
Hide file tree
Showing 27 changed files with 796 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ async def main():

openai = runner.get_openai()

result = await openai.Embedding.acreate(
input="sample text", model="text-similarity-davinci-001"
result = openai.ChatCompletion.create(
messages=[{"role": "user", "content": "Hello!"}], model="gpt-3.5-turbo"
)

print("Result: ", result)
Expand Down
38 changes: 38 additions & 0 deletions examples/examples/pipeline/openai/create-chat-completion-async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import asyncio
import os

import gentrace
from dotenv import load_dotenv

load_dotenv()


async def main():
pipeline = gentrace.Pipeline(
"test-gentrace-python-pipeline",
os.getenv("GENTRACE_API_KEY"),
host="http://localhost:3000/api/v1",
openai_config={
"api_key": os.getenv("OPENAI_KEY"),
},
)

pipeline.setup()

runner = pipeline.start()

openai = runner.get_openai()

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

print("Result: ", result)

info = runner.submit()

print("Response: ", info["pipelineRunId"])


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

import gentrace
from dotenv import load_dotenv

load_dotenv()

pipeline = gentrace.Pipeline(
"test-gentrace-python-pipeline",
os.getenv("GENTRACE_API_KEY"),
host="http://localhost:3000/api/v1",
openai_config={
"api_key": os.getenv("OPENAI_KEY"),
},
)

pipeline.setup()

runner = pipeline.start()

openai = runner.get_openai()

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

for completion in result:
pass

print("Result: ", result)

info = runner.submit()

print("Response: ", info["pipelineRunId"])
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
openai = runner.get_openai()

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

print("Result: ", result)
Expand Down
37 changes: 37 additions & 0 deletions examples/examples/pipeline/openai/create-completion-async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import asyncio
import os

import gentrace
from dotenv import load_dotenv

load_dotenv()


async def main():
pipeline = gentrace.Pipeline(
"test-gentrace-python-pipeline",
os.getenv("GENTRACE_API_KEY"),
host="http://localhost:3000/api/v1",
openai_config={
"api_key": os.getenv("OPENAI_KEY"),
},
)

pipeline.setup()

runner = pipeline.start()

openai = runner.get_openai()

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

info = runner.submit()

print("Response: ", info["pipelineRunId"])


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

import gentrace
from dotenv import load_dotenv

load_dotenv()

pipeline = gentrace.Pipeline(
"test-gentrace-python-pipeline",
os.getenv("GENTRACE_API_KEY"),
host="http://localhost:3000/api/v1",
openai_config={
"api_key": os.getenv("OPENAI_KEY"),
},
)

pipeline.setup()

runner = pipeline.start()

openai = runner.get_openai()

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

for value in result:
pass

print("Result: ", result)

info = runner.submit()

print("Response: ", info["pipelineRunId"])
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
prompt_inputs={"name": "test"},
)

for value in result:
pass

print("Result: ", result)

info = runner.submit()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions examples/examples/self-contained/openai/create-embedding.py
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.Embedding.create(
input="sample text",
model="text-similarity-davinci-001",
pipeline_id="testing-value",
)

gentrace.flush()

print("Result: ", result.pipeline_run_id)
26 changes: 13 additions & 13 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.2.2.tar.gz", develop = true}
gentrace-py = {path = "../package/dist/gentrace_py-0.3.0.tar.gz", develop = true}

[tool.poetry.group.lint.dependencies]
black = "^23.3.0"
Expand Down
7 changes: 6 additions & 1 deletion package/gentrace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
from gentrace.exceptions import ApiException

from gentrace.providers.pipeline import Pipeline
from gentrace.providers.pipeline_run import PipelineRun
from gentrace.providers.pipeline_run import PipelineRun, flush
from gentrace.providers.step_run import StepRun
from gentrace.providers.utils import to_date_string

from gentrace.providers.getters import providers

api_key = ""
host = ""
1 change: 1 addition & 0 deletions package/gentrace/providers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from gentrace.providers.getters import providers
from gentrace.providers.pipeline import Pipeline
from gentrace.providers.pipeline_run import PipelineRun
from gentrace.providers.step_run import StepRun
Loading

0 comments on commit f896cc2

Please sign in to comment.