-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
158 additions
and
63 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
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,12 @@ | ||
bring expect; | ||
bring "./openai.w" as openai; | ||
|
||
bring cloud; | ||
|
||
let key = new cloud.Secret(name: "my-openai-key"); | ||
let oai = new openai.OpenAI(apiKeySecret: key); | ||
|
||
new cloud.Function(inflight () => { | ||
let answer = oai.createCompletion("tell me a short joke", model: "gpt-3.5-turbo", max_tokens: 2048); | ||
log(answer); | ||
}) as "tell me a joke"; |
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,10 @@ | ||
export default interface extern { | ||
createNewInflightClient: (apiKey: string, org?: (string) | undefined) => Promise<IOpenAI$Inflight>, | ||
} | ||
export interface CompletionParams { | ||
readonly max_tokens: number; | ||
readonly model: string; | ||
} | ||
export interface IOpenAI$Inflight { | ||
readonly createCompletion: (prompt: string, params?: (CompletionParams) | undefined) => Promise<string>; | ||
} |
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 |
---|---|---|
@@ -1,21 +1,19 @@ | ||
bring expect; | ||
bring "./openai.w" as openai; | ||
|
||
let client = new openai.OpenAI(); | ||
bring cloud; | ||
|
||
// This test currently doesn't pass because of issue https://github.com/winglang/wing/issues/5948 | ||
// test "cant create client without key" { | ||
// let var errorMessage = ""; | ||
// try { | ||
// let answer = client.createCompletion("tell me a short joke"); | ||
// } catch e { | ||
// errorMessage = e; | ||
// } | ||
// expect.equal(errorMessage, "OpenAI API key is required"); | ||
// } | ||
let key = new cloud.Secret(name: "my-openai-key"); | ||
let oai = new openai.OpenAI(apiKeySecret: key); | ||
|
||
// This test currently cannot pass because we can't pass credentials to it in the test runner | ||
// test "basic completion" { | ||
// let answer = client.createCompletion("tell me a short joke"); | ||
// expect.notNil(answer); | ||
// } | ||
test "basic completion" { | ||
let answer = oai.createCompletion("tell me a short joke", model: "gpt-3.5-turbo", max_tokens: 2048); | ||
|
||
// in tests, the response is just an echo of the request | ||
expect.equal(answer, Json.stringify({ | ||
mock: { | ||
prompt:"tell me a short joke", | ||
params:{"model":"gpt-3.5-turbo","max_tokens":2048} | ||
} | ||
})); | ||
} |
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
Oops, something went wrong.