Skip to content

Commit

Permalink
Chat completion helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
dgellow committed Jul 19, 2024
1 parent 9304bfc commit 2a6974d
Show file tree
Hide file tree
Showing 18 changed files with 1,802 additions and 26 deletions.
8 changes: 8 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
Types:

- <code><a href="./src/resources/chat/completions.ts">ChatCompletion</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionAssistantMessageParam</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionChunk</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionFunctionMessageParam</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionMessage</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionMessageParam</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionSystemMessageParam</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionTool</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionToolMessageParam</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionUsage</a></code>
- <code><a href="./src/resources/chat/completions.ts">ChatCompletionUserMessageParam</a></code>

Methods:

Expand Down
24 changes: 24 additions & 0 deletions examples/chat-completions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env -S npm run tsn -T

import Together from 'together-ai';

const together = new Together();
async function main() {
const runner = together.chat.completions
.stream({
model: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
messages: [{ role: 'user', content: 'Say this is a test' }],
})
.on('message', (msg) => console.log(msg))
.on('content', (diff) => process.stdout.write(diff));

for await (const chunk of runner) {
// Note: comment out the next line to print chunks as they are streamed from the API
// console.log('chunk', chunk);
}

const result = await runner.finalMessage();
console.log(result);
}

main();
2 changes: 1 addition & 1 deletion examples/embedding.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env -S npm run tsn -T

import Together from 'together';
import Together from 'together-ai';

const together = new Together();

Expand Down
2 changes: 1 addition & 1 deletion examples/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Example of listing and retrieving files

import Together from 'together';
import Together from 'together-ai';

const together = new Together();

Expand Down
2 changes: 1 addition & 1 deletion examples/fine-tune.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env -S npm run tsn -T

import Together from 'together';
import Together from 'together-ai';

const together = new Together();

Expand Down
2 changes: 1 addition & 1 deletion examples/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//An example to generate an image and save to a file

import Together from 'together';
import Together from 'together-ai';
import fs from 'fs';

const together = new Together();
Expand Down
2 changes: 1 addition & 1 deletion examples/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//An example to request a list of models and print them.

import Together from 'together';
import Together from 'together-ai';

const together = new Together();

Expand Down
2 changes: 1 addition & 1 deletion examples/streaming.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env -S npm run tsn -T

import Together from 'together';
import Together from 'together-ai';

const together = new Together();

Expand Down
Loading

0 comments on commit 2a6974d

Please sign in to comment.