-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tomas Pilar <[email protected]>
- Loading branch information
1 parent
ebff49c
commit 9d32dc9
Showing
13 changed files
with
155 additions
and
203 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
export const MODEL = 'google/flan-ul2'; | ||
export const CHAT_MODEL = 'meta-llama/llama-2-70b-chat'; |
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,96 +1,28 @@ | ||
import { Client } from '../src/index.js'; | ||
|
||
import { loadGenerateInput } from './load_input.js'; | ||
import { MODEL } from './constants.js'; | ||
|
||
const client = new Client({ | ||
apiKey: process.env.GENAI_API_KEY, | ||
}); | ||
|
||
const multipleInputs = loadGenerateInput(); | ||
const singleInput = multipleInputs[0]; | ||
const input = { model_id: MODEL, input: 'How are you?' }; | ||
|
||
// { | ||
// // Use with a single input to get a promise | ||
// const output = await client.generate(singleInput); | ||
// console.log(output); | ||
// } | ||
|
||
// { | ||
// // Or supply a callback | ||
// client.generate(singleInput, (err, output) => { | ||
// if (err) console.error(err); | ||
// else console.log(output); | ||
// }); | ||
// } | ||
|
||
// { | ||
// // Use with multiple inputs to get a promise | ||
// const outputs = await Promise.all(client.generate(multipleInputs)); | ||
// console.log(outputs); | ||
|
||
// // Or supply a callback which will be called for each output | ||
// // Callback is guaranteed to be called in the order of respective inputs | ||
// client.generate(multipleInputs, (err, output) => { | ||
// if (err) console.error(err); | ||
// else console.log(output); | ||
// }); | ||
|
||
// // The method is optimized for sequential await, order the inputs accordingly | ||
// for (const outputPromise of client.generate(multipleInputs)) { | ||
// try { | ||
// console.log(await outputPromise); | ||
// } catch (err) { | ||
// console.error(err); | ||
// } | ||
// } | ||
// } | ||
|
||
// { | ||
// // Streaming (callback style) | ||
// client.generate( | ||
// singleInput, | ||
// { | ||
// stream: true, | ||
// }, | ||
// (err, output) => { | ||
// if (err) { | ||
// console.error(err); | ||
// } else if (output === null) { | ||
// // END of stream | ||
// } else { | ||
// console.log(output.stop_reason); | ||
// console.log(output.generated_token_count); | ||
// console.log(output.input_token_count); | ||
// console.log(output.generated_text); | ||
// } | ||
// }, | ||
// ); | ||
// } | ||
{ | ||
const output = await client.text.generation.create(input); | ||
console.log(output); | ||
} | ||
|
||
{ | ||
// Streaming (async iterators) | ||
const stream = client.generation_stream(singleInput); | ||
const stream = await client.text.generation.create_stream(input); | ||
for await (const chunk of stream) { | ||
console.log(chunk.stop_reason); | ||
console.log(chunk.generated_token_count); | ||
console.log(chunk.input_token_count); | ||
console.log(chunk.generated_text); | ||
const result = chunk.results?.at(0); | ||
if (result) { | ||
console.log(result.stop_reason); | ||
console.log(result.generated_token_count); | ||
console.log(result.input_token_count); | ||
console.log(result.generated_text); | ||
} | ||
} | ||
} | ||
|
||
{ | ||
// Streaming (built-in stream methods) | ||
const stream = client.generation_stream(singleInput); | ||
stream.on('data', (chunk) => { | ||
console.log(chunk.stop_reason); | ||
console.log(chunk.generated_token_count); | ||
console.log(chunk.input_token_count); | ||
console.log(chunk.generated_text); | ||
}); | ||
stream.on('error', (err) => { | ||
console.error('error has occurred', err); | ||
}); | ||
stream.on('close', () => { | ||
console.info('end of stream'); | ||
}); | ||
} |
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,23 +1,32 @@ | ||
import { Client } from '../src/index.js'; | ||
|
||
import { CHAT_MODEL } from './constants.js'; | ||
|
||
const client = new Client({ | ||
apiKey: process.env.GENAI_API_KEY, | ||
}); | ||
|
||
{ | ||
// List historical success requests to the API | ||
for await (const request of client.history({ | ||
origin: 'API', | ||
status: 'SUCCESS', | ||
})) { | ||
const { results } = await client.request.list({ | ||
origin: 'api', | ||
status: 'success', | ||
}); | ||
for (const request of results) { | ||
console.log(request); | ||
} | ||
} | ||
|
||
{ | ||
// List all requests from the past via callback interface | ||
client.history((err, request) => { | ||
if (err) console.error(err); | ||
console.log(request); | ||
// List all requests related to a chat conversation | ||
const { conversation_id } = await client.text.chat.create({ | ||
model_id: CHAT_MODEL, | ||
messages: [{ role: 'user', content: 'How are you?' }], | ||
}); | ||
const { results } = await client.request.chat({ | ||
conversationId: conversation_id, | ||
}); | ||
for (const request of results) { | ||
console.log(request); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,8 +1,19 @@ | ||
import { Client } from '../src/index.js'; | ||
|
||
import { MODEL } from './constants.js'; | ||
|
||
const client = new Client({ | ||
apiKey: process.env.GENAI_API_KEY, | ||
}); | ||
|
||
const models = await client.models({ limit: 100, offset: 0 }); | ||
console.log(models); | ||
{ | ||
// List first hundred models | ||
const { results } = await client.model.list({ limit: 100, offset: 0 }); | ||
console.log(results); | ||
} | ||
|
||
{ | ||
// Retrieve info about a specific model | ||
const { result } = await client.model.retrieve({ id: MODEL }); | ||
console.log(result); | ||
} |
Oops, something went wrong.