Skip to content

Commit

Permalink
Add openai-automated to python
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole White committed Oct 23, 2023
1 parent eea57a2 commit 28535ce
Show file tree
Hide file tree
Showing 5 changed files with 911 additions and 4 deletions.
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

0 comments on commit 28535ce

Please sign in to comment.