This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for our Fine-tuning API (#80)
- Loading branch information
Showing
13 changed files
with
685 additions
and
52 deletions.
There are no files selected for viewing
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,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}]} |
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,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); |
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,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); |
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
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,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>; | ||
} |
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,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'}) { | ||
const formData = new FormData(); | ||
formData.append('file', file); | ||
formData.append('purpose', purpose); | ||
const response = await this.client._request( | ||
'post', | ||
'v1/files', | ||
null, | ||
undefined, | ||
formData, | ||
); | ||
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}) { | ||
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; |
Oops, something went wrong.