-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "What's the capital of France?"}, {"role": "assistant", "content": "Paris, as if everyone doesn't know that already."}]} | ||
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "Who wrote 'Romeo and Juliet'?"}, {"role": "assistant", "content": "Oh, just some guy named William Shakespeare. Ever heard of him?"}]} | ||
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "How far is the Moon from Earth?"}, {"role": "assistant", "content": "Around 384,400 kilometers. Give or take a few, like that really matters.", "weight": 0}]} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import MistralClient from '@mistralai/mistralai'; | ||
import * as fs from 'fs'; | ||
|
||
|
||
const apiKey = process.env.MISTRAL_API_KEY; | ||
|
||
const client = new MistralClient(apiKey); | ||
|
||
// Create a new file | ||
const blob = new Blob( | ||
[fs.readFileSync('file.jsonl')], | ||
{type: 'application/json'}, | ||
); | ||
const createdFile = await client.files.create({file: blob}); | ||
console.log(createdFile); | ||
|
||
// List files | ||
const files = await client.files.list(); | ||
console.log(files); | ||
|
||
// Retrieve a file | ||
const retrievedFile = await client.files.retrieve({fileId: createdFile.id}); | ||
console.log(retrievedFile); | ||
|
||
// Delete a file | ||
const deletedFile = await client.files.delete({fileId: createdFile.id}); | ||
console.log(deletedFile); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import MistralClient from '@mistralai/mistralai'; | ||
import * as fs from 'fs'; | ||
|
||
|
||
const apiKey = process.env.MISTRAL_API_KEY; | ||
|
||
const client = new MistralClient(apiKey); | ||
|
||
// Create a new file | ||
const blob = new Blob( | ||
[fs.readFileSync('file.jsonl')], | ||
{type: 'application/json'}, | ||
); | ||
const createdFile = await client.files.create({file: blob}); | ||
|
||
// Create a new job | ||
const hyperparameters = { | ||
training_steps: 10, | ||
learning_rate: 0.0001, | ||
}; | ||
const createdJob = await client.jobs.create({ | ||
model: 'open-mistral-7b', | ||
trainingFiles: [createdFile.id], | ||
validationFiles: [createdFile.id], | ||
hyperparameters, | ||
}); | ||
console.log(createdJob); | ||
|
||
// List jobs | ||
const jobs = await client.jobs.list(); | ||
console.log(jobs); | ||
|
||
// Retrieve a job | ||
const retrievedJob = await client.jobs.retrieve({jobId: createdJob.id}); | ||
console.log(retrievedJob); | ||
|
||
// Cancel a job | ||
const canceledJob = await client.jobs.cancel({jobId: createdJob.id}); | ||
console.log(canceledJob); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export enum Purpose { | ||
finetune = 'fine-tune', | ||
} | ||
|
||
export interface FileObject { | ||
id: string; | ||
object: string; | ||
bytes: number; | ||
created_at: number; | ||
filename: string; | ||
purpose?: Purpose; | ||
} | ||
|
||
export interface FileDeleted { | ||
id: string; | ||
object: string; | ||
deleted: boolean; | ||
} | ||
|
||
export class FilesClient { | ||
constructor(client: MistralClient); | ||
|
||
create(options: { file: File; purpose?: string }): Promise<FileObject>; | ||
|
||
retrieve(options: { fileId: string }): Promise<FileObject>; | ||
|
||
list(): Promise<FileObject[]>; | ||
|
||
delete(options: { fileId: string }): Promise<FileDeleted>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Class representing a client for file operations. | ||
*/ | ||
class FilesClient { | ||
/** | ||
* Create a FilesClient object. | ||
* @param {MistralClient} client - The client object used for making requests. | ||
*/ | ||
constructor(client) { | ||
this.client = client; | ||
} | ||
|
||
/** | ||
* Create a new file. | ||
* @param {File} file - The file to be created. | ||
* @param {string} purpose - The purpose of the file. Default is 'fine-tune'. | ||
* @return {Promise<*>} A promise that resolves to a FileObject. | ||
* @throws {MistralAPIError} If no response is received from the server. | ||
*/ | ||
async create({ file, purpose = "fine-tune" }) { | ||
Check failure on line 20 in src/files.js
|
||
const formData = new FormData(); | ||
formData.append("file", file); | ||
Check failure on line 22 in src/files.js
|
||
formData.append("purpose", purpose); | ||
Check failure on line 23 in src/files.js
|
||
const response = await this.client._request( | ||
"post", | ||
Check failure on line 25 in src/files.js
|
||
"v1/files", | ||
Check failure on line 26 in src/files.js
|
||
null, | ||
undefined, | ||
formData | ||
Check failure on line 29 in src/files.js
|
||
); | ||
return response; | ||
} | ||
|
||
/** | ||
* Retrieve a file. | ||
* @param {string} fileId - The ID of the file to retrieve. | ||
* @return {Promise<*>} A promise that resolves to the file data. | ||
*/ | ||
async retrieve({ fileId }) { | ||
Check failure on line 39 in src/files.js
|
||
const response = await this.client._request("get", `v1/files/${fileId}`); | ||
return response; | ||
} | ||
|
||
/** | ||
* List all files. | ||
* @return {Promise<Array<FileObject>>} A promise that resolves to | ||
* an array of FileObject. | ||
*/ | ||
async list() { | ||
const response = await this.client._request("get", "v1/files"); | ||
return response; | ||
} | ||
|
||
/** | ||
* Delete a file. | ||
* @param {string} fileId - The ID of the file to delete. | ||
* @return {Promise<*>} A promise that resolves to the response. | ||
*/ | ||
async delete({ fileId }) { | ||
const response = await this.client._request("delete", `v1/files/${fileId}`); | ||
return response; | ||
} | ||
} | ||
|
||
export default FilesClient; |