Skip to content
Open
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
2 changes: 0 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
root = true

[*]

indent_style = space
indent_size = 2

end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand Down
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# OSX
#
.DS_Store

.cosine/
Expand All @@ -11,7 +10,6 @@
jsconfig.json

# Xcode
#
build/
*.pbxuser
!default.pbxuser
Expand All @@ -31,7 +29,6 @@ DerivedData
project.xcworkspace

# Android/IJ
#
.classpath
.cxx
.gradle
Expand All @@ -42,14 +39,12 @@ local.properties
android.iml

# Cocoapods
#
example/ios/Pods

# Ruby
example/vendor/

# node.js
#
node_modules/
npm-debug.log
yarn-debug.log
Expand Down
113 changes: 113 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# OSX
.DS_Store

.cosine/
# XDE
.expo/

# VSCode
.vscode/
jsconfig.json

# Xcode
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IJ
.classpath
.cxx
.gradle
.idea
.project
.settings
local.properties
android.iml

# Cocoapods
example/ios/Pods

# Ruby
example/vendor/

# node.js
node_modules/
npm-debug.log
yarn-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
android/app/libs
android/keystores/debug.keystore

# Yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Expo
.expo/

# Turborepo
.turbo/

# generated by bob
lib/

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
.pnp
.pnp.js

.yarn/
# testing
coverage

# next.js
.next
out

# production
build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts


2 changes: 1 addition & 1 deletion .watchmanconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
4 changes: 2 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ nmHoistingLimits: workspaces

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
spec: '@yarnpkg/plugin-interactive-tools'
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
spec: '@yarnpkg/plugin-workspace-tools'

yarnPath: .yarn/releases/yarn-3.6.1.cjs
21 changes: 10 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Contributor Covenant Code of Conduct

## Our Pledge
Expand All @@ -18,23 +17,23 @@ diverse, inclusive, and healthy community.
Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
- Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of
- The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Add this line to your `metro.config.js` file in order to enable [Package exports
config.resolver.unstable_enablePackageExports = true;
```


### 2. On React Native app

On your React Native app import `useChat` or `useCompletion` from `react-native-vercel-ai`. Same API as Vercel AI library.
Expand Down
20 changes: 10 additions & 10 deletions example/next-app/app/api/assistant/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const openai = new OpenAI({
export const runtime = 'edge';

const homeTemperatures = {
bedroom: 20,
'bedroom': 20,
'home office': 21,
'living room': 21,
kitchen: 22,
bathroom: 23,
'kitchen': 22,
'bathroom': 23,
};

export async function POST(req: Request) {
Expand Down Expand Up @@ -50,7 +50,7 @@ export async function POST(req: Request) {
// Poll for status change
while (run.status === 'queued' || run.status === 'in_progress') {
// delay for 500ms:
await new Promise(resolve => setTimeout(resolve, 500));
await new Promise((resolve) => setTimeout(resolve, 500));

run = await openai.beta.threads.runs.retrieve(threadId!, run.id);
}
Expand All @@ -69,7 +69,7 @@ export async function POST(req: Request) {
if (run.required_action?.type === 'submit_tool_outputs') {
const tool_outputs =
run.required_action.submit_tool_outputs.tool_calls.map(
toolCall => {
(toolCall) => {
const parameters = JSON.parse(toolCall.function.arguments);

switch (toolCall.function.name) {
Expand Down Expand Up @@ -98,16 +98,16 @@ export async function POST(req: Request) {

default:
throw new Error(
`Unknown tool call function: ${toolCall.function.name}`,
`Unknown tool call function: ${toolCall.function.name}`
);
}
},
}
);

run = await openai.beta.threads.runs.submitToolOutputs(
threadId!,
run.id,
{ tool_outputs },
{ tool_outputs }
);

await waitForRun(run);
Expand All @@ -131,10 +131,10 @@ export async function POST(req: Request) {
id: message.id,
role: 'assistant',
content: message.content.filter(
content => content.type === 'text',
(content) => content.type === 'text'
) as Array<MessageContentText>,
});
}
},
}
);
}
2 changes: 1 addition & 1 deletion example/next-app/app/api/chat-with-functions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function POST(req: Request) {
const stream = OpenAIStream(response, {
experimental_onFunctionCall: async (
{ name, arguments: args },
createFunctionCallMessages,
createFunctionCallMessages
) => {
if (name === 'get_current_weather') {
// Call a weather API here
Expand Down
2 changes: 1 addition & 1 deletion example/next-app/app/api/chat-with-vision/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ./app/api/chat/route.ts
import OpenAI from 'openai';
import { OpenAIStream, StreamingTextResponse } from 'ai';
import OpenAI from 'openai';

// Create an OpenAI API client (that's edge friendly!)
const openai = new OpenAI({
Expand Down
33 changes: 19 additions & 14 deletions example/next-app/app/api/chat/middleware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
// src/app/middleware.js
// or
// src/pages/middleware.js
import { NextResponse } from "next/server";
import { NextResponse } from 'next/server';

export function middleware() {
// retrieve the current response
const res = NextResponse.next()
// add the CORS headers to the response
res.headers.append('Access-Control-Allow-Credentials', "true")
res.headers.append('Access-Control-Allow-Origin', '*') // replace this with your actual origin
res.headers.append('Access-Control-Allow-Methods', 'GET,DELETE,PATCH,POST,PUT')
res.headers.append(
'Access-Control-Allow-Headers',
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
)
return res
// retrieve the current response
const res = NextResponse.next();
// add the CORS headers to the response
res.headers.append('Access-Control-Allow-Credentials', 'true');
res.headers.append('Access-Control-Allow-Origin', '*'); // replace this with your actual origin
res.headers.append(
'Access-Control-Allow-Methods',
'GET,DELETE,PATCH,POST,PUT'
);
res.headers.append(
'Access-Control-Allow-Headers',
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
);
return res;
}

// specify the path regex to apply the middleware to
export const config = {
matcher: '/api/:path*',
}
matcher: '/api/:path*',
};
Loading