Skip to content

Commit

Permalink
Merge branch 'main' into feature/codeinterpreter-output-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigio committed May 3, 2024
2 parents fb8ce65 + 1fa3266 commit 2131970
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
# Instead, rename this file to ".env" instead of ".env.example". (.env will not be committed)

# Create an OpenAI API key at https://platform.openai.com/account/api-keys
OPENAI_API_KEY="sk-123..."
OPENAI_API_KEY="sk-123..."

# (optional) Create an OpenAI Assistant at https://platform.openai.com/assistants.
# IMPORTANT! Be sure to enable file search and code interpreter tools.
OPENAI_ASSISTANT_ID="123..."
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
# OpenAI Assistants API Quickstart

A quick-start template using the OpenAI [Assistants API](https://platform.openai.com/docs/assistants/overview) with [Next.js](https://nextjs.org/docs).
<br/>
<br/>
![OpenAI Assistants API Quickstart](https://github.com/openai/openai-assistants-quickstart/assets/27232/755e85e9-3ea4-421f-b202-3b0c435ea270)



## Quickstart Setup

### 1. Clone repo

```shell
git clone https://github.com/openai/openai-assistants-quickstart.git
cd openai-assistants-quickstart
```

### 2. Set your [OpenAI API key](https://platform.openai.com/api-keys)

```shell
export OPENAI_API_KEY="sk_..."
```

(or in `.env.example` and rename it to `.env`).

### 3. Install dependencies

```shell
npm install
```

### 4. Run

```shell
npm run dev
```

### 5. Navigate to [http:https://localhost:3000](http:https://localhost:3000).

## Deployment

You can deploy this project to Vercel or any other platform that supports Next.js.

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fopenai%2Fopenai-assistants-quickstart&env=OPENAI_API_KEY,OPENAI_ASSISTANT_ID&envDescription=API%20Keys%20and%20Instructions&envLink=https%3A%2F%2Fgithub.com%2Fopenai%2Fopenai-assistants-quickstart%2Fblob%2Fmain%2F.env.example)

## Overview

This project is intended to serve as a template for using the Assistants API in Next.js with [streaming](https://platform.openai.com/docs/assistants/overview/step-4-create-a-run), tool use ([code interpreter](https://platform.openai.com/docs/assistants/tools/code-interpreter) and [file search](https://platform.openai.com/docs/assistants/tools/file-search)), and [function calling](https://platform.openai.com/docs/assistants/tools/function-calling). While there are multiple pages to demonstrate each of these capabilities, they all use the same underlying assistant with all capabilities enabled.
Expand Down Expand Up @@ -61,4 +71,3 @@ The main logic for chat will be found in the `Chat` component in `app/components
## Feedback

Let us know if you have any thoughts, questions, or feedback in [this form](https://docs.google.com/forms/d/e/1FAIpQLScn_RSBryMXCZjCyWV4_ebctksVvQYWkrq90iN21l1HLv3kPg/viewform?usp=sf_link)!

2 changes: 1 addition & 1 deletion app/api/assistants/threads/[threadId]/messages/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function POST(request, { params: { threadId } }) {
content: content,
});

const stream = openai.beta.threads.runs.createAndStream(threadId, {
const stream = openai.beta.threads.runs.stream(threadId, {
assistant_id: assistantId,
});

Expand Down
6 changes: 5 additions & 1 deletion app/assistant-config.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const assistantId = ""; // set your assistant ID here
export let assistantId = ""; // set your assistant ID here

if (assistantId === "") {
assistantId = process.env.OPENAI_ASSISTANT_ID;
}

0 comments on commit 2131970

Please sign in to comment.