Skip to content

Commit

Permalink
[openai] Types match all minor versions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuanapoli committed Jun 22, 2023
1 parent 78e4dcd commit c2221f1
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// @flow
import { describe, it } from 'flow-typed-test';
import { Configuration, OpenAIApi } from 'openai';

describe('openai', () => {
let openAIApi: OpenAIApi;

it('constructs client', () => {
const apiKey = "secret";
const configuration = new Configuration({ apiKey });
openAIApi = new OpenAIApi(configuration);

// $FlowExpectedError[incompatible-call] valid configuration required
const invalidConfiguration = new OpenAIApi({wrong: "type"});

// $FlowExpectedError[incompatible-call] string required
const invalidApiKey = new OpenAIApi({apiKey: 1234});
});

it('constructs client with async api key', () => {
const apiKey = Promise.resolve("secret");
const configuration = new Configuration({ apiKey });
openAIApi = new OpenAIApi(configuration);

// $FlowExpectedError[incompatible-call] string required
const invalidApiKey = new OpenAIApi({apiKey: Promise.resolve(1234)});
});

it('creates answer', () => {
// $FlowExpectedError[prop-missing] requires model, question, examples, examples_context
openAIApi.createAnswer({});

openAIApi.createAnswer({model: "davinci", question: "Who won the NBA championship in 2023?", examples:[], examples_context: "I am a basketball bot."});
});

it('creates chat completion', () => {
openAIApi.createChatCompletion({model: "gpt-3.5-turbo", messages: [], functions: [{name: "hello-world"}]});

// $FlowExpectedError[prop-missing] requires role
openAIApi.createChatCompletion({model: "gpt-3.5-turbo", messages: [{}]});

// $FlowExpectedError[prop-missing] requires messages
openAIApi.createChatCompletion({model: "incomplete-request"});
});
});

0 comments on commit c2221f1

Please sign in to comment.