Skip to content

Commit

Permalink
Add openai-automated to python (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole White authored Oct 23, 2023
1 parent eea57a2 commit 2ff7dc0
Show file tree
Hide file tree
Showing 6 changed files with 912 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
project:
- Python/langchain
- Python/openai-manual
- Python/openai-automated

steps:
- name: Checkout repository
Expand Down
34 changes: 34 additions & 0 deletions Python/openai-automated/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!-- banner start -->
<p align="center">
<img src="https://app.autoblocks.ai/images/logo.png" width="300px">
</p>

<p align="center">
<a href="https://docs.autoblocks.ai/">Documentation</a>
|
<a href="https://app.autoblocks.ai/">Application</a>
|
<a href="https://www.autoblocks.ai/">Home</a>
</p>

<p align="center">
:bangbang:
Make sure you've read the <a href="/README.md#getting-started">getting started</a> section in the main README.
</p>
<!-- banner end -->

## Install dependencies:

```bash
poetry install
```

## Run the script

```bash
poetry run python main.py
```

## View logs in Autoblocks

After you run the script, you can view your trace on the [explore page](https://app.autoblocks.ai/explore).
36 changes: 36 additions & 0 deletions Python/openai-automated/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import dotenv

# Environment variables need to be loaded before we import
# trace_openai and openai
dotenv.load_dotenv("../../.env")

from autoblocks.vendor.openai import trace_openai
import openai


def main():
# Call at the entrypoint to your application
trace_openai()
print("Automatically tracing all calls to OpenAI...")

print("Calling OpenAI...")
openai.ChatCompletion.create(
messages=[
{
"role": "system",
"content": "You are a helpful assistant. You answer questions about a software product named Acme."
},
{
"role": "user",
"content": "How do I sign up?"
}
],
model="gpt-3.5-turbo",
temperature=0.7,
)
print("Finished calling OpenAI")
print("View the trace at https://app.autoblocks.ai/explore")


if __name__ == "__main__":
main()
Loading

1 comment on commit 2ff7dc0

@vercel
Copy link

@vercel vercel bot commented on 2ff7dc0 Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.