-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from backmesh/test
Optional callbacks + add basic tests in CI
- Loading branch information
Showing
9 changed files
with
8,140 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
|
||
- name: Install dependencies | ||
run: yarn | ||
|
||
- name: Run tests | ||
run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules | ||
dist | ||
dist | ||
openai-node | ||
scripts/test-runner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = function (api) { | ||
api.cache(true); | ||
return { | ||
presets: ['babel-preset-expo'], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
rm -rf openai-node | ||
git clone https://github.com/openai/openai-node.git | ||
cd openai-node | ||
bash scripts/mock --daemon | ||
cd .. | ||
cp openai-node/scripts/test scripts/test-runner | ||
bash scripts/test-runner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { | ||
OpenAI, | ||
} from '../src/index'; | ||
|
||
// jest runs in node, but this is needed by react-native-sse | ||
global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; | ||
|
||
// using mocks from https://github.com/openai/openai-node/blob/master/.stats.yml#L2 | ||
describe('OpenAI Integration Tests', () => { | ||
let openAI: OpenAI; | ||
|
||
beforeEach(() => { | ||
openAI = new OpenAI({ | ||
apiKey: 'test-api-key', // Replace with a valid API key | ||
baseURL: 'http://127.0.0.1:4010', // Replace with your local server URL | ||
}); | ||
}); | ||
|
||
describe('beta.assistants', () => { | ||
it('should get assistants', async () => { | ||
const assistant = await openAI.beta.assistants.list(); | ||
expect(assistant).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('moderations', () => { | ||
it('should create moderation', async () => { | ||
const moderation = await openAI.moderations.create({ input: 'test' }); | ||
expect(moderation).toBeDefined(); | ||
expect(moderation.id).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('chat.completions', () => { | ||
it('should create completion', async () => { | ||
const completion = await openAI.chat.completions.create({ | ||
model: 'gpt-4o-mini', | ||
messages: [{"role": "user", "content": "Hello!"}], | ||
}); | ||
expect(completion).toBeDefined(); | ||
expect(completion.id).toBeDefined(); | ||
const content = completion.choices[0].message; | ||
expect(content).toBeDefined(); | ||
}); | ||
it('should stream completion', async () => { | ||
openAI.chat.completions.stream( | ||
{ | ||
model: 'gpt-4o-mini', | ||
messages: [{"role": "user", "content": "Hello!"}], | ||
}, | ||
(completion) => { | ||
expect(completion).toBeDefined(); | ||
expect(completion.id).toBeDefined(); | ||
const content = completion.choices[0].message; | ||
expect(content).toBeDefined(); | ||
}, | ||
{ | ||
onError: (error) => expect(error).not.toBeDefined(), | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
// https://stackoverflow.com/questions/58262638/why-doesnt-expo-file-system-work-in-jest | ||
// describe('files', () => { | ||
// it('should upload file', async () => { | ||
// const FileUploadTestComponent = () => { | ||
// const [file, setFile] = useState<any | null>(null); | ||
// const [error, setError] = useState<any | null>(null); | ||
|
||
// const handleFileUpload = async () => { | ||
// try { | ||
// const uploadedFile = await openAI.files.create('../README.md', 'fine-tune'); | ||
// setFile(uploadedFile); | ||
// } catch (err) { | ||
// setError(err); | ||
// } | ||
// }; | ||
|
||
// return ( | ||
// <View> | ||
// <Button title="Upload File" onPress={handleFileUpload} /> | ||
// {file && ( | ||
// <Text>File uploaded successfully: {file.id}</Text> | ||
// )} | ||
// {error && ( | ||
// <Text>Error uploading file: {error}</Text> | ||
// )} | ||
// </View> | ||
// ); | ||
// }; | ||
// const { getByText, findByText } = renderer.create(<FileUploadTestComponent />); | ||
// fireEvent.press(getByText('Upload File')); | ||
|
||
// const successMessage = await findByText(/File uploaded successfully:/); | ||
// expect(successMessage).toBeDefined(); | ||
|
||
// const tree = renderer.create(<View>Snapshot test!</View>).toJSON(); | ||
// expect(tree).toMatchSnapshot(); | ||
|
||
// const file = await openAI.files.create('../README.md', 'fine-tune'); | ||
// expect(file).toBeDefined(); | ||
// expect(file.id).toBeDefined(); | ||
// }); | ||
// }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
{ | ||
"extends": "expo/tsconfig.base", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"module": "commonjs", | ||
"target": "es6", | ||
"declaration": true, | ||
"strict": true, | ||
"esModuleInterop": true | ||
"paths": { | ||
"@/*": [ | ||
"./*" | ||
] | ||
} | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules"] | ||
"include": [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
".expo/types/**/*.ts", | ||
"expo-env.d.ts" | ||
], | ||
"exclude": [ | ||
"openai-node" | ||
] | ||
} |
Oops, something went wrong.