Skip to content

🌿 Fern Regeneration -- June 12, 2025 #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('jest').Config} */
export default {
preset: "ts-jest",
testEnvironment: "node",
moduleNameMapper: {
"(.+)\.js$": "$1",
},
};
55 changes: 39 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
{
"name": "cohere-ai",
"version": "7.17.1",
"version": "7.18.0",
"private": false,
"repository": "https://github.com/cohere-ai/cohere-typescript",
"main": "./index.js",
"types": "./index.d.ts",
"type": "commonjs",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.mjs",
"types": "./dist/cjs/index.d.ts",
"exports": {
".": {
"types": "./dist/cjs/index.d.ts",
"import": {
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
},
"default": "./dist/cjs/index.js"
},
"./package.json": "./package.json"
},
"files": [
"dist",
"reference.md"
],
"scripts": {
"format": "prettier . --write --ignore-unknown",
"build": "tsc",
"prepack": "cp -rv dist/. .",
"build": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc --project ./tsconfig.cjs.json",
"build:esm": "tsc --project ./tsconfig.esm.json && node scripts/rename-to-esm-files.js dist/esm",
"test": "jest"
},
"dependencies": {
"url-join": "4.0.1",
"form-data": "^4.0.0",
"formdata-node": "^6.0.3",
"node-fetch": "2.7.0",
"qs": "6.11.2",
"node-fetch": "^2.7.0",
"qs": "^6.13.1",
"readable-stream": "^4.5.2",
"js-base64": "3.7.2",
"js-base64": "3.7.7",
"form-data-encoder": "^4.0.2",
"@aws-sdk/client-sagemaker": "^3.583.0",
"@aws-sdk/credential-providers": "^3.583.0",
Expand All @@ -28,23 +50,24 @@
},
"devDependencies": {
"@types/url-join": "4.0.1",
"@types/qs": "6.9.8",
"@types/node-fetch": "2.6.9",
"@types/qs": "^6.9.17",
"@types/node-fetch": "^2.6.12",
"@types/readable-stream": "^4.0.14",
"webpack": "^5.91.0",
"ts-loader": "^9.5.1",
"jest": "^29.7.0",
"@types/jest": "29.5.5",
"@types/jest": "^29.5.14",
"ts-jest": "^29.1.2",
"jest-environment-jsdom": "29.7.0",
"@types/node": "17.0.33",
"prettier": "2.7.1",
"typescript": "4.6.4",
"jest-environment-jsdom": "^29.7.0",
"@types/node": "^18.19.70",
"prettier": "^3.4.2",
"typescript": "~5.7.2",
"@types/convict": "^6.1.6"
},
"browser": {
"fs": false,
"os": false,
"path": false
}
},
"packageManager": "yarn@1.22.22"
}
71 changes: 31 additions & 40 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ Follow the [Migration Guide](https://docs.cohere.com/v2/docs/migrating-v1-to-v2)

```typescript
const response = await client.v2.chatStream({
model: "model",
model: "command-r",
messages: [
{
role: "tool",
toolCallId: "messages",
content: "messages",
role: "user",
content: "Hello!",
},
],
});
Expand Down Expand Up @@ -167,12 +166,11 @@ Follow the [Migration Guide](https://docs.cohere.com/v2/docs/migrating-v1-to-v2)

```typescript
await client.v2.chat({
model: "model",
model: "command-a-03-2025",
messages: [
{
role: "tool",
toolCallId: "messages",
content: "messages",
role: "user",
content: "Tell me about LLMs",
},
],
});
Expand Down Expand Up @@ -243,9 +241,10 @@ If you want to learn more how to use the embedding model, have a look at the [Se

```typescript
await client.v2.embed({
model: "model",
inputType: "search_document",
embeddingTypes: ["float"],
texts: ["hello", "goodbye"],
model: "embed-v4.0",
input_type: "classification",
embedding_types: ["float"],
});
```

Expand Down Expand Up @@ -310,9 +309,16 @@ This endpoint takes in a query and a list of texts and produces an ordered array

```typescript
await client.v2.rerank({
model: "model",
query: "query",
documents: ["documents"],
documents: [
"Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages.",
"Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
"Capital punishment has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states.",
],
query: "What is the capital of the United States?",
top_n: 3,
model: "rerank-v3.5",
});
```

Expand Down Expand Up @@ -435,8 +441,8 @@ This API launches an async Embed job for a [Dataset](https://docs.cohere.com/doc
```typescript
await client.embedJobs.create({
model: "model",
datasetId: "dataset_id",
inputType: "search_document",
dataset_id: "dataset_id",
input_type: "search_document",
});
```

Expand Down Expand Up @@ -663,7 +669,7 @@ await client.datasets.list();
</dl>
</details>

<details><summary><code>client.datasets.<a href="/src/api/resources/datasets/client/Client.ts">create</a>(data, evalData, { ...params }) -> Cohere.DatasetsCreateResponse</code></summary>
<details><summary><code>client.datasets.<a href="/src/api/resources/datasets/client/Client.ts">create</a>({ ...params }) -> Cohere.DatasetsCreateResponse</code></summary>
<dl>
<dd>

Expand Down Expand Up @@ -691,7 +697,8 @@ Create a dataset by uploading a file. See ['Dataset Creation'](https://docs.cohe
<dd>

```typescript
await client.datasets.create(fs.createReadStream("/path/to/your/file"), fs.createReadStream("/path/to/your/file"), {
await client.datasets.create({
data: fs.createReadStream("/path/to/your/file"),
name: "name",
type: "embed-input",
});
Expand All @@ -710,22 +717,6 @@ await client.datasets.create(fs.createReadStream("/path/to/your/file"), fs.creat
<dl>
<dd>

**data:** `File | fs.ReadStream | Blob`

</dd>
</dl>

<dl>
<dd>

**evalData:** `File | fs.ReadStream | Blob | undefined`

</dd>
</dl>

<dl>
<dd>

**request:** `Cohere.DatasetsCreateRequest`

</dd>
Expand Down Expand Up @@ -1519,10 +1510,10 @@ await client.finetuning.listFinetunedModels();
await client.finetuning.createFinetunedModel({
name: "api-test",
settings: {
baseModel: {
baseType: "BASE_TYPE_CHAT",
base_model: {
base_type: "BASE_TYPE_CHAT",
},
datasetId: "my-dataset-id",
dataset_id: "my-dataset-id",
},
});
```
Expand Down Expand Up @@ -1671,10 +1662,10 @@ await client.finetuning.deleteFinetunedModel("id");
await client.finetuning.updateFinetunedModel("id", {
name: "name",
settings: {
baseModel: {
baseType: "BASE_TYPE_UNSPECIFIED",
base_model: {
base_type: "BASE_TYPE_UNSPECIFIED",
},
datasetId: "dataset_id",
dataset_id: "dataset_id",
},
});
```
Expand Down
115 changes: 115 additions & 0 deletions scripts/rename-to-esm-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/env node

const fs = require("fs").promises;
const path = require("path");

const extensionMap = {
".js": ".mjs",
".d.ts": ".d.mts",
};
const oldExtensions = Object.keys(extensionMap);

async function findFiles(rootPath) {
const files = [];

async function scan(directory) {
const entries = await fs.readdir(directory, { withFileTypes: true });

for (const entry of entries) {
const fullPath = path.join(directory, entry.name);

if (entry.isDirectory()) {
if (entry.name !== "node_modules" && !entry.name.startsWith(".")) {
await scan(fullPath);
}
} else if (entry.isFile()) {
if (oldExtensions.some((ext) => entry.name.endsWith(ext))) {
files.push(fullPath);
}
}
}
}

await scan(rootPath);
return files;
}

async function updateFiles(files) {
const updatedFiles = [];
for (const file of files) {
const updated = await updateFileContents(file);
updatedFiles.push(updated);
}

console.log(`Updated imports in ${updatedFiles.length} files.`);
}

async function updateFileContents(file) {
const content = await fs.readFile(file, "utf8");

let newContent = content;
// Update each extension type defined in the map
for (const [oldExt, newExt] of Object.entries(extensionMap)) {
const regex = new RegExp(`(import|export)(.+from\\s+['"])(\\.\\.?\\/[^'"]+)(\\${oldExt})(['"])`, "g");
newContent = newContent.replace(regex, `$1$2$3${newExt}$5`);
}

if (content !== newContent) {
await fs.writeFile(file, newContent, "utf8");
return true;
}
return false;
}

async function renameFiles(files) {
let counter = 0;
for (const file of files) {
const ext = oldExtensions.find((ext) => file.endsWith(ext));
const newExt = extensionMap[ext];

if (newExt) {
const newPath = file.slice(0, -ext.length) + newExt;
await fs.rename(file, newPath);
counter++;
}
}

console.log(`Renamed ${counter} files.`);
}

async function main() {
try {
const targetDir = process.argv[2];
if (!targetDir) {
console.error("Please provide a target directory");
process.exit(1);
}

const targetPath = path.resolve(targetDir);
const targetStats = await fs.stat(targetPath);

if (!targetStats.isDirectory()) {
console.error("The provided path is not a directory");
process.exit(1);
}

console.log(`Scanning directory: ${targetDir}`);

const files = await findFiles(targetDir);

if (files.length === 0) {
console.log("No matching files found.");
process.exit(0);
}

console.log(`Found ${files.length} files.`);
await updateFiles(files);
await renameFiles(files);
console.log("\nDone!");
} catch (error) {
console.error("An error occurred:", error.message);
process.exit(1);
}
}

main();
Loading
Loading