diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d791adb..a955a76 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,25 @@ jobs: - name: Check types run: ./scripts/lint + + build: + name: build + runs-on: ubuntu-latest + + + steps: + - uses: actions/checkout@v4 + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Install dependencies + run: yarn install + + - name: Check build + run: ./scripts/build test: name: test runs-on: ubuntu-latest diff --git a/.release-please-manifest.json b/.release-please-manifest.json index a8250dd..6752a57 100755 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.6.0-alpha.6" + ".": "0.6.0-alpha.7" } diff --git a/.stats.yml b/.stats.yml index 1a7c6c5..99ef580 100755 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 15 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai%2FTogetherAI-1fe74361c29a31a4c44057fb30a8ddb72a635d9cd4b37e64a8bd668c3c964326.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai%2FTogetherAI-49d420a0d032aa57d5da9e8ef21bd80ca55cac0c21161bf3a20e0fca38db44ff.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index da1af1d..e26ab52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## 0.6.0-alpha.7 (2024-08-28) + +Full Changelog: [v0.6.0-alpha.6...v0.6.0-alpha.7](https://github.com/togethercomputer/together-typescript/compare/v0.6.0-alpha.6...v0.6.0-alpha.7) + +### Features + +* **api:** OpenAPI spec update via Stainless API ([#44](https://github.com/togethercomputer/together-typescript/issues/44)) ([5fbcdd8](https://github.com/togethercomputer/together-typescript/commit/5fbcdd8eb359ccd8f0bceb34d8d424c96e3e4268)) + + +### Bug Fixes + +* chat completion streaming when enabling logprobs ([cad72ef](https://github.com/togethercomputer/together-typescript/commit/cad72ef78213cbaa4497c7358b65e94c4b15f99a)) + + +### Chores + +* **ci:** check for build errors ([#46](https://github.com/togethercomputer/together-typescript/issues/46)) ([ef2541c](https://github.com/togethercomputer/together-typescript/commit/ef2541c70dfee841373dfe16a5c866ebcf382822)) + ## 0.6.0-alpha.6 (2024-08-26) Full Changelog: [v0.6.0-alpha.5...v0.6.0-alpha.6](https://github.com/togethercomputer/together-typescript/compare/v0.6.0-alpha.5...v0.6.0-alpha.6) diff --git a/examples/chat-completions.ts b/examples/chat-completions.ts index 01d435e..29ece8a 100755 --- a/examples/chat-completions.ts +++ b/examples/chat-completions.ts @@ -8,17 +8,18 @@ async function main() { .stream({ model: 'mistralai/Mixtral-8x7B-Instruct-v0.1', messages: [{ role: 'user', content: 'Say this is a test' }], + logprobs: 1, }) .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); + console.log('chunk', chunk); } const result = await runner.finalMessage(); - console.log(result); + console.log({ result }); } main(); diff --git a/package.json b/package.json index 7fdb5e1..04acdbb 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "together-ai", - "version": "0.6.0-alpha.6", + "version": "0.6.0-alpha.7", "description": "The official TypeScript library for the Together API", "author": "Together ", "types": "dist/index.d.ts", diff --git a/src/lib/ChatCompletionStream.ts b/src/lib/ChatCompletionStream.ts index 7f580c6..2d28778 100644 --- a/src/lib/ChatCompletionStream.ts +++ b/src/lib/ChatCompletionStream.ts @@ -157,20 +157,26 @@ export class ChatCompletionStream for (const { delta, finish_reason, index, logprobs = null, ...other } of chunk.choices) { let choice = snapshot.choices[index]; if (!choice) { - choice = snapshot.choices[index] = { finish_reason, index, message: {}, logprobs, ...other }; + choice = snapshot.choices[index] = { + finish_reason, + index, + message: {}, + logprobs: { token_ids: [], token_logprobs: [], tokens: [] }, + ...other, + }; } if (logprobs) { + console.log({ logprobs }); if (!choice.logprobs) { - choice.logprobs = Object.assign({}, logprobs); - } else { - const { content, ...rest } = logprobs; - Object.assign(choice.logprobs, rest); - if (content) { - choice.logprobs.content ??= []; - choice.logprobs.content.push(...content); - } + choice.logprobs = { token_ids: [], token_logprobs: [], tokens: [] }; } + choice.logprobs.token_ids ??= []; + choice.logprobs.token_ids.push(delta.token_id ?? null); + choice.logprobs.token_logprobs ??= []; + choice.logprobs.token_logprobs.push(logprobs ?? null); + choice.logprobs.tokens ??= []; + choice.logprobs.tokens.push(delta.content ?? null); } if (finish_reason) choice.finish_reason = finish_reason; diff --git a/src/resources/completions.ts b/src/resources/completions.ts index b6090e7..2a8bfaa 100755 --- a/src/resources/completions.ts +++ b/src/resources/completions.ts @@ -66,17 +66,17 @@ export interface LogProbs { /** * List of token IDs corresponding to the logprobs */ - token_ids?: Array; + token_ids?: Array; /** * List of token log probabilities */ - token_logprobs?: Array; + token_logprobs?: Array; /** * List of token strings */ - tokens?: Array; + tokens?: Array; } export interface ToolChoice { diff --git a/src/resources/models.ts b/src/resources/models.ts index b94310f..f818f4b 100755 --- a/src/resources/models.ts +++ b/src/resources/models.ts @@ -23,7 +23,7 @@ export namespace ModelListResponse { object: string; - type: 'chat' | 'language' | 'code' | 'image' | 'embedding' | 'moderation'; + type: 'chat' | 'language' | 'code' | 'image' | 'embedding' | 'moderation' | 'rerank'; context_length?: number; diff --git a/src/version.ts b/src/version.ts index b76dedc..b040a91 100755 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.6.0-alpha.6'; // x-release-please-version +export const VERSION = '0.6.0-alpha.7'; // x-release-please-version